summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/borrowck')
-rw-r--r--tests/ui/borrowck/borrowck-thread-local-static-borrow-outlives-fn.stderr2
-rw-r--r--tests/ui/borrowck/issue-111554.rs28
-rw-r--r--tests/ui/borrowck/issue-111554.stderr29
3 files changed, 58 insertions, 1 deletions
diff --git a/tests/ui/borrowck/borrowck-thread-local-static-borrow-outlives-fn.stderr b/tests/ui/borrowck/borrowck-thread-local-static-borrow-outlives-fn.stderr
index 26453b42f..2f397f6b5 100644
--- a/tests/ui/borrowck/borrowck-thread-local-static-borrow-outlives-fn.stderr
+++ b/tests/ui/borrowck/borrowck-thread-local-static-borrow-outlives-fn.stderr
@@ -4,7 +4,7 @@ error[E0712]: thread-local variable borrowed past end of function
LL | assert_static(&FOO);
| ^^^^ thread-local variables cannot be borrowed beyond the end of the function
LL | }
- | - end of enclosing function is here
+ | - end of enclosing function is here
error: aborting due to previous error
diff --git a/tests/ui/borrowck/issue-111554.rs b/tests/ui/borrowck/issue-111554.rs
new file mode 100644
index 000000000..0dad55be3
--- /dev/null
+++ b/tests/ui/borrowck/issue-111554.rs
@@ -0,0 +1,28 @@
+struct Foo {}
+
+impl Foo {
+ pub fn foo(&mut self) {
+ || bar(&mut self);
+ //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
+ }
+
+ pub fn baz(&self) {
+ || bar(&mut self);
+ //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
+ //~| ERROR cannot borrow data in a `&` reference as mutable
+ }
+
+ pub fn qux(mut self) {
+ || bar(&mut self);
+ // OK
+ }
+
+ pub fn quux(self) {
+ || bar(&mut self);
+ //~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
+ }
+}
+
+fn bar(_: &mut Foo) {}
+
+fn main() {}
diff --git a/tests/ui/borrowck/issue-111554.stderr b/tests/ui/borrowck/issue-111554.stderr
new file mode 100644
index 000000000..6b7a42e49
--- /dev/null
+++ b/tests/ui/borrowck/issue-111554.stderr
@@ -0,0 +1,29 @@
+error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
+ --> $DIR/issue-111554.rs:5:16
+ |
+LL | || bar(&mut self);
+ | ^^^^^^^^^ cannot borrow as mutable
+
+error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
+ --> $DIR/issue-111554.rs:10:16
+ |
+LL | || bar(&mut self);
+ | ^^^^^^^^^ cannot borrow as mutable
+
+error[E0596]: cannot borrow data in a `&` reference as mutable
+ --> $DIR/issue-111554.rs:10:16
+ |
+LL | || bar(&mut self);
+ | ^^^^^^^^^ cannot borrow as mutable
+
+error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
+ --> $DIR/issue-111554.rs:21:16
+ |
+LL | pub fn quux(self) {
+ | ---- help: consider changing this to be mutable: `mut self`
+LL | || bar(&mut self);
+ | ^^^^^^^^^ cannot borrow as mutable
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0596`.