about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-12-26 12:29:16 -0800
committerEsteban Küber <esteban@kuber.com.ar>2022-12-26 12:43:52 -0800
commit8bde5bbc07e94fd8d39c263f873c53131b617d24 (patch)
tree448d00d85bf0246d9c0ad8e272194008e7924ebc
parent85ff8889e455c1e88723a6d7450042e17f91657a (diff)
downloadrust-8bde5bbc07e94fd8d39c263f873c53131b617d24.tar.gz
rust-8bde5bbc07e94fd8d39c263f873c53131b617d24.zip
Fix suggestion when there are arguments in the method
-rw-r--r--compiler/rustc_hir_typeck/src/demand.rs2
-rw-r--r--src/test/ui/suggestions/shadowed-lplace-method-2.rs23
-rw-r--r--src/test/ui/suggestions/shadowed-lplace-method-2.stderr25
3 files changed, 49 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs
index ea34cd94f8a..5afd2ad045e 100644
--- a/compiler/rustc_hir_typeck/src/demand.rs
+++ b/compiler/rustc_hir_typeck/src/demand.rs
@@ -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()),
                     },
                 ]
             })
diff --git a/src/test/ui/suggestions/shadowed-lplace-method-2.rs b/src/test/ui/suggestions/shadowed-lplace-method-2.rs
new file mode 100644
index 00000000000..dab99fbacd9
--- /dev/null
+++ b/src/test/ui/suggestions/shadowed-lplace-method-2.rs
@@ -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
+}
diff --git a/src/test/ui/suggestions/shadowed-lplace-method-2.stderr b/src/test/ui/suggestions/shadowed-lplace-method-2.stderr
new file mode 100644
index 00000000000..94eef15f330
--- /dev/null
+++ b/src/test/ui/suggestions/shadowed-lplace-method-2.stderr
@@ -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`.