-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Be more obvious when suggesting dereference #45947
Be more obvious when suggesting dereference #45947
Conversation
I'm still not quite sure I understand the error... Isn't |
It is a pattern match, though, right? I was under the impression that in Rust all arguments to functions and closures are actually patterns, which can bind new names, just as in an Another way of asking the question is to ask if |
Ah, I see. The correct pattern would be |
Hmm... so the hint was actually on the right track. It suggests replacing |
Can't we just adjust our error message until it includes all the surrounding reference patterns, so we'll get this: error: non-reference pattern used to match a reference (see issue #42640)
--> src/coord.rs:194:23
|
194 | .filter(|&(ref k, _)| self.hash(k) == server)
| ^^^^^^^^^^^ help: consider using: `&&(ref k, _)`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error: aborting due to previous error
error: Could not compile `kv_2pc`.
To learn more, run the command again with --verbose. |
@arielb1 yeah, I think that's a better approach. |
Hi @estebank, what is the status of this PR? |
8b8dbaa
to
8ca6925
Compare
What problems do you foresee with it? |
src/libsyntax_pos/lib.rs
Outdated
let lo = if span_lo == 0 { | ||
0 | ||
} else { | ||
span_lo - 1 |
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.
Doesn't this mean we now have the same problem with the following case:
let x = &&&0;
let &&x = x;
IIUC, the error message would suggest using &&
, right?
src/libsyntax_pos/lib.rs
Outdated
let span = self.data(); | ||
let span_lo = span.lo.0; | ||
let lo = if span_lo == 0 { | ||
0 |
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.
This looks likely to introduce an infinite loop in some case, where we go up to the start of the file. You can return an Option<Span>
instead.
Please don't fiddle with spans, it causes very weird situations with macros. You can use |
b28b38e
to
f1a672c
Compare
@@ -120,15 +120,33 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
.pat_adjustments_mut() | |||
.insert(pat.hir_id, pat_adjustments); | |||
} else { | |||
let mut ref_sp = pat.span; | |||
let mut id = pat.id; | |||
loop { // make span include all enclosing `&` to avoid confusing diag output |
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.
nit: s/loop/while let/
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.
ok a while-let would be ugly too. Why can't we have a do-while loop?
@bors r+ |
📌 Commit f1a672c has been approved by |
@bors r- CI failed, the UI test |
☔ The latest upstream changes (presumably #46116) made this pull request unmergeable. Please resolve the merge conflicts. |
Include enclosing span when suggesting dereference on a span that is already a reference: ``` error: non-reference pattern used to match a reference (see issue rust-lang#42640) --> dont-suggest-dereference-on-arg.rs:16:19 | 16 | .filter(|&(ref a, _)| foo(a)) | ^^^^^^^^^^^ help: consider using: `&&(ref k, _)` | = help: add #![feature(match_default_bindings)] to the crate attributes to enable ```
33f0684
to
48d291a
Compare
x.iter() | ||
.filter(|&(ref a, _)| foo(a)) | ||
//~^ ERROR non-reference pattern used to match a reference | ||
//~| HELP consider using a reference |
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.
[00:47:09] error: /checkout/src/test/ui/suggestions/dont-suggest-dereference-on-arg.rs:16: unexpected help message: '16:18: 16:29: add #![feature(match_default_bindings)] to the crate attributes to enable'
Needs one more //~| HELP
.
48d291a
to
15dfd7e
Compare
@bors r=arielb1 |
📌 Commit 15dfd7e has been approved by |
…ielb1 Be more obvious when suggesting dereference Include `&` span when suggesting dereference on a span that is already a reference: ``` error: non-reference pattern used to match a reference (see issue #42640) --> dont-suggest-dereference-on-arg.rs:16:19 | 16 | .filter(|&(ref a, _)| foo(a)) | ^^^^^^^^^^^ help: consider using: `&&(ref k, _)` | = help: add #![feature(match_default_bindings)] to the crate attributes to enable ``` Fix #45925.
☀️ Test successful - status-appveyor, status-travis |
Include
&
span when suggesting dereference on a span that is already a reference:Fix #45925.