-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix escaping inference var ICE in point_at_expr_source_of_inferred_type
#107175
Conversation
if !span.overlaps(mismatch_span) { | ||
err.span_label( | ||
span, | ||
with_forced_trimmed_paths!(format!( | ||
"here the type of `{ident}` is inferred to be `{ty}`", | ||
)), | ||
); | ||
);} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love let-chains 🙃
@@ -0,0 +1,20 @@ | |||
// The error message here still is pretty confusing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably check how many spans we have and if there's only one, with infer vars in the type, then we skip the customization? Not necessary for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after fixing formatting
35ef3fc
to
9f933b5
Compare
@bors r=estebank |
…ush, r=estebank Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type` Fixes rust-lang#107158 `point_at_expr_source_of_inferred_type` uses `lookup_probe` to adjust the self type of a method receiver -- but that method returns inference variables from inside a probe. That means that the ty vars are no longer valid, so we can't use any infcx methods on them. Also, pass some extra span info to hack a quick solution to bad labels, resulting in this diagnostic improvement: ```rust fn example2() { let mut x = vec![1]; x.push(""); } ``` ```diff error[E0308]: mismatched types --> src/main.rs:5:12 | 5 | x.push(""); | ---- ^^ | | | | | expected integer, found `&str` - | | this is of type `&'static str`, which causes `x` to be inferred as `Vec<{integer}>` | arguments to this method are incorrect ``` (since that "which causes `x` to be inferred as `Vec<{integer}>` part is wrong) r? `@estebank` (we really should make this code better in general, cc rust-lang#106590, but that's a bit bigger issue that needs some more thinking about)
…ush, r=estebank Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type` Fixes rust-lang#107158 `point_at_expr_source_of_inferred_type` uses `lookup_probe` to adjust the self type of a method receiver -- but that method returns inference variables from inside a probe. That means that the ty vars are no longer valid, so we can't use any infcx methods on them. Also, pass some extra span info to hack a quick solution to bad labels, resulting in this diagnostic improvement: ```rust fn example2() { let mut x = vec![1]; x.push(""); } ``` ```diff error[E0308]: mismatched types --> src/main.rs:5:12 | 5 | x.push(""); | ---- ^^ | | | | | expected integer, found `&str` - | | this is of type `&'static str`, which causes `x` to be inferred as `Vec<{integer}>` | arguments to this method are incorrect ``` (since that "which causes `x` to be inferred as `Vec<{integer}>` part is wrong) r? ``@estebank`` (we really should make this code better in general, cc rust-lang#106590, but that's a bit bigger issue that needs some more thinking about)
@bors rollup as this only affects diagnostics |
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#106407 (Improve proc macro attribute diagnostics) - rust-lang#106960 (Teach parser to understand fake anonymous enum syntax) - rust-lang#107085 (Custom MIR: Support binary and unary operations) - rust-lang#107086 (Print PID holding bootstrap build lock on Linux) - rust-lang#107175 (Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`) - rust-lang#107204 (suggest qualifying bare associated constants) - rust-lang#107248 (abi: add AddressSpace field to Primitive::Pointer ) - rust-lang#107272 (Implement ObjectSafe and WF in the new solver) - rust-lang#107285 (Implement `Generator` and `Future` in the new solver) - rust-lang#107286 (ICE in new solver if we see an inference variable) - rust-lang#107313 (Add Style Team Triagebot config) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#106407 (Improve proc macro attribute diagnostics) - rust-lang#106960 (Teach parser to understand fake anonymous enum syntax) - rust-lang#107085 (Custom MIR: Support binary and unary operations) - rust-lang#107086 (Print PID holding bootstrap build lock on Linux) - rust-lang#107175 (Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`) - rust-lang#107204 (suggest qualifying bare associated constants) - rust-lang#107248 (abi: add AddressSpace field to Primitive::Pointer ) - rust-lang#107272 (Implement ObjectSafe and WF in the new solver) - rust-lang#107285 (Implement `Generator` and `Future` in the new solver) - rust-lang#107286 (ICE in new solver if we see an inference variable) - rust-lang#107313 (Add Style Team Triagebot config) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #107158
point_at_expr_source_of_inferred_type
useslookup_probe
to adjust the self type of a method receiver -- but that method returns inference variables from inside a probe. That means that the ty vars are no longer valid, so we can't use any infcx methods on them.Also, pass some extra span info to hack a quick solution to bad labels, resulting in this diagnostic improvement:
error[E0308]: mismatched types --> src/main.rs:5:12 | 5 | x.push(""); | ---- ^^ | | | | | expected integer, found `&str` - | | this is of type `&'static str`, which causes `x` to be inferred as `Vec<{integer}>` | arguments to this method are incorrect
(since that "which causes
x
to be inferred asVec<{integer}>
part is wrong)r? @estebank
(we really should make this code better in general, cc #106590, but that's a bit bigger issue that needs some more thinking about)