-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 suggestions for &a: T
parameters
#97964
Fix suggestions for &a: T
parameters
#97964
Conversation
Previously we were suggesting stuff like `fn f( &u32) {}`
This comment has been minimized.
This comment has been minimized.
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.
I left some general comments, but thanks @WaffleLapkin for such thorough UI tests.
inner: &Pat<'_>, | ||
expected: Ty<'tcx>, | ||
) { | ||
fn borrow_pat_suggestion(&self, err: &mut Diagnostic, pat: &Pat<'_>, inner: &Pat<'_>) { |
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.
What is pat
and inner
in this case? Is pat
the (direct?) parent of inner
always?
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.
Yes. pat
is Ref(inner)
, see
rust/compiler/rustc_typeck/src/check/pat.rs
Lines 201 to 202 in e9d49b2
PatKind::Ref(inner, mutbl) => { | |
self.check_pat_ref(pat, inner, mutbl, expected, def_bm, ti) |
rust/compiler/rustc_typeck/src/check/pat.rs
Line 1871 in e9d49b2
self.borrow_pat_suggestion(&mut err, pat, inner); |
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.
Huh, could we simplify the redundant parameters then, if you think that would be simpler? Or if not, could you leave a comment that explains this relationship.
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.
What we really want is to have pat: Pat<PatKind::Ref>
or something, but we don't have variant types so everything is messy :(
In the end I've removed inner
(we need to match anyway, so that should be fine) and added comments about preconditions
This comment has been minimized.
This comment has been minimized.
f19b8e8
to
33ccd76
Compare
Thanks @WaffleLapkin, this is definitely an great improvement on the diagnostic. @bors r+ rollup |
📌 Commit 33ccd76 has been approved by |
…ions, r=compiler-errors Fix suggestions for `&a: T` parameters I've accidentally discovered that we have broken suggestions for `&a: T` parameters: ```rust fn f(&mut bar: u32) {} fn main() { let _ = |&mut a| (); } ``` ```text error[E0308]: mismatched types --> ./t.rs:1:6 | 1 | fn f(&mut bar: u32) {} | ^^^^^^^^----- | | | | | expected due to this | expected `u32`, found `&mut _` | help: did you mean `bar`: `&u32` | = note: expected type `u32` found mutable reference `&mut _` error[E0308]: mismatched types --> ./t.rs:4:23 | 4 | let _: fn(u32) = |&mut a| (); | ^^^^^-- | | | | | expected due to this | expected `u32`, found `&mut _` | help: did you mean `a`: `&u32` | = note: expected type `u32` found mutable reference `&mut _` ``` It's hard to see, but 1. The help span is overlapping with "expected" spans 2. It suggests `fn f( &u32) {}` (no `mut` and lost parameter name) and `|&u32 ()` (no closing `|` and lost parameter name) I've tried to fix this. r? `@compiler-errors`
Rollup of 7 pull requests Successful merges: - rust-lang#97202 (os str capacity documentation) - rust-lang#97964 (Fix suggestions for `&a: T` parameters) - rust-lang#98053 (Fix generic impl rustdoc json output) - rust-lang#98059 (Inline `const_eval_select`) - rust-lang#98092 (Fix sidebar items expand collapse) - rust-lang#98119 (Refactor path segment parameter error) - rust-lang#98135 (Add regression test for rust-lang#93775) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I've accidentally discovered that we have broken suggestions for
&a: T
parameters:It's hard to see, but
fn f( &u32) {}
(nomut
and lost parameter name) and|&u32 ()
(no closing|
and lost parameter name)I've tried to fix this.
r? @compiler-errors