summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /tests/ui/closures
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/closures')
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs25
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr58
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs2
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs6
-rw-r--r--tests/ui/closures/cannot-call-unsized-via-ptr-2.rs11
-rw-r--r--tests/ui/closures/cannot-call-unsized-via-ptr-2.stderr21
-rw-r--r--tests/ui/closures/cannot-call-unsized-via-ptr.rs10
-rw-r--r--tests/ui/closures/cannot-call-unsized-via-ptr.stderr12
-rw-r--r--tests/ui/closures/closure-move-sync.rs6
-rw-r--r--tests/ui/closures/closure-move-sync.stderr20
-rw-r--r--tests/ui/closures/issue-111932.rs9
-rw-r--r--tests/ui/closures/issue-111932.stderr26
-rw-r--r--tests/ui/closures/issue-113087.rs11
-rw-r--r--tests/ui/closures/issue-113087.stderr16
-rw-r--r--tests/ui/closures/issue-72408-nested-closures-exponential.rs1
15 files changed, 187 insertions, 47 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs b/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs
index 41b09ba03..c3898afa9 100644
--- a/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs
+++ b/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs
@@ -87,6 +87,31 @@ fn test_4_should_not_capture_array() {
}
};
c();
+
+ // We also do not need to capture an array
+ // behind a reference (#112607)
+ let array: &[i32; 3] = &[0; 3];
+ let c = #[rustc_capture_analysis]
+ || {
+ //~^ First Pass analysis includes:
+ match array {
+ [_, _, _] => {}
+ }
+ };
+ c();
+
+ // We should still not insert a read if the array is inside an
+ // irrefutable pattern
+ struct Foo<T>(T);
+ let f = &Foo(&[10; 3]);
+ let c = #[rustc_capture_analysis]
+ || {
+ //~^ First Pass analysis includes:
+ match f {
+ Foo([_, _, _]) => ()
+ }
+ };
+ c();
}
// Testing MultiVariant patterns
diff --git a/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr b/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr
index e137af1a0..c3c3f8b84 100644
--- a/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr
+++ b/tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr
@@ -109,7 +109,29 @@ LL | | };
| |_____^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:105:5
+ --> $DIR/patterns-capture-analysis.rs:95:5
+ |
+LL | / || {
+LL | |
+LL | | match array {
+LL | | [_, _, _] => {}
+LL | | }
+LL | | };
+ | |_____^
+
+error: First Pass analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:108:5
+ |
+LL | / || {
+LL | |
+LL | | match f {
+LL | | Foo([_, _, _]) => ()
+LL | | }
+LL | | };
+ | |_____^
+
+error: First Pass analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:130:5
|
LL | / || {
LL | |
@@ -121,13 +143,13 @@ LL | | };
| |_____^
|
note: Capturing variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:108:15
+ --> $DIR/patterns-capture-analysis.rs:133:15
|
LL | match variant {
| ^^^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:105:5
+ --> $DIR/patterns-capture-analysis.rs:130:5
|
LL | / || {
LL | |
@@ -139,13 +161,13 @@ LL | | };
| |_____^
|
note: Min Capture variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:108:15
+ --> $DIR/patterns-capture-analysis.rs:133:15
|
LL | match variant {
| ^^^^^^^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:123:5
+ --> $DIR/patterns-capture-analysis.rs:148:5
|
LL | / || {
LL | |
@@ -157,13 +179,13 @@ LL | | };
| |_____^
|
note: Capturing slice[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:126:15
+ --> $DIR/patterns-capture-analysis.rs:151:15
|
LL | match slice {
| ^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:123:5
+ --> $DIR/patterns-capture-analysis.rs:148:5
|
LL | / || {
LL | |
@@ -175,13 +197,13 @@ LL | | };
| |_____^
|
note: Min Capture slice[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:126:15
+ --> $DIR/patterns-capture-analysis.rs:151:15
|
LL | match slice {
| ^^^^^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:135:5
+ --> $DIR/patterns-capture-analysis.rs:160:5
|
LL | / || {
LL | |
@@ -193,13 +215,13 @@ LL | | };
| |_____^
|
note: Capturing slice[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:138:15
+ --> $DIR/patterns-capture-analysis.rs:163:15
|
LL | match slice {
| ^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:135:5
+ --> $DIR/patterns-capture-analysis.rs:160:5
|
LL | / || {
LL | |
@@ -211,13 +233,13 @@ LL | | };
| |_____^
|
note: Min Capture slice[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:138:15
+ --> $DIR/patterns-capture-analysis.rs:163:15
|
LL | match slice {
| ^^^^^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:147:5
+ --> $DIR/patterns-capture-analysis.rs:172:5
|
LL | / || {
LL | |
@@ -229,13 +251,13 @@ LL | | };
| |_____^
|
note: Capturing slice[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:150:15
+ --> $DIR/patterns-capture-analysis.rs:175:15
|
LL | match slice {
| ^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:147:5
+ --> $DIR/patterns-capture-analysis.rs:172:5
|
LL | / || {
LL | |
@@ -247,13 +269,13 @@ LL | | };
| |_____^
|
note: Min Capture slice[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:150:15
+ --> $DIR/patterns-capture-analysis.rs:175:15
|
LL | match slice {
| ^^^^^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:164:5
+ --> $DIR/patterns-capture-analysis.rs:189:5
|
LL | / || {
LL | |
@@ -264,5 +286,5 @@ LL | | }
LL | | };
| |_____^
-error: aborting due to 16 previous errors
+error: aborting due to 18 previous errors
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs b/tests/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs
index 03400e0ee..6d4cf6fa5 100644
--- a/tests/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs
@@ -15,7 +15,7 @@ struct Struct {
fn main() {
let mut s = Struct { x: 10, y: 10, s: String::new() };
- let mut c = {
+ let mut c = || {
s.x += 10;
s.y += 42;
s.s = String::from("new");
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs b/tests/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs
index d2375aa69..a386e9f40 100644
--- a/tests/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs
@@ -2,7 +2,7 @@
//check-pass
#![warn(unused)]
#![feature(rustc_attrs)]
-#![feature(btree_drain_filter)]
+#![feature(btree_extract_if)]
use std::collections::BTreeMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
@@ -14,14 +14,14 @@ fn main() {
map.insert("c", ());
{
- let mut it = map.drain_filter(|_, _| true);
+ let mut it = map.extract_if(|_, _| true);
catch_unwind(AssertUnwindSafe(|| while it.next().is_some() {})).unwrap_err();
let result = catch_unwind(AssertUnwindSafe(|| it.next()));
assert!(matches!(result, Ok(None)));
}
{
- let mut it = map.drain_filter(|_, _| true);
+ let mut it = map.extract_if(|_, _| true);
catch_unwind(AssertUnwindSafe(|| while let Some(_) = it.next() {})).unwrap_err();
let result = catch_unwind(AssertUnwindSafe(|| it.next()));
assert!(matches!(result, Ok(None)));
diff --git a/tests/ui/closures/cannot-call-unsized-via-ptr-2.rs b/tests/ui/closures/cannot-call-unsized-via-ptr-2.rs
new file mode 100644
index 000000000..2d8565517
--- /dev/null
+++ b/tests/ui/closures/cannot-call-unsized-via-ptr-2.rs
@@ -0,0 +1,11 @@
+#![feature(unsized_fn_params)]
+
+fn main() {
+ // CoerceMany "LUB"
+ let f = if true { |_a| {} } else { |_b| {} };
+ //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
+ //~| ERROR the size for values of type `[u8]` cannot be known at compilation time
+
+ let slice: Box<[u8]> = Box::new([1; 8]);
+ f(*slice);
+}
diff --git a/tests/ui/closures/cannot-call-unsized-via-ptr-2.stderr b/tests/ui/closures/cannot-call-unsized-via-ptr-2.stderr
new file mode 100644
index 000000000..d88b84365
--- /dev/null
+++ b/tests/ui/closures/cannot-call-unsized-via-ptr-2.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> $DIR/cannot-call-unsized-via-ptr-2.rs:5:24
+ |
+LL | let f = if true { |_a| {} } else { |_b| {} };
+ | ^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> $DIR/cannot-call-unsized-via-ptr-2.rs:5:41
+ |
+LL | let f = if true { |_a| {} } else { |_b| {} };
+ | ^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/closures/cannot-call-unsized-via-ptr.rs b/tests/ui/closures/cannot-call-unsized-via-ptr.rs
new file mode 100644
index 000000000..5ce4650b0
--- /dev/null
+++ b/tests/ui/closures/cannot-call-unsized-via-ptr.rs
@@ -0,0 +1,10 @@
+#![feature(unsized_fn_params)]
+
+fn main() {
+ // Simple coercion
+ let f: fn([u8]) = |_result| {};
+ //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
+
+ let slice: Box<[u8]> = Box::new([1; 8]);
+ f(*slice);
+}
diff --git a/tests/ui/closures/cannot-call-unsized-via-ptr.stderr b/tests/ui/closures/cannot-call-unsized-via-ptr.stderr
new file mode 100644
index 000000000..9ecc66d5c
--- /dev/null
+++ b/tests/ui/closures/cannot-call-unsized-via-ptr.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+ --> $DIR/cannot-call-unsized-via-ptr.rs:5:24
+ |
+LL | let f: fn([u8]) = |_result| {};
+ | ^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `[u8]`
+ = note: all function arguments must have a statically known size
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/closures/closure-move-sync.rs b/tests/ui/closures/closure-move-sync.rs
index ea2d1434c..3ee2b35f5 100644
--- a/tests/ui/closures/closure-move-sync.rs
+++ b/tests/ui/closures/closure-move-sync.rs
@@ -13,10 +13,4 @@ fn bar() {
t.join().unwrap();
}
-fn foo() {
- let (tx, _rx) = channel();
- thread::spawn(|| tx.send(()).unwrap());
- //~^ ERROR `Sender<()>` cannot be shared between threads safely
-}
-
fn main() {}
diff --git a/tests/ui/closures/closure-move-sync.stderr b/tests/ui/closures/closure-move-sync.stderr
index 64e3b51ea..aee903ac9 100644
--- a/tests/ui/closures/closure-move-sync.stderr
+++ b/tests/ui/closures/closure-move-sync.stderr
@@ -20,24 +20,6 @@ LL | let t = thread::spawn(|| {
note: required by a bound in `spawn`
--> $SRC_DIR/std/src/thread/mod.rs:LL:COL
-error[E0277]: `Sender<()>` cannot be shared between threads safely
- --> $DIR/closure-move-sync.rs:18:19
- |
-LL | thread::spawn(|| tx.send(()).unwrap());
- | ------------- ^^^^^^^^^^^^^^^^^^^^^^^ `Sender<()>` cannot be shared between threads safely
- | |
- | required by a bound introduced by this call
- |
- = help: the trait `Sync` is not implemented for `Sender<()>`
- = note: required for `&Sender<()>` to implement `Send`
-note: required because it's used within this closure
- --> $DIR/closure-move-sync.rs:18:19
- |
-LL | thread::spawn(|| tx.send(()).unwrap());
- | ^^
-note: required by a bound in `spawn`
- --> $SRC_DIR/std/src/thread/mod.rs:LL:COL
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/closures/issue-111932.rs b/tests/ui/closures/issue-111932.rs
new file mode 100644
index 000000000..eb3fe08cb
--- /dev/null
+++ b/tests/ui/closures/issue-111932.rs
@@ -0,0 +1,9 @@
+trait Foo: std::fmt::Debug {}
+
+fn print_foos(foos: impl Iterator<Item = dyn Foo>) {
+ foos.for_each(|foo| { //~ ERROR [E0277]
+ println!("{:?}", foo); //~ ERROR [E0277]
+ });
+}
+
+fn main() {}
diff --git a/tests/ui/closures/issue-111932.stderr b/tests/ui/closures/issue-111932.stderr
new file mode 100644
index 000000000..937bdf3be
--- /dev/null
+++ b/tests/ui/closures/issue-111932.stderr
@@ -0,0 +1,26 @@
+error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
+ --> $DIR/issue-111932.rs:4:20
+ |
+LL | foos.for_each(|foo| {
+ | ^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
+ = note: all function arguments must have a statically known size
+ = help: unsized fn params are gated as an unstable feature
+
+error[E0277]: the size for values of type `dyn Foo` cannot be known at compilation time
+ --> $DIR/issue-111932.rs:5:26
+ |
+LL | println!("{:?}", foo);
+ | ---- ^^^ doesn't have a size known at compile-time
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sized` is not implemented for `dyn Foo`
+note: required by a bound in `core::fmt::rt::Argument::<'a>::new_debug`
+ --> $SRC_DIR/core/src/fmt/rt.rs:LL:COL
+ = 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 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/closures/issue-113087.rs b/tests/ui/closures/issue-113087.rs
new file mode 100644
index 000000000..a4edc2f2f
--- /dev/null
+++ b/tests/ui/closures/issue-113087.rs
@@ -0,0 +1,11 @@
+fn some_fn<'a>(_: &'a i32, _: impl FnOnce(&'a i32)) {}
+
+fn main() {
+ let some_closure = |_| {};
+
+ for a in [1] {
+ some_fn(&a, |c| { //~ ERROR does not live long enough
+ some_closure(c);
+ });
+ }
+}
diff --git a/tests/ui/closures/issue-113087.stderr b/tests/ui/closures/issue-113087.stderr
new file mode 100644
index 000000000..8ccef4a54
--- /dev/null
+++ b/tests/ui/closures/issue-113087.stderr
@@ -0,0 +1,16 @@
+error[E0597]: `a` does not live long enough
+ --> $DIR/issue-113087.rs:7:17
+ |
+LL | for a in [1] {
+ | - binding `a` declared here
+LL | some_fn(&a, |c| {
+ | ^^ borrowed value does not live long enough
+LL | some_closure(c);
+ | ------------ borrow later captured here by closure
+LL | });
+LL | }
+ | - `a` dropped here while still borrowed
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/tests/ui/closures/issue-72408-nested-closures-exponential.rs b/tests/ui/closures/issue-72408-nested-closures-exponential.rs
index 2d6ba9365..d064ebcef 100644
--- a/tests/ui/closures/issue-72408-nested-closures-exponential.rs
+++ b/tests/ui/closures/issue-72408-nested-closures-exponential.rs
@@ -1,4 +1,5 @@
// build-pass
+// ignore-compare-mode-next-solver (hangs)
// Closures include captured types twice in a type tree.
//