Rollup merge of #106291 - obeis:issue-106182, r=oli-obk
Fix incorrect suggestion for extra `&` in pattern Closes #106182
This commit is contained in:
commit
37c1d6dc09
@ -761,6 +761,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
err.span_note(sp, format!("{msg}: `{sugg}`"));
|
||||
}
|
||||
}
|
||||
hir::Node::Pat(pt) if let PatKind::TupleStruct(_, pat_arr, _) = pt.kind => {
|
||||
for i in pat_arr.iter() {
|
||||
if let PatKind::Ref(the_ref, _) = i.kind
|
||||
&& let PatKind::Binding(mt, _, ident, _) = the_ref.kind {
|
||||
let hir::BindingAnnotation(_, mtblty) = mt;
|
||||
err.span_suggestion_verbose(
|
||||
i.span,
|
||||
format!("consider removing `&{mutability}` from the pattern"),
|
||||
mtblty.prefix_str().to_string() + &ident.name.to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some((sp, msg, sugg)) = mut_var_suggestion {
|
||||
err.span_note(sp, format!("{msg}: `{sugg}`"));
|
||||
}
|
||||
}
|
||||
hir::Node::Param(_) | hir::Node::Arm(_) | hir::Node::Pat(_) => {
|
||||
// rely on match ergonomics or it might be nested `&&pat`
|
||||
err.span_suggestion_verbose(
|
||||
|
14
src/test/ui/mismatched_types/issue-106182.fixed
Normal file
14
src/test/ui/mismatched_types/issue-106182.fixed
Normal file
@ -0,0 +1,14 @@
|
||||
// run-rustfix
|
||||
|
||||
struct _S(u32, Vec<i32>);
|
||||
|
||||
fn _foo(x: &_S) {
|
||||
match x {
|
||||
_S(mut _y, _v) => {
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
14
src/test/ui/mismatched_types/issue-106182.rs
Normal file
14
src/test/ui/mismatched_types/issue-106182.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// run-rustfix
|
||||
|
||||
struct _S(u32, Vec<i32>);
|
||||
|
||||
fn _foo(x: &_S) {
|
||||
match x {
|
||||
_S(& (mut _y), _v) => {
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
18
src/test/ui/mismatched_types/issue-106182.stderr
Normal file
18
src/test/ui/mismatched_types/issue-106182.stderr
Normal file
@ -0,0 +1,18 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-106182.rs:7:12
|
||||
|
|
||||
LL | match x {
|
||||
| - this expression has type `&_S`
|
||||
LL | _S(& (mut _y), _v) => {
|
||||
| ^^^^^^^^^^ expected `u32`, found reference
|
||||
|
|
||||
= note: expected type `u32`
|
||||
found reference `&_`
|
||||
help: consider removing `&` from the pattern
|
||||
|
|
||||
LL | _S(mut _y, _v) => {
|
||||
| ~~~~~~
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -336,9 +336,8 @@ LL | let S(&mut _b) = S(0);
|
||||
| ^^^^^^^
|
||||
help: consider removing `&mut` from the pattern
|
||||
|
|
||||
LL - let S(&mut _b) = S(0);
|
||||
LL + let S(_b) = S(0);
|
||||
|
|
||||
LL | let S(_b) = S(0);
|
||||
| ~~
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/ref-pat-suggestions.rs:31:14
|
||||
|
Loading…
x
Reference in New Issue
Block a user