about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev+love@gmail.com>2023-01-08 17:01:46 +0900
committerGitHub <noreply@github.com>2023-01-08 17:01:46 +0900
commitfe075319e6d21ffce8978b8861de1f8b34cd7bcc (patch)
tree0a8efbcb213da88e07a42a69d38e1689010b9169 /src/test/ui
parented77ffe166506422f208f3a3870e77893ae84449 (diff)
parent23c3a307300827dbd53637742905293b9240506a (diff)
downloadrust-fe075319e6d21ffce8978b8861de1f8b34cd7bcc.tar.gz
rust-fe075319e6d21ffce8978b8861de1f8b34cd7bcc.zip
Rollup merge of #106410 - clubby789:borrow-mut-self-mut-self-diag, r=compiler-errors
Suggest `mut self: &mut Self` for `?Sized` impls

Closes #106325
Closes #93078

The suggestion is _probably_ not what the user wants (hence `MaybeIncorrect`) but at least makes the problem in the above issues clearer. It might be better to add a note explaining why this is the case, but I'm not sure how best to word that so this is a start.

``@rustbot`` label +A-diagnostics
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/borrowck/issue-93078.rs15
-rw-r--r--src/test/ui/borrowck/issue-93078.stderr12
2 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/issue-93078.rs b/src/test/ui/borrowck/issue-93078.rs
new file mode 100644
index 00000000000..2e608c5db3e
--- /dev/null
+++ b/src/test/ui/borrowck/issue-93078.rs
@@ -0,0 +1,15 @@
+trait Modify {
+    fn modify(&mut self) ;
+}
+
+impl<T> Modify for T  {
+    fn modify(&mut self)  {}
+}
+
+trait Foo {
+    fn mute(&mut self) {
+        self.modify(); //~ ERROR cannot borrow `self` as mutable
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/issue-93078.stderr b/src/test/ui/borrowck/issue-93078.stderr
new file mode 100644
index 00000000000..771a652a173
--- /dev/null
+++ b/src/test/ui/borrowck/issue-93078.stderr
@@ -0,0 +1,12 @@
+error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
+  --> $DIR/issue-93078.rs:11:9
+   |
+LL |         self.modify();
+   |         ^^^^^^^^^^^^^ cannot borrow as mutable
+   |
+   = note: as `Self` may be unsized, this call attempts to take `&mut &mut self`
+   = note: however, `&mut self` expands to `self: &mut Self`, therefore `self` cannot be borrowed mutably
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0596`.