Skip to content

Commit 8bde5bb

Browse files
committed
Fix suggestion when there are arguments in the method
1 parent 85ff888 commit 8bde5bb

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
392392
),
393393
match &args[..] {
394394
[] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()),
395-
[first, ..] => (base.span.until(first.span), String::new()),
395+
[first, ..] => (base.span.between(first.span), ", ".to_string()),
396396
},
397397
]
398398
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![allow(unused)]
2+
3+
struct X {
4+
x: (),
5+
}
6+
pub trait A {
7+
fn foo(&mut self, _: usize) -> &mut ();
8+
}
9+
impl A for X {
10+
fn foo(&mut self, _: usize) -> &mut () {
11+
&mut self.x
12+
}
13+
}
14+
impl X {
15+
fn foo(&mut self, _: usize) -> &mut Self {
16+
self
17+
}
18+
}
19+
20+
fn main() {
21+
let mut x = X { x: () };
22+
*x.foo(0) = (); //~ ERROR E0308
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/shadowed-lplace-method-2.rs:22:17
3+
|
4+
LL | *x.foo(0) = ();
5+
| --------- ^^ expected struct `X`, found `()`
6+
| |
7+
| expected due to the type of this binding
8+
|
9+
note: the `foo` call is resolved to the method in `X`, shadowing the method of the same name on trait `A`
10+
--> $DIR/shadowed-lplace-method-2.rs:22:8
11+
|
12+
LL | *x.foo(0) = ();
13+
| ^^^ refers to `X::foo`
14+
help: you might have meant to call the other method; you can use the fully-qualified path to call it explicitly
15+
|
16+
LL | *<_ as A>::foo(&mut x, 0) = ();
17+
| ++++++++++++++++++ ~
18+
help: try wrapping the expression in `X`
19+
|
20+
LL | *x.foo(0) = X { x: () };
21+
| ++++++ +
22+
23+
error: aborting due to previous error
24+
25+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)