summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/ui/borrowck
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/borrowck')
-rw-r--r--tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr32
-rw-r--r--tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr4
-rw-r--r--tests/ui/borrowck/borrowck-access-permissions.stderr6
-rw-r--r--tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr8
-rw-r--r--tests/ui/borrowck/borrowck-block-uninit.rs (renamed from tests/ui/borrowck/borrowck-block-unint.rs)0
-rw-r--r--tests/ui/borrowck/borrowck-block-uninit.stderr (renamed from tests/ui/borrowck/borrowck-block-unint.stderr)2
-rw-r--r--tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr4
-rw-r--r--tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs1
-rw-r--r--tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs1
-rw-r--r--tests/ui/borrowck/borrowck-issue-14498.stderr2
-rw-r--r--tests/ui/borrowck/borrowck-reborrow-from-mut.stderr2
-rw-r--r--tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs2
-rw-r--r--tests/ui/borrowck/borrowck-vec-pattern-nesting.rs2
-rw-r--r--tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr18
-rw-r--r--tests/ui/borrowck/erase-error-in-mir-drop-tracking.rs23
-rw-r--r--tests/ui/borrowck/erase-error-in-mir-drop-tracking.stderr24
-rw-r--r--tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed39
-rw-r--r--tests/ui/borrowck/issue-109271-pass-self-into-closure.rs39
-rw-r--r--tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr85
-rw-r--r--tests/ui/borrowck/issue-45199.rs3
-rw-r--r--tests/ui/borrowck/issue-45199.stderr4
-rw-r--r--tests/ui/borrowck/issue-47646.rs13
-rw-r--r--tests/ui/borrowck/issue-47646.stderr20
-rw-r--r--tests/ui/borrowck/issue-85765.stderr2
-rw-r--r--tests/ui/borrowck/let_underscore_temporary.rs30
-rw-r--r--tests/ui/borrowck/let_underscore_temporary.stderr79
-rw-r--r--tests/ui/borrowck/move-error-snippets-ext.rs2
-rw-r--r--tests/ui/borrowck/mutability-errors.stderr24
-rw-r--r--tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.rs11
-rw-r--r--tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.stderr43
-rw-r--r--tests/ui/borrowck/tainted-promoteds.rs12
-rw-r--r--tests/ui/borrowck/tainted-promoteds.stderr14
32 files changed, 490 insertions, 61 deletions
diff --git a/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr b/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr
index 0ca14c3f3..047175626 100644
--- a/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr
+++ b/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr
@@ -1,19 +1,3 @@
-error: cannot borrow value as mutable because it is also borrowed as immutable
- --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:36:9
- |
-LL | ref foo @ [.., ref mut bar] => (),
- | ^^^^^^^ ----------- value is mutably borrowed by `bar` here
- | |
- | value is borrowed by `foo` here
-
-error: cannot borrow value as mutable because it is also borrowed as immutable
- --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:120:9
- |
-LL | ref foo @ Some(box ref mut s) => (),
- | ^^^^^^^ --------- value is mutably borrowed by `s` here
- | |
- | value is borrowed by `foo` here
-
error[E0382]: borrow of moved value: `x`
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:18:5
|
@@ -43,6 +27,14 @@ LL | &x;
LL | drop(r);
| - mutable borrow later used here
+error: cannot borrow value as mutable because it is also borrowed as immutable
+ --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:36:9
+ |
+LL | ref foo @ [.., ref mut bar] => (),
+ | ^^^^^^^ ----------- value is mutably borrowed by `bar` here
+ | |
+ | value is borrowed by `foo` here
+
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:50:5
|
@@ -120,6 +112,14 @@ LL | &mut x;
LL | drop(r);
| - immutable borrow later used here
+error: cannot borrow value as mutable because it is also borrowed as immutable
+ --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:120:9
+ |
+LL | ref foo @ Some(box ref mut s) => (),
+ | ^^^^^^^ --------- value is mutably borrowed by `s` here
+ | |
+ | value is borrowed by `foo` here
+
error[E0382]: borrow of moved value: `x`
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:134:5
|
diff --git a/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr b/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr
index 4cc1d821d..cfc86ff0d 100644
--- a/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr
+++ b/tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr
@@ -7,7 +7,7 @@ LL | let q = &raw mut *x;
help: consider changing this to be a mutable reference
|
LL | let x = &mut 0;
- | ~~~~~~
+ | +++
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
--> $DIR/borrow-raw-address-of-deref-mutability.rs:14:13
@@ -18,7 +18,7 @@ LL | let q = &raw mut *x;
help: consider changing this to be a mutable pointer
|
LL | let x = &mut 0 as *const i32;
- | ~~~~~~
+ | +++
error: aborting due to 2 previous errors
diff --git a/tests/ui/borrowck/borrowck-access-permissions.stderr b/tests/ui/borrowck/borrowck-access-permissions.stderr
index 26f3e2bbd..c161e2d95 100644
--- a/tests/ui/borrowck/borrowck-access-permissions.stderr
+++ b/tests/ui/borrowck/borrowck-access-permissions.stderr
@@ -35,7 +35,7 @@ LL | let _y1 = &mut *ref_x;
help: consider changing this to be a mutable reference
|
LL | let ref_x = &mut x;
- | ~~~~~~
+ | +++
error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
--> $DIR/borrowck-access-permissions.rs:39:23
@@ -46,7 +46,7 @@ LL | let _y1 = &mut *ptr_x;
help: consider changing this to be a mutable pointer
|
LL | let ptr_x : *const _ = &mut x;
- | ~~~~~~
+ | +++
error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:48:18
@@ -57,7 +57,7 @@ LL | let _y = &mut *foo_ref.f;
help: consider changing this to be a mutable reference
|
LL | let foo_ref = &mut foo;
- | ~~~~~~~~
+ | +++
error: aborting due to 6 previous errors
diff --git a/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr b/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr
index cbacc87a0..cf0c4127d 100644
--- a/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr
+++ b/tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr
@@ -6,8 +6,8 @@ LL | *s.pointer += 1;
|
help: consider changing this to be a mutable reference
|
-LL | fn a(s: &mut S<'_>) {
- | ~~~~~~~~~~
+LL | fn a(s: &mut S) {
+ | +++
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
@@ -17,8 +17,8 @@ LL | *s.pointer += 1;
|
help: consider changing this to be a mutable reference
|
-LL | fn c(s: &mut &mut S<'_>) {
- | ~~~~~~~~~~~~~~~
+LL | fn c(s: &mut &mut S) {
+ | +++
error: aborting due to 2 previous errors
diff --git a/tests/ui/borrowck/borrowck-block-unint.rs b/tests/ui/borrowck/borrowck-block-uninit.rs
index 8d13b25a3..8d13b25a3 100644
--- a/tests/ui/borrowck/borrowck-block-unint.rs
+++ b/tests/ui/borrowck/borrowck-block-uninit.rs
diff --git a/tests/ui/borrowck/borrowck-block-unint.stderr b/tests/ui/borrowck/borrowck-block-uninit.stderr
index f47921a97..1a5969586 100644
--- a/tests/ui/borrowck/borrowck-block-unint.stderr
+++ b/tests/ui/borrowck/borrowck-block-uninit.stderr
@@ -1,5 +1,5 @@
error[E0381]: used binding `x` isn't initialized
- --> $DIR/borrowck-block-unint.rs:4:11
+ --> $DIR/borrowck-block-uninit.rs:4:11
|
LL | let x: isize;
| - binding declared here but left uninitialized
diff --git a/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr b/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr
index dd0817ff2..59ef61b19 100644
--- a/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr
+++ b/tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr
@@ -27,8 +27,8 @@ LL | let x: &mut isize = &mut **t0;
|
help: consider changing this to be a mutable reference
|
-LL | fn foo4(t0: &mut &mut isize) {
- | ~~~~~~~~~~~~~~~
+LL | fn foo4(t0: &mut &mut isize) {
+ | +++
error: aborting due to 3 previous errors
diff --git a/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs b/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs
index 0229ca37a..60128c941 100644
--- a/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs
+++ b/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs
@@ -1,6 +1,7 @@
// Check that closure captures for slice patterns are inferred correctly
#![allow(unused_variables)]
+#![allow(dropping_references)]
// run-pass
diff --git a/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs b/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs
index dd6708582..78e965cc4 100644
--- a/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs
+++ b/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs
@@ -1,6 +1,7 @@
// run-pass
#![allow(unused_mut)]
#![allow(unused_variables)]
+#![allow(dropping_copy_types)]
// pretty-expanded FIXME #23616
struct A { a: isize, b: Box<isize> }
diff --git a/tests/ui/borrowck/borrowck-issue-14498.stderr b/tests/ui/borrowck/borrowck-issue-14498.stderr
index 374c5ee3e..12d67d536 100644
--- a/tests/ui/borrowck/borrowck-issue-14498.stderr
+++ b/tests/ui/borrowck/borrowck-issue-14498.stderr
@@ -7,7 +7,7 @@ LL | ***p = 2;
help: consider changing this to be a mutable reference
|
LL | let p = &mut y;
- | ~~~~~~
+ | +++
error[E0506]: cannot assign to `**y` because it is borrowed
--> $DIR/borrowck-issue-14498.rs:25:5
diff --git a/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr b/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr
index d9590e446..fb3db4e14 100644
--- a/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr
+++ b/tests/ui/borrowck/borrowck-reborrow-from-mut.stderr
@@ -111,7 +111,7 @@ LL | let _bar1 = &mut foo.bar1;
help: consider changing this to be a mutable reference
|
LL | fn borrow_mut_from_imm(foo: &mut Foo) {
- | ~~~~~~~~
+ | +++
error: aborting due to 11 previous errors
diff --git a/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs b/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs
index 1cf763f66..9acb1ec5e 100644
--- a/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs
+++ b/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs
@@ -1,6 +1,8 @@
// run-pass
// pretty-expanded FIXME #23616
+#![allow(dropping_copy_types)]
+
struct A { a: isize, b: Box<isize> }
fn field_copy_after_field_borrow() {
diff --git a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs
index 127a3f5b2..1bda7a497 100644
--- a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs
+++ b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs
@@ -8,7 +8,6 @@ fn a() {
//~^ NOTE `vec[_]` is borrowed here
vec[0] = Box::new(4); //~ ERROR cannot assign
//~^ NOTE `vec[_]` is assigned to here
- //~| NOTE in this expansion of desugaring of drop and replace
_a.use_ref();
//~^ NOTE borrow later used here
}
@@ -23,7 +22,6 @@ fn b() {
//~^ `vec[_]` is borrowed here
vec[0] = Box::new(4); //~ ERROR cannot assign
//~^ NOTE `vec[_]` is assigned to here
- //~| NOTE in this expansion of desugaring of drop and replace
_b.use_ref();
//~^ NOTE borrow later used here
}
diff --git a/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr b/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr
index 5e1251b05..70b9e4f44 100644
--- a/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr
+++ b/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr
@@ -6,24 +6,24 @@ LL | [box ref _a, _, _] => {
LL |
LL | vec[0] = Box::new(4);
| ^^^^^^ `vec[_]` is assigned to here but it was already borrowed
-...
+LL |
LL | _a.use_ref();
| ------------ borrow later used here
error[E0506]: cannot assign to `vec[_]` because it is borrowed
- --> $DIR/borrowck-vec-pattern-nesting.rs:24:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:23:13
|
LL | &mut [ref _b @ ..] => {
| ------ `vec[_]` is borrowed here
LL |
LL | vec[0] = Box::new(4);
| ^^^^^^ `vec[_]` is assigned to here but it was already borrowed
-...
+LL |
LL | _b.use_ref();
| ------------ borrow later used here
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:36:11
+ --> $DIR/borrowck-vec-pattern-nesting.rs:34:11
|
LL | match vec {
| ^^^ cannot move out of here
@@ -41,7 +41,7 @@ LL + [_a,
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:48:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:46:13
|
LL | let a = vec[0];
| ^^^^^^
@@ -55,7 +55,7 @@ LL | let a = &vec[0];
| +
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:57:11
+ --> $DIR/borrowck-vec-pattern-nesting.rs:55:11
|
LL | match vec {
| ^^^ cannot move out of here
@@ -73,7 +73,7 @@ LL + [
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:67:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:65:13
|
LL | let a = vec[0];
| ^^^^^^
@@ -87,7 +87,7 @@ LL | let a = &vec[0];
| +
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:76:11
+ --> $DIR/borrowck-vec-pattern-nesting.rs:74:11
|
LL | match vec {
| ^^^ cannot move out of here
@@ -106,7 +106,7 @@ LL + [_a, _b, _c] => {}
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:87:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:85:13
|
LL | let a = vec[0];
| ^^^^^^
diff --git a/tests/ui/borrowck/erase-error-in-mir-drop-tracking.rs b/tests/ui/borrowck/erase-error-in-mir-drop-tracking.rs
new file mode 100644
index 000000000..addbe5d65
--- /dev/null
+++ b/tests/ui/borrowck/erase-error-in-mir-drop-tracking.rs
@@ -0,0 +1,23 @@
+// compile-flags: -Zdrop-tracking-mir
+// edition:2021
+
+use std::future::Future;
+
+trait Client {
+ type Connecting<'a>: Future + Send
+ where
+ Self: 'a;
+
+ fn connect(&'_ self) -> Self::Connecting<'a>;
+ //~^ ERROR use of undeclared lifetime name `'a`
+}
+
+fn call_connect<C>(c: &'_ C) -> impl '_ + Future + Send
+where
+ C: Client + Send + Sync,
+{
+ async move { c.connect().await }
+ //~^ ERROR `C` does not live long enough
+}
+
+fn main() {}
diff --git a/tests/ui/borrowck/erase-error-in-mir-drop-tracking.stderr b/tests/ui/borrowck/erase-error-in-mir-drop-tracking.stderr
new file mode 100644
index 000000000..53abe3dc9
--- /dev/null
+++ b/tests/ui/borrowck/erase-error-in-mir-drop-tracking.stderr
@@ -0,0 +1,24 @@
+error[E0261]: use of undeclared lifetime name `'a`
+ --> $DIR/erase-error-in-mir-drop-tracking.rs:11:46
+ |
+LL | fn connect(&'_ self) -> Self::Connecting<'a>;
+ | ^^ undeclared lifetime
+ |
+help: consider introducing lifetime `'a` here
+ |
+LL | fn connect<'a>(&'_ self) -> Self::Connecting<'a>;
+ | ++++
+help: consider introducing lifetime `'a` here
+ |
+LL | trait Client<'a> {
+ | ++++
+
+error: `C` does not live long enough
+ --> $DIR/erase-error-in-mir-drop-tracking.rs:19:5
+ |
+LL | async move { c.connect().await }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0261`.
diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed b/tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed
new file mode 100644
index 000000000..4a8831dab
--- /dev/null
+++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.fixed
@@ -0,0 +1,39 @@
+// run-rustfix
+#![allow(unused)]
+struct S;
+
+impl S {
+ fn call(&mut self, f: impl FnOnce((), &mut Self)) {
+ // change state or something ...
+ f((), self);
+ // change state or something ...
+ }
+
+ fn get(&self) {}
+ fn set(&mut self) {}
+}
+
+fn main() {
+ let mut v = S;
+
+ v.call(|(), this: &mut S| this.get());
+ //~^ error: cannot borrow `v` as mutable because it is also borrowed as immutable
+ v.call(|(), this: &mut S| this.set());
+ //~^ error: cannot borrow `v` as mutable more than once at a time
+ //~| error: cannot borrow `v` as mutable more than once at a time
+
+ v.call(|(), this: &mut S| {
+ //~^ error: cannot borrow `v` as mutable more than once at a time
+ //~| error: cannot borrow `v` as mutable more than once at a time
+
+ _ = this;
+ this.set();
+ this.get();
+ S::get(&this);
+
+ use std::ops::Add;
+ let v = 0u32;
+ _ = v + v;
+ _ = v.add(3);
+ });
+}
diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.rs b/tests/ui/borrowck/issue-109271-pass-self-into-closure.rs
new file mode 100644
index 000000000..fcd855f86
--- /dev/null
+++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.rs
@@ -0,0 +1,39 @@
+// run-rustfix
+#![allow(unused)]
+struct S;
+
+impl S {
+ fn call(&mut self, f: impl FnOnce((), &mut Self)) {
+ // change state or something ...
+ f((), self);
+ // change state or something ...
+ }
+
+ fn get(&self) {}
+ fn set(&mut self) {}
+}
+
+fn main() {
+ let mut v = S;
+
+ v.call(|(), this: &mut S| v.get());
+ //~^ error: cannot borrow `v` as mutable because it is also borrowed as immutable
+ v.call(|(), this: &mut S| v.set());
+ //~^ error: cannot borrow `v` as mutable more than once at a time
+ //~| error: cannot borrow `v` as mutable more than once at a time
+
+ v.call(|(), this: &mut S| {
+ //~^ error: cannot borrow `v` as mutable more than once at a time
+ //~| error: cannot borrow `v` as mutable more than once at a time
+
+ _ = v;
+ v.set();
+ v.get();
+ S::get(&v);
+
+ use std::ops::Add;
+ let v = 0u32;
+ _ = v + v;
+ _ = v.add(3);
+ });
+}
diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr
new file mode 100644
index 000000000..25974e0d0
--- /dev/null
+++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr
@@ -0,0 +1,85 @@
+error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
+ --> $DIR/issue-109271-pass-self-into-closure.rs:19:5
+ |
+LL | v.call(|(), this: &mut S| v.get());
+ | ^^----^------------------^-^^^^^^^
+ | | | | |
+ | | | | first borrow occurs due to use of `v` in closure
+ | | | | help: try using the closure argument: `this`
+ | | | immutable borrow occurs here
+ | | immutable borrow later used by call
+ | mutable borrow occurs here
+
+error[E0499]: cannot borrow `v` as mutable more than once at a time
+ --> $DIR/issue-109271-pass-self-into-closure.rs:21:5
+ |
+LL | v.call(|(), this: &mut S| v.set());
+ | ^^----^------------------^-^^^^^^^
+ | | | | |
+ | | | | first borrow occurs due to use of `v` in closure
+ | | | | help: try using the closure argument: `this`
+ | | | first mutable borrow occurs here
+ | | first borrow later used by call
+ | second mutable borrow occurs here
+
+error[E0499]: cannot borrow `v` as mutable more than once at a time
+ --> $DIR/issue-109271-pass-self-into-closure.rs:21:12
+ |
+LL | v.call(|(), this: &mut S| v.set());
+ | -------^^^^^^^^^^^^^^^^^^---------
+ | | | | |
+ | | | | second borrow occurs due to use of `v` in closure
+ | | | second mutable borrow occurs here
+ | | first borrow later used by call
+ | first mutable borrow occurs here
+
+error[E0499]: cannot borrow `v` as mutable more than once at a time
+ --> $DIR/issue-109271-pass-self-into-closure.rs:25:5
+ |
+LL | v.call(|(), this: &mut S| {
+ | ^ ---- ------------------ first mutable borrow occurs here
+ | | |
+ | _____| first borrow later used by call
+ | |
+LL | |
+LL | |
+LL | |
+LL | | _ = v;
+LL | | v.set();
+ | | - first borrow occurs due to use of `v` in closure
+... |
+LL | | _ = v.add(3);
+LL | | });
+ | |______^ second mutable borrow occurs here
+ |
+help: try using the closure argument
+ |
+LL ~ _ = this;
+LL ~ this.set();
+LL ~ this.get();
+LL ~ S::get(&this);
+ |
+
+error[E0499]: cannot borrow `v` as mutable more than once at a time
+ --> $DIR/issue-109271-pass-self-into-closure.rs:25:12
+ |
+LL | v.call(|(), this: &mut S| {
+ | - ---- ^^^^^^^^^^^^^^^^^^ second mutable borrow occurs here
+ | | |
+ | _____| first borrow later used by call
+ | |
+LL | |
+LL | |
+LL | |
+LL | | _ = v;
+LL | | v.set();
+ | | - second borrow occurs due to use of `v` in closure
+... |
+LL | | _ = v.add(3);
+LL | | });
+ | |______- first mutable borrow occurs here
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0499, E0502.
+For more information about an error, try `rustc --explain E0499`.
diff --git a/tests/ui/borrowck/issue-45199.rs b/tests/ui/borrowck/issue-45199.rs
index 6a6b25541..ded46e56e 100644
--- a/tests/ui/borrowck/issue-45199.rs
+++ b/tests/ui/borrowck/issue-45199.rs
@@ -5,7 +5,6 @@ fn test_drop_replace() {
b = Box::new(1); //~ NOTE first assignment
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
- //~| NOTE in this expansion of desugaring of drop and replace
}
fn test_call() {
@@ -14,14 +13,12 @@ fn test_call() {
//~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
- //~| NOTE in this expansion of desugaring of drop and replace
}
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
//~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
//~| NOTE cannot assign to immutable argument
- //~| NOTE in this expansion of desugaring of drop and replace
}
fn main() {}
diff --git a/tests/ui/borrowck/issue-45199.stderr b/tests/ui/borrowck/issue-45199.stderr
index 163f2370b..47aa30908 100644
--- a/tests/ui/borrowck/issue-45199.stderr
+++ b/tests/ui/borrowck/issue-45199.stderr
@@ -10,7 +10,7 @@ LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `b`
- --> $DIR/issue-45199.rs:15:5
+ --> $DIR/issue-45199.rs:14:5
|
LL | let b = Box::new(1);
| -
@@ -22,7 +22,7 @@ LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
error[E0384]: cannot assign to immutable argument `b`
- --> $DIR/issue-45199.rs:22:5
+ --> $DIR/issue-45199.rs:20:5
|
LL | fn test_args(b: Box<i32>) {
| - help: consider making this binding mutable: `mut b`
diff --git a/tests/ui/borrowck/issue-47646.rs b/tests/ui/borrowck/issue-47646.rs
new file mode 100644
index 000000000..ace6cdce8
--- /dev/null
+++ b/tests/ui/borrowck/issue-47646.rs
@@ -0,0 +1,13 @@
+use std::collections::BinaryHeap;
+
+fn main() {
+ let mut heap: BinaryHeap<i32> = BinaryHeap::new();
+ let borrow = heap.peek_mut();
+
+ match (borrow, ()) {
+ (Some(_), ()) => {
+ println!("{:?}", heap); //~ ERROR cannot borrow `heap` as immutable
+ }
+ _ => {}
+ };
+}
diff --git a/tests/ui/borrowck/issue-47646.stderr b/tests/ui/borrowck/issue-47646.stderr
new file mode 100644
index 000000000..84cf9237a
--- /dev/null
+++ b/tests/ui/borrowck/issue-47646.stderr
@@ -0,0 +1,20 @@
+error[E0502]: cannot borrow `heap` as immutable because it is also borrowed as mutable
+ --> $DIR/issue-47646.rs:9:30
+ |
+LL | let borrow = heap.peek_mut();
+ | --------------- mutable borrow occurs here
+LL |
+LL | match (borrow, ()) {
+ | ------------ a temporary with access to the mutable borrow is created here ...
+LL | (Some(_), ()) => {
+LL | println!("{:?}", heap);
+ | ^^^^ immutable borrow occurs here
+...
+LL | };
+ | - ... and the mutable borrow might be used here, when that temporary is dropped and runs the destructor for type `(Option<PeekMut<'_, i32>>, ())`
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0502`.
diff --git a/tests/ui/borrowck/issue-85765.stderr b/tests/ui/borrowck/issue-85765.stderr
index b4bb128cb..2985a658f 100644
--- a/tests/ui/borrowck/issue-85765.stderr
+++ b/tests/ui/borrowck/issue-85765.stderr
@@ -18,7 +18,7 @@ LL | *r = 0;
help: consider changing this to be a mutable reference
|
LL | let r = &mut mutvar;
- | ~~~~~~~~~~~
+ | +++
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
--> $DIR/issue-85765.rs:19:5
diff --git a/tests/ui/borrowck/let_underscore_temporary.rs b/tests/ui/borrowck/let_underscore_temporary.rs
index 37b5c5d9d..835cd2079 100644
--- a/tests/ui/borrowck/let_underscore_temporary.rs
+++ b/tests/ui/borrowck/let_underscore_temporary.rs
@@ -1,4 +1,4 @@
-// check-pass
+// check-fail
fn let_underscore(string: &Option<&str>, mut num: Option<i32>) {
let _ = if let Some(s) = *string { s.len() } else { 0 };
@@ -8,6 +8,7 @@ fn let_underscore(string: &Option<&str>, mut num: Option<i32>) {
s
} else {
&mut 0
+ //~^ ERROR temporary value dropped while borrowed
};
let _ = if let Some(ref s) = num { s } else { &0 };
let _ = if let Some(mut s) = num {
@@ -21,6 +22,33 @@ fn let_underscore(string: &Option<&str>, mut num: Option<i32>) {
s
} else {
&mut 0
+ //~^ ERROR temporary value dropped while borrowed
+ };
+}
+
+fn let_ascribe(string: &Option<&str>, mut num: Option<i32>) {
+ let _: _ = if let Some(s) = *string { s.len() } else { 0 };
+ let _: _ = if let Some(s) = &num { s } else { &0 };
+ let _: _ = if let Some(s) = &mut num {
+ *s += 1;
+ s
+ } else {
+ &mut 0
+ //~^ ERROR temporary value dropped while borrowed
+ };
+ let _: _ = if let Some(ref s) = num { s } else { &0 };
+ let _: _ = if let Some(mut s) = num {
+ s += 1;
+ s
+ } else {
+ 0
+ };
+ let _: _ = if let Some(ref mut s) = num {
+ *s += 1;
+ s
+ } else {
+ &mut 0
+ //~^ ERROR temporary value dropped while borrowed
};
}
diff --git a/tests/ui/borrowck/let_underscore_temporary.stderr b/tests/ui/borrowck/let_underscore_temporary.stderr
new file mode 100644
index 000000000..74f3598c4
--- /dev/null
+++ b/tests/ui/borrowck/let_underscore_temporary.stderr
@@ -0,0 +1,79 @@
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/let_underscore_temporary.rs:10:14
+ |
+LL | let _ = if let Some(s) = &mut num {
+ | _____________-
+LL | | *s += 1;
+LL | | s
+LL | | } else {
+LL | | &mut 0
+ | | ^ creates a temporary value which is freed while still in use
+LL | |
+LL | | };
+ | | -
+ | | |
+ | |_____temporary value is freed at the end of this statement
+ | borrow later used here
+ |
+ = note: consider using a `let` binding to create a longer lived value
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/let_underscore_temporary.rs:24:14
+ |
+LL | let _ = if let Some(ref mut s) = num {
+ | _____________-
+LL | | *s += 1;
+LL | | s
+LL | | } else {
+LL | | &mut 0
+ | | ^ creates a temporary value which is freed while still in use
+LL | |
+LL | | };
+ | | -
+ | | |
+ | |_____temporary value is freed at the end of this statement
+ | borrow later used here
+ |
+ = note: consider using a `let` binding to create a longer lived value
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/let_underscore_temporary.rs:36:14
+ |
+LL | let _: _ = if let Some(s) = &mut num {
+ | ________________-
+LL | | *s += 1;
+LL | | s
+LL | | } else {
+LL | | &mut 0
+ | | ^ creates a temporary value which is freed while still in use
+LL | |
+LL | | };
+ | | -
+ | | |
+ | |_____temporary value is freed at the end of this statement
+ | borrow later used here
+ |
+ = note: consider using a `let` binding to create a longer lived value
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/let_underscore_temporary.rs:50:14
+ |
+LL | let _: _ = if let Some(ref mut s) = num {
+ | ________________-
+LL | | *s += 1;
+LL | | s
+LL | | } else {
+LL | | &mut 0
+ | | ^ creates a temporary value which is freed while still in use
+LL | |
+LL | | };
+ | | -
+ | | |
+ | |_____temporary value is freed at the end of this statement
+ | borrow later used here
+ |
+ = note: consider using a `let` binding to create a longer lived value
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0716`.
diff --git a/tests/ui/borrowck/move-error-snippets-ext.rs b/tests/ui/borrowck/move-error-snippets-ext.rs
index c77f6c827..27041d55d 100644
--- a/tests/ui/borrowck/move-error-snippets-ext.rs
+++ b/tests/ui/borrowck/move-error-snippets-ext.rs
@@ -1,4 +1,4 @@
-// ignore-test
+// ignore-test (auxiliary, used by other tests)
macro_rules! aaa {
($c:ident) => {{
diff --git a/tests/ui/borrowck/mutability-errors.stderr b/tests/ui/borrowck/mutability-errors.stderr
index d7c602718..b39e57d70 100644
--- a/tests/ui/borrowck/mutability-errors.stderr
+++ b/tests/ui/borrowck/mutability-errors.stderr
@@ -7,7 +7,7 @@ LL | *x = (1,);
help: consider changing this to be a mutable reference
|
LL | fn named_ref(x: &mut (i32,)) {
- | ~~~~~~~~~~~
+ | +++
error[E0594]: cannot assign to `x.0`, which is behind a `&` reference
--> $DIR/mutability-errors.rs:10:5
@@ -18,7 +18,7 @@ LL | x.0 = 1;
help: consider changing this to be a mutable reference
|
LL | fn named_ref(x: &mut (i32,)) {
- | ~~~~~~~~~~~
+ | +++
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
--> $DIR/mutability-errors.rs:11:5
@@ -29,7 +29,7 @@ LL | &mut *x;
help: consider changing this to be a mutable reference
|
LL | fn named_ref(x: &mut (i32,)) {
- | ~~~~~~~~~~~
+ | +++
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `&` reference
--> $DIR/mutability-errors.rs:12:5
@@ -40,7 +40,7 @@ LL | &mut x.0;
help: consider changing this to be a mutable reference
|
LL | fn named_ref(x: &mut (i32,)) {
- | ~~~~~~~~~~~
+ | +++
error[E0594]: cannot assign to data in a `&` reference
--> $DIR/mutability-errors.rs:16:5
@@ -74,8 +74,8 @@ LL | *x = (1,);
|
help: consider changing this to be a mutable pointer
|
-LL | unsafe fn named_ptr(x: *mut (i32,)) {
- | ~~~~~~~~~~~
+LL | unsafe fn named_ptr(x: *mut const (i32,)) {
+ | +++
error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer
--> $DIR/mutability-errors.rs:24:5
@@ -85,8 +85,8 @@ LL | (*x).0 = 1;
|
help: consider changing this to be a mutable pointer
|
-LL | unsafe fn named_ptr(x: *mut (i32,)) {
- | ~~~~~~~~~~~
+LL | unsafe fn named_ptr(x: *mut const (i32,)) {
+ | +++
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
--> $DIR/mutability-errors.rs:25:5
@@ -96,8 +96,8 @@ LL | &mut *x;
|
help: consider changing this to be a mutable pointer
|
-LL | unsafe fn named_ptr(x: *mut (i32,)) {
- | ~~~~~~~~~~~
+LL | unsafe fn named_ptr(x: *mut const (i32,)) {
+ | +++
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `*const` pointer
--> $DIR/mutability-errors.rs:26:5
@@ -107,8 +107,8 @@ LL | &mut (*x).0;
|
help: consider changing this to be a mutable pointer
|
-LL | unsafe fn named_ptr(x: *mut (i32,)) {
- | ~~~~~~~~~~~
+LL | unsafe fn named_ptr(x: *mut const (i32,)) {
+ | +++
error[E0594]: cannot assign to data in a `*const` pointer
--> $DIR/mutability-errors.rs:30:5
diff --git a/tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.rs b/tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.rs
new file mode 100644
index 000000000..c9e043577
--- /dev/null
+++ b/tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.rs
@@ -0,0 +1,11 @@
+type Lazy<T> = Box<dyn Fn() -> T + 'static>;
+
+fn test(x: &i32) -> Lazy<i32> {
+ Box::new(|| {
+ //~^ ERROR lifetime may not live long enough
+ //~| ERROR closure may outlive the current function
+ *x
+ })
+}
+
+fn main() {}
diff --git a/tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.stderr b/tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.stderr
new file mode 100644
index 000000000..28b4b4aa2
--- /dev/null
+++ b/tests/ui/borrowck/suggest-lt-on-ty-alias-w-generics.stderr
@@ -0,0 +1,43 @@
+error: lifetime may not live long enough
+ --> $DIR/suggest-lt-on-ty-alias-w-generics.rs:4:5
+ |
+LL | fn test(x: &i32) -> Lazy<i32> {
+ | - let's call the lifetime of this reference `'1`
+LL | / Box::new(|| {
+LL | |
+LL | |
+LL | | *x
+LL | | })
+ | |______^ returning this value requires that `'1` must outlive `'static`
+ |
+help: to declare that the trait object captures data from argument `x`, you can add a lifetime parameter `'a` in the type alias
+ |
+LL | type Lazy<'a, T> = Box<dyn Fn() -> T + 'a>;
+ | +++ ~~
+
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+ --> $DIR/suggest-lt-on-ty-alias-w-generics.rs:4:14
+ |
+LL | Box::new(|| {
+ | ^^ may outlive borrowed value `x`
+...
+LL | *x
+ | -- `x` is borrowed here
+ |
+note: closure is returned here
+ --> $DIR/suggest-lt-on-ty-alias-w-generics.rs:4:5
+ |
+LL | / Box::new(|| {
+LL | |
+LL | |
+LL | | *x
+LL | | })
+ | |______^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+ |
+LL | Box::new(move || {
+ | ++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0373`.
diff --git a/tests/ui/borrowck/tainted-promoteds.rs b/tests/ui/borrowck/tainted-promoteds.rs
new file mode 100644
index 000000000..2b6f0ddbd
--- /dev/null
+++ b/tests/ui/borrowck/tainted-promoteds.rs
@@ -0,0 +1,12 @@
+// Regression test for issue #110856, where a borrowck error for a MIR tainted
+// all promoteds within. This in turn generated a spurious "erroneous constant
+// used" note when trying to evaluate a promoted.
+
+pub fn f() -> u32 {
+ let a = 0;
+ a = &0 * &1 * &2 * &3;
+ //~^ ERROR: cannot assign twice to immutable variable
+ a
+}
+
+fn main() {}
diff --git a/tests/ui/borrowck/tainted-promoteds.stderr b/tests/ui/borrowck/tainted-promoteds.stderr
new file mode 100644
index 000000000..b276ea9ac
--- /dev/null
+++ b/tests/ui/borrowck/tainted-promoteds.stderr
@@ -0,0 +1,14 @@
+error[E0384]: cannot assign twice to immutable variable `a`
+ --> $DIR/tainted-promoteds.rs:7:5
+ |
+LL | let a = 0;
+ | -
+ | |
+ | first assignment to `a`
+ | help: consider making this binding mutable: `mut a`
+LL | a = &0 * &1 * &2 * &3;
+ | ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0384`.