summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /tests/ui/closures/2229_closure_analysis
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis')
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr33
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr33
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.rs37
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/if-let-guards.rs55
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr3
-rw-r--r--tests/ui/closures/2229_closure_analysis/repr_packed.rs10
-rw-r--r--tests/ui/closures/2229_closure_analysis/repr_packed.stderr19
7 files changed, 172 insertions, 18 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr
new file mode 100644
index 000000000..394629c00
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr
@@ -0,0 +1,33 @@
+error[E0505]: cannot move out of `value` because it is borrowed
+ --> $DIR/if-let-guards-errors.rs:16:13
+ |
+LL | let f = |x: &E| {
+ | ------- borrow of `value` occurs here
+LL | match &x {
+LL | E::Number(_) if let E::Number(ref mut n) = *value => { }
+ | ------ borrow occurs due to use in closure
+...
+LL | let x = value;
+ | ^^^^^ move out of `value` occurs here
+LL |
+LL | drop(f);
+ | - borrow later used here
+
+error[E0382]: use of moved value: `value`
+ --> $DIR/if-let-guards-errors.rs:28:13
+ |
+LL | fn if_let_move(value: Box<E>) {
+ | ----- move occurs because `value` has type `Box<E>`, which does not implement the `Copy` trait
+LL | let f = |x: &E| {
+ | ------- value moved into closure here
+LL | match &x {
+LL | E::Number(_) if let E::String(s) = *value => { }
+ | ------ variable moved due to use in closure
+...
+LL | let x = value;
+ | ^^^^^ value used here after move
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0382, E0505.
+For more information about an error, try `rustc --explain E0382`.
diff --git a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr
new file mode 100644
index 000000000..567284501
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr
@@ -0,0 +1,33 @@
+error[E0505]: cannot move out of `value` because it is borrowed
+ --> $DIR/if-let-guards-errors.rs:16:13
+ |
+LL | let f = |x: &E| {
+ | ------- borrow of `*value` occurs here
+LL | match &x {
+LL | E::Number(_) if let E::Number(ref mut n) = *value => { }
+ | ------ borrow occurs due to use in closure
+...
+LL | let x = value;
+ | ^^^^^ move out of `value` occurs here
+LL |
+LL | drop(f);
+ | - borrow later used here
+
+error[E0382]: use of moved value: `value`
+ --> $DIR/if-let-guards-errors.rs:28:13
+ |
+LL | fn if_let_move(value: Box<E>) {
+ | ----- move occurs because `value` has type `Box<E>`, which does not implement the `Copy` trait
+LL | let f = |x: &E| {
+ | ------- value moved into closure here
+LL | match &x {
+LL | E::Number(_) if let E::String(s) = *value => { }
+ | ------ variable moved due to use in closure
+...
+LL | let x = value;
+ | ^^^^^ value used here after move
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0382, E0505.
+For more information about an error, try `rustc --explain E0382`.
diff --git a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.rs b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.rs
new file mode 100644
index 000000000..17e38c033
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.rs
@@ -0,0 +1,37 @@
+// Check the if let guards don't force capture by value
+// revisions: e2018 e2021
+//[e2018] edition:2018
+//[e2021] edition:2021
+
+#![feature(if_let_guard)]
+#![allow(irrefutable_let_patterns)]
+
+fn if_let_ref_mut(mut value: Box<E>) {
+ let f = |x: &E| {
+ match &x {
+ E::Number(_) if let E::Number(ref mut n) = *value => { }
+ _ => {}
+ }
+ };
+ let x = value;
+ //~^ ERROR cannot move out of `value` because it is borrowed
+ drop(f);
+}
+
+fn if_let_move(value: Box<E>) {
+ let f = |x: &E| {
+ match &x {
+ E::Number(_) if let E::String(s) = *value => { }
+ _ => {}
+ }
+ };
+ let x = value;
+ //~^ ERROR use of moved value: `value`
+}
+
+enum E {
+ String(String),
+ Number(i32),
+}
+
+fn main() {}
diff --git a/tests/ui/closures/2229_closure_analysis/match/if-let-guards.rs b/tests/ui/closures/2229_closure_analysis/match/if-let-guards.rs
new file mode 100644
index 000000000..fa331707b
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/match/if-let-guards.rs
@@ -0,0 +1,55 @@
+// Check the if let guards don't force capture by value
+// revisions: e2018 e2021
+// check-pass
+//[e2018] edition:2018
+//[e2021] edition:2021
+
+#![feature(if_let_guard)]
+#![allow(irrefutable_let_patterns)]
+
+fn if_let_underscore(value: Box<E>) {
+ |x: &E| {
+ match &x {
+ E::Number(_) if let _ = *value => { }
+ _ => {}
+ }
+ };
+ let x = value;
+}
+
+fn if_let_copy(value: Box<E>) {
+ |x: &E| {
+ match &x {
+ E::Number(_) if let E::Number(n) = *value => { }
+ _ => {}
+ }
+ };
+ let x = value;
+}
+
+fn if_let_ref(value: Box<E>) {
+ |x: &E| {
+ match &x {
+ E::Number(_) if let E::Number(ref n) = *value => { }
+ _ => {}
+ }
+ };
+ let x = value;
+}
+
+fn if_let_ref_mut(mut value: Box<E>) {
+ |x: &E| {
+ match &x {
+ E::Number(_) if let E::Number(ref mut n) = *value => { }
+ _ => {}
+ }
+ };
+ let x = value;
+}
+
+enum E {
+ String(String),
+ Number(i32),
+}
+
+fn main() {}
diff --git a/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr b/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr
index 3a5fad154..0807f4590 100644
--- a/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr
+++ b/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr
@@ -45,7 +45,8 @@ note: `E2` defined here
|
LL | pub enum E2 { A, B }
| ^^^^^^^^^^^
- = note: the matched value is of type `E2`, which is marked as non-exhaustive
+ = note: the matched value is of type `E2`
+ = note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL | let _e = || { match e2 { E2::A => (), E2::B => (), _ => todo!() } };
diff --git a/tests/ui/closures/2229_closure_analysis/repr_packed.rs b/tests/ui/closures/2229_closure_analysis/repr_packed.rs
index f23670f63..8c23454fa 100644
--- a/tests/ui/closures/2229_closure_analysis/repr_packed.rs
+++ b/tests/ui/closures/2229_closure_analysis/repr_packed.rs
@@ -3,7 +3,8 @@
#![feature(rustc_attrs)]
// `u8` aligned at a byte and are unaffected by repr(packed).
-// Therefore we can precisely (and safely) capture references to both the fields.
+// Therefore we *could* precisely (and safely) capture references to both the fields,
+// but we don't, since we don't want capturing to change when field types change alignment.
fn test_alignment_not_affected() {
#[repr(packed)]
struct Foo { x: u8, y: u8 }
@@ -17,11 +18,10 @@ fn test_alignment_not_affected() {
//~^ ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
let z1: &u8 = &foo.x;
- //~^ NOTE: Capturing foo[(0, 0)] -> ImmBorrow
- //~| NOTE: Min Capture foo[(0, 0)] -> ImmBorrow
+ //~^ NOTE: Capturing foo[] -> ImmBorrow
let z2: &mut u8 = &mut foo.y;
- //~^ NOTE: Capturing foo[(1, 0)] -> MutBorrow
- //~| NOTE: Min Capture foo[(1, 0)] -> MutBorrow
+ //~^ NOTE: Capturing foo[] -> MutBorrow
+ //~| NOTE: Min Capture foo[] -> MutBorrow
*z2 = 42;
diff --git a/tests/ui/closures/2229_closure_analysis/repr_packed.stderr b/tests/ui/closures/2229_closure_analysis/repr_packed.stderr
index 580061ebc..32b3d844c 100644
--- a/tests/ui/closures/2229_closure_analysis/repr_packed.stderr
+++ b/tests/ui/closures/2229_closure_analysis/repr_packed.stderr
@@ -1,5 +1,5 @@
error[E0658]: attributes on expressions are experimental
- --> $DIR/repr_packed.rs:13:17
+ --> $DIR/repr_packed.rs:14:17
|
LL | let mut c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | let c = #[rustc_capture_analysis]
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
error: First Pass analysis includes:
- --> $DIR/repr_packed.rs:16:5
+ --> $DIR/repr_packed.rs:17:5
|
LL | / || {
LL | |
@@ -37,19 +37,19 @@ LL | | println!("({}, {})", z1, z2);
LL | | };
| |_____^
|
-note: Capturing foo[(0, 0)] -> ImmBorrow
- --> $DIR/repr_packed.rs:19:24
+note: Capturing foo[] -> ImmBorrow
+ --> $DIR/repr_packed.rs:20:24
|
LL | let z1: &u8 = &foo.x;
| ^^^^^
-note: Capturing foo[(1, 0)] -> MutBorrow
+note: Capturing foo[] -> MutBorrow
--> $DIR/repr_packed.rs:22:32
|
LL | let z2: &mut u8 = &mut foo.y;
| ^^^^^
error: Min Capture analysis includes:
- --> $DIR/repr_packed.rs:16:5
+ --> $DIR/repr_packed.rs:17:5
|
LL | / || {
LL | |
@@ -60,12 +60,7 @@ LL | | println!("({}, {})", z1, z2);
LL | | };
| |_____^
|
-note: Min Capture foo[(0, 0)] -> ImmBorrow
- --> $DIR/repr_packed.rs:19:24
- |
-LL | let z1: &u8 = &foo.x;
- | ^^^^^
-note: Min Capture foo[(1, 0)] -> MutBorrow
+note: Min Capture foo[] -> MutBorrow
--> $DIR/repr_packed.rs:22:32
|
LL | let z2: &mut u8 = &mut foo.y;