diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
commit | 631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch) | |
tree | a1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/ui/borrowck | |
parent | Adding debian version 1.69.0+dfsg1-1. (diff) | |
download | rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip |
Merging upstream version 1.70.0+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.stderr | 10 | ||||
-rw-r--r-- | tests/ui/borrowck/borrowck-pat-enum.rs | 1 | ||||
-rw-r--r-- | tests/ui/borrowck/borrowck-vec-pattern-nesting.rs | 2 | ||||
-rw-r--r-- | tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr | 18 | ||||
-rw-r--r-- | tests/ui/borrowck/drop-in-loop.rs | 24 | ||||
-rw-r--r-- | tests/ui/borrowck/drop-in-loop.stderr | 14 | ||||
-rw-r--r-- | tests/ui/borrowck/issue-45199.rs | 3 | ||||
-rw-r--r-- | tests/ui/borrowck/issue-45199.stderr | 4 | ||||
-rw-r--r-- | tests/ui/borrowck/issue-58776-borrowck-scans-children.rs | 1 | ||||
-rw-r--r-- | tests/ui/borrowck/issue-58776-borrowck-scans-children.stderr | 19 | ||||
-rw-r--r-- | tests/ui/borrowck/issue-64453.stderr | 2 | ||||
-rw-r--r-- | tests/ui/borrowck/issue-70919-drop-in-loop.rs | 25 | ||||
-rw-r--r-- | tests/ui/borrowck/let_underscore_temporary.rs | 27 |
13 files changed, 113 insertions, 37 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 5835f0675..0ca14c3f3 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 @@ -2,18 +2,16 @@ 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 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 mutably borrowed by `s` here + | | | value is borrowed by `foo` here error[E0382]: borrow of moved value: `x` diff --git a/tests/ui/borrowck/borrowck-pat-enum.rs b/tests/ui/borrowck/borrowck-pat-enum.rs index 7f9c5544d..6e51a2b2e 100644 --- a/tests/ui/borrowck/borrowck-pat-enum.rs +++ b/tests/ui/borrowck/borrowck-pat-enum.rs @@ -1,6 +1,5 @@ // run-pass #![allow(dead_code)] -// ignore-pretty issue #37199 fn match_ref(v: Option<isize>) -> isize { match v { diff --git a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs index 1bda7a497..127a3f5b2 100644 --- a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs +++ b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs @@ -8,6 +8,7 @@ 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 } @@ -22,6 +23,7 @@ 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 70b9e4f44..5e1251b05 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:23:13 + --> $DIR/borrowck-vec-pattern-nesting.rs:24: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:34:11 + --> $DIR/borrowck-vec-pattern-nesting.rs:36: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:46:13 + --> $DIR/borrowck-vec-pattern-nesting.rs:48: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:55:11 + --> $DIR/borrowck-vec-pattern-nesting.rs:57: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:65:13 + --> $DIR/borrowck-vec-pattern-nesting.rs:67: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:74:11 + --> $DIR/borrowck-vec-pattern-nesting.rs:76: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:85:13 + --> $DIR/borrowck-vec-pattern-nesting.rs:87:13 | LL | let a = vec[0]; | ^^^^^^ diff --git a/tests/ui/borrowck/drop-in-loop.rs b/tests/ui/borrowck/drop-in-loop.rs new file mode 100644 index 000000000..866c27ef2 --- /dev/null +++ b/tests/ui/borrowck/drop-in-loop.rs @@ -0,0 +1,24 @@ +// A version of `issue-70919-drop-in-loop`, but without +// the necessary `drop` call. +// +// This should fail to compile, since the `Drop` impl +// for `WrapperWithDrop` could observe the changed +// `base` value. + +struct WrapperWithDrop<'a>(&'a mut bool); +impl<'a> Drop for WrapperWithDrop<'a> { + fn drop(&mut self) { + } +} + +fn drop_in_loop() { + let mut base = true; + let mut wrapper = WrapperWithDrop(&mut base); + loop { + base = false; //~ ERROR: cannot assign to `base` + wrapper = WrapperWithDrop(&mut base); + } +} + +fn main() { +} diff --git a/tests/ui/borrowck/drop-in-loop.stderr b/tests/ui/borrowck/drop-in-loop.stderr new file mode 100644 index 000000000..d5734e7ec --- /dev/null +++ b/tests/ui/borrowck/drop-in-loop.stderr @@ -0,0 +1,14 @@ +error[E0506]: cannot assign to `base` because it is borrowed + --> $DIR/drop-in-loop.rs:18:9 + | +LL | let mut wrapper = WrapperWithDrop(&mut base); + | --------- `base` is borrowed here +LL | loop { +LL | base = false; + | ^^^^^^^^^^^^ `base` is assigned to here but it was already borrowed +LL | wrapper = WrapperWithDrop(&mut base); + | ------- borrow might be used here, when `wrapper` is dropped and runs the `Drop` code for type `WrapperWithDrop` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0506`. diff --git a/tests/ui/borrowck/issue-45199.rs b/tests/ui/borrowck/issue-45199.rs index ded46e56e..6a6b25541 100644 --- a/tests/ui/borrowck/issue-45199.rs +++ b/tests/ui/borrowck/issue-45199.rs @@ -5,6 +5,7 @@ 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() { @@ -13,12 +14,14 @@ 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 47aa30908..163f2370b 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:14:5 + --> $DIR/issue-45199.rs:15: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:20:5 + --> $DIR/issue-45199.rs:22:5 | LL | fn test_args(b: Box<i32>) { | - help: consider making this binding mutable: `mut b` diff --git a/tests/ui/borrowck/issue-58776-borrowck-scans-children.rs b/tests/ui/borrowck/issue-58776-borrowck-scans-children.rs index efa313a9d..0b2372d12 100644 --- a/tests/ui/borrowck/issue-58776-borrowck-scans-children.rs +++ b/tests/ui/borrowck/issue-58776-borrowck-scans-children.rs @@ -5,7 +5,6 @@ fn main() { greeting = "DEALLOCATED".to_string(); //~^ ERROR cannot assign drop(greeting); - //~^ ERROR cannot move println!("thread result: {:?}", res); } diff --git a/tests/ui/borrowck/issue-58776-borrowck-scans-children.stderr b/tests/ui/borrowck/issue-58776-borrowck-scans-children.stderr index 0870b4237..967451c68 100644 --- a/tests/ui/borrowck/issue-58776-borrowck-scans-children.stderr +++ b/tests/ui/borrowck/issue-58776-borrowck-scans-children.stderr @@ -12,21 +12,6 @@ LL | greeting = "DEALLOCATED".to_string(); LL | println!("thread result: {:?}", res); | --- borrow later used here -error[E0505]: cannot move out of `greeting` because it is borrowed - --> $DIR/issue-58776-borrowck-scans-children.rs:7:10 - | -LL | let res = (|| (|| &greeting)())(); - | -- -------- borrow occurs due to use in closure - | | - | borrow of `greeting` occurs here -... -LL | drop(greeting); - | ^^^^^^^^ move out of `greeting` occurs here -... -LL | println!("thread result: {:?}", res); - | --- borrow later used here - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0505, E0506. -For more information about an error, try `rustc --explain E0505`. +For more information about this error, try `rustc --explain E0506`. diff --git a/tests/ui/borrowck/issue-64453.stderr b/tests/ui/borrowck/issue-64453.stderr index 245c3a40e..f032ea779 100644 --- a/tests/ui/borrowck/issue-64453.stderr +++ b/tests/ui/borrowck/issue-64453.stderr @@ -1,4 +1,4 @@ -error: `Arguments::<'a>::new_v1` is not yet stable as a const fn +error: `Arguments::<'a>::new_const` is not yet stable as a const fn --> $DIR/issue-64453.rs:4:31 | LL | static settings_dir: String = format!(""); diff --git a/tests/ui/borrowck/issue-70919-drop-in-loop.rs b/tests/ui/borrowck/issue-70919-drop-in-loop.rs new file mode 100644 index 000000000..a8d5849a3 --- /dev/null +++ b/tests/ui/borrowck/issue-70919-drop-in-loop.rs @@ -0,0 +1,25 @@ +// Regression test for issue #70919 +// Tests that we don't emit a spurious "borrow might be used" error +// when we have an explicit `drop` in a loop + +// check-pass + +struct WrapperWithDrop<'a>(&'a mut bool); +impl<'a> Drop for WrapperWithDrop<'a> { + fn drop(&mut self) { + } +} + +fn drop_in_loop() { + let mut base = true; + let mut wrapper = WrapperWithDrop(&mut base); + loop { + drop(wrapper); + + base = false; + wrapper = WrapperWithDrop(&mut base); + } +} + +fn main() { +} diff --git a/tests/ui/borrowck/let_underscore_temporary.rs b/tests/ui/borrowck/let_underscore_temporary.rs new file mode 100644 index 000000000..37b5c5d9d --- /dev/null +++ b/tests/ui/borrowck/let_underscore_temporary.rs @@ -0,0 +1,27 @@ +// check-pass + +fn let_underscore(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 + }; + 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 + }; +} + +fn main() {} |