-
Notifications
You must be signed in to change notification settings - Fork 13.7k
fix ICE when suggesting ::new
#146217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix ICE when suggesting ::new
#146217
+69
−10
Conversation
This file contains hidden or 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
compiler-errors
is not on the review rotation at the moment.
They may take a while to respond.
@rustbot
rustbot
added
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Sep 4, 2025
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@bors r=compiler-errors rollup
@bors
bors
added
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Sep 5, 2025
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Sep 5, 2025
...iler-errors fix ICE when suggesting `::new` fixes rust-lang#146174 This code suggests to write `Foo::new(...)` when the user writes `Foo(...)` or `Foo { ... }` and the constructor is private, where `new` is some associated function that returns `Self`. When checking that the return type of `new` is `Self`, we need to instantiate the parameters of `new` with infer vars, so we don't end up with a type like `Box<$param(0)>` in a context that doesn't have any parameters. But then we can't use `normalize_erasing_late_bound_regions` anymore because that goes though a query that can't deal with infer vars. Since this is diagnostic-only code that is supposed to check for exactly `-> Self`, I think it's fine to just skip normalizing here, especially since The Correct Way<sup>TM</sup> would involve a probe and make this code even more complicated. Also, the code here does almost the same thing, and these suggestions can probably be unified in the future: https://github.com/rust-lang/rust/blob/4ca8078d37c53ee4ff8fb32b4453b915116f25b8/compiler/rustc_hir_typeck/src/method/suggest.rs#L2123-L2129 r? `@compiler-errors` cc `@Qelxiros` -- this should unblock rust-lang#144420
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Sep 5, 2025
...iler-errors fix ICE when suggesting `::new` fixes rust-lang#146174 This code suggests to write `Foo::new(...)` when the user writes `Foo(...)` or `Foo { ... }` and the constructor is private, where `new` is some associated function that returns `Self`. When checking that the return type of `new` is `Self`, we need to instantiate the parameters of `new` with infer vars, so we don't end up with a type like `Box<$param(0)>` in a context that doesn't have any parameters. But then we can't use `normalize_erasing_late_bound_regions` anymore because that goes though a query that can't deal with infer vars. Since this is diagnostic-only code that is supposed to check for exactly `-> Self`, I think it's fine to just skip normalizing here, especially since The Correct Way<sup>TM</sup> would involve a probe and make this code even more complicated. Also, the code here does almost the same thing, and these suggestions can probably be unified in the future: https://github.com/rust-lang/rust/blob/4ca8078d37c53ee4ff8fb32b4453b915116f25b8/compiler/rustc_hir_typeck/src/method/suggest.rs#L2123-L2129 r? ```@compiler-errors``` cc ```@Qelxiros``` -- this should unblock rust-lang#144420
bors
added a commit
that referenced
this pull request
Sep 5, 2025
Rollup of 6 pull requests Successful merges: - #144342 (add exact bitshifts) - #145709 (Fix LoongArch C function ABI when passing/returning structs containing floats) - #146152 (Unify and deduplicate algebraic float tests) - #146186 (Update cc-rs to 1.2.33, and switch rustc_codegen_ssa to use find-msvc-tools) - #146207 (std: Implement WASIp2-specific stdio routines) - #146217 (fix ICE when suggesting `::new`) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
that referenced
this pull request
Sep 5, 2025
Rollup of 5 pull requests Successful merges: - #144342 (add exact bitshifts) - #145709 (Fix LoongArch C function ABI when passing/returning structs containing floats) - #146152 (Unify and deduplicate algebraic float tests) - #146207 (std: Implement WASIp2-specific stdio routines) - #146217 (fix ICE when suggesting `::new`) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Sep 5, 2025
Rollup merge of #146217 - lukas-code:suggest-new-ice, r=compiler-errors fix ICE when suggesting `::new` fixes #146174 This code suggests to write `Foo::new(...)` when the user writes `Foo(...)` or `Foo { ... }` and the constructor is private, where `new` is some associated function that returns `Self`. When checking that the return type of `new` is `Self`, we need to instantiate the parameters of `new` with infer vars, so we don't end up with a type like `Box<$param(0)>` in a context that doesn't have any parameters. But then we can't use `normalize_erasing_late_bound_regions` anymore because that goes though a query that can't deal with infer vars. Since this is diagnostic-only code that is supposed to check for exactly `-> Self`, I think it's fine to just skip normalizing here, especially since The Correct Way<sup>TM</sup> would involve a probe and make this code even more complicated. Also, the code here does almost the same thing, and these suggestions can probably be unified in the future: https://github.com/rust-lang/rust/blob/4ca8078d37c53ee4ff8fb32b4453b915116f25b8/compiler/rustc_hir_typeck/src/method/suggest.rs#L2123-L2129 r? ````@compiler-errors```` cc ````@Qelxiros```` -- this should unblock #144420
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #146174
This code suggests to write
Foo::new(...)
when the user writesFoo(...)
orFoo { ... }
and the constructor is private, wherenew
is some associated function that returnsSelf
.When checking that the return type of
new
isSelf
, we need to instantiate the parameters ofnew
with infer vars, so we don't end up with a type likeBox<$param(0)>
in a context that doesn't have any parameters. But then we can't usenormalize_erasing_late_bound_regions
anymore because that goes though a query that can't deal with infer vars.Since this is diagnostic-only code that is supposed to check for exactly
-> Self
, I think it's fine to just skip normalizing here, especially since The Correct WayTM would involve a probe and make this code even more complicated.Also, the code here does almost the same thing, and these suggestions can probably be unified in the future:
rust/compiler/rustc_hir_typeck/src/method/suggest.rs
Lines 2123 to 2129 in 4ca8078
r? @compiler-errors
cc @Qelxiros -- this should unblock #144420