forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#119638 - lukas-code:suggest-constructor-cycle-error, r=cjgillot fix cyle error when suggesting to use associated function instead of constructor Fixes rust-lang#119625. The first commit fixes the infinite recursion and makes the cycle error actually show up. We do this by making the `Display` for `ty::Instance` impl respect `with_no_queries` so that it can be used in query descriptions. The second commit fixes the cycle error `resolver_for_lowering` -> `normalize` -> `resolve_instance` (for evaluating const) -> `lang_items` (for `drop_in_place`) -> `resolver_for_lowering` (for collecting lang items). We do this by simply skipping the suggestion when encountering an unnormalized type.
- Loading branch information
Showing
5 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/ui/resolve/auxiliary/suggest-constructor-cycle-error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mod m { | ||
pub struct Uuid(()); | ||
|
||
impl Uuid { | ||
pub fn encode_buffer() -> [u8; LENGTH] { | ||
[] | ||
} | ||
} | ||
const LENGTH: usize = 0; | ||
} | ||
|
||
pub use m::Uuid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// aux-build:suggest-constructor-cycle-error.rs | ||
|
||
// Regression test for https://github.com/rust-lang/rust/issues/119625 | ||
|
||
extern crate suggest_constructor_cycle_error as a; | ||
|
||
const CONST_NAME: a::Uuid = a::Uuid(()); | ||
//~^ ERROR: cannot initialize a tuple struct which contains private fields [E0423] | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0423]: cannot initialize a tuple struct which contains private fields | ||
--> $DIR/suggest-constructor-cycle-error.rs:7:29 | ||
| | ||
LL | const CONST_NAME: a::Uuid = a::Uuid(()); | ||
| ^^^^^^^ | ||
| | ||
note: constructor is not visible here due to private fields | ||
--> $DIR/auxiliary/suggest-constructor-cycle-error.rs:2:21 | ||
| | ||
LL | pub struct Uuid(()); | ||
| ^^ private field | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0423`. |