Fix suggestion when there are arguments in the method

This commit is contained in:
Esteban Küber 2022-12-26 12:29:16 -08:00
parent 85ff8889e4
commit 8bde5bbc07
3 changed files with 49 additions and 1 deletions

View File

@ -392,7 +392,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
),
match &args[..] {
[] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()),
[first, ..] => (base.span.until(first.span), String::new()),
[first, ..] => (base.span.between(first.span), ", ".to_string()),
},
]
})

View File

@ -0,0 +1,23 @@
#![allow(unused)]
struct X {
x: (),
}
pub trait A {
fn foo(&mut self, _: usize) -> &mut ();
}
impl A for X {
fn foo(&mut self, _: usize) -> &mut () {
&mut self.x
}
}
impl X {
fn foo(&mut self, _: usize) -> &mut Self {
self
}
}
fn main() {
let mut x = X { x: () };
*x.foo(0) = (); //~ ERROR E0308
}

View File

@ -0,0 +1,25 @@
error[E0308]: mismatched types
--> $DIR/shadowed-lplace-method-2.rs:22:17
|
LL | *x.foo(0) = ();
| --------- ^^ expected struct `X`, found `()`
| |
| expected due to the type of this binding
|
note: the `foo` call is resolved to the method in `X`, shadowing the method of the same name on trait `A`
--> $DIR/shadowed-lplace-method-2.rs:22:8
|
LL | *x.foo(0) = ();
| ^^^ refers to `X::foo`
help: you might have meant to call the other method; you can use the fully-qualified path to call it explicitly
|
LL | *<_ as A>::foo(&mut x, 0) = ();
| ++++++++++++++++++ ~
help: try wrapping the expression in `X`
|
LL | *x.foo(0) = X { x: () };
| ++++++ +
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.