summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /tests/ui/closures
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.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/bad-pattern.rs23
-rw-r--r--tests/ui/closures/2229_closure_analysis/bad-pattern.stderr113
-rw-r--r--tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr2
-rw-r--r--tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr3
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr28
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs72
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr209
-rw-r--r--tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs1
-rw-r--r--tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr2
-rw-r--r--tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs1
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs2
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs21
-rw-r--r--tests/ui/closures/binder/nested-closures-regions.stderr10
-rw-r--r--tests/ui/closures/issue-868.rs18
-rw-r--r--tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr2
-rw-r--r--tests/ui/closures/print/closure-print-generic-verbose-1.stderr2
-rw-r--r--tests/ui/closures/print/closure-print-generic-verbose-2.stderr2
-rw-r--r--tests/ui/closures/print/closure-print-verbose.stderr2
-rw-r--r--tests/ui/closures/static-closures-with-nonstatic-return.rs15
19 files changed, 417 insertions, 111 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/bad-pattern.rs b/tests/ui/closures/2229_closure_analysis/bad-pattern.rs
new file mode 100644
index 000000000..a7bf9b67d
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/bad-pattern.rs
@@ -0,0 +1,23 @@
+// regression test for #108683
+// edition:2021
+
+enum Refutable {
+ A,
+ B,
+}
+
+fn example(v1: u32, v2: [u32; 4], v3: Refutable) {
+ const PAT: u32 = 0;
+ let v4 = &v2[..];
+ || {
+ let 0 = v1; //~ ERROR refutable pattern in local binding
+ let (0 | 1) = v1; //~ ERROR refutable pattern in local binding
+ let 1.. = v1; //~ ERROR refutable pattern in local binding
+ let [0, 0, 0, 0] = v2; //~ ERROR refutable pattern in local binding
+ let [0] = v4; //~ ERROR refutable pattern in local binding
+ let Refutable::A = v3; //~ ERROR refutable pattern in local binding
+ let PAT = v1; //~ ERROR refutable pattern in local binding
+ };
+}
+
+fn main() {}
diff --git a/tests/ui/closures/2229_closure_analysis/bad-pattern.stderr b/tests/ui/closures/2229_closure_analysis/bad-pattern.stderr
new file mode 100644
index 000000000..ca8c2a16d
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/bad-pattern.stderr
@@ -0,0 +1,113 @@
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:13:13
+ |
+LL | let 0 = v1;
+ | ^ pattern `1_u32..=u32::MAX` not covered
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+ = note: the matched value is of type `u32`
+help: you might want to use `if let` to ignore the variant that isn't matched
+ |
+LL | if let 0 = v1 { todo!() };
+ | ++ +++++++++++
+help: alternatively, you could prepend the pattern with an underscore to define a new named variable; identifiers cannot begin with digits
+ |
+LL | let _0 = v1;
+ | +
+
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:14:14
+ |
+LL | let (0 | 1) = v1;
+ | ^^^^^ pattern `2_u32..=u32::MAX` not covered
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+ = note: the matched value is of type `u32`
+help: you might want to use `if let` to ignore the variant that isn't matched
+ |
+LL | if let (0 | 1) = v1 { todo!() };
+ | ++ +++++++++++
+
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:15:13
+ |
+LL | let 1.. = v1;
+ | ^^^ pattern `0_u32` not covered
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+ = note: the matched value is of type `u32`
+help: you might want to use `if let` to ignore the variant that isn't matched
+ |
+LL | if let 1.. = v1 { todo!() };
+ | ++ +++++++++++
+
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:16:13
+ |
+LL | let [0, 0, 0, 0] = v2;
+ | ^^^^^^^^^^^^ pattern `[1_u32..=u32::MAX, _, _, _]` not covered
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+ = note: the matched value is of type `[u32; 4]`
+help: you might want to use `if let` to ignore the variant that isn't matched
+ |
+LL | if let [0, 0, 0, 0] = v2 { todo!() };
+ | ++ +++++++++++
+
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:17:13
+ |
+LL | let [0] = v4;
+ | ^^^ patterns `&[]` and `&[_, _, ..]` not covered
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+ = note: the matched value is of type `&[u32]`
+help: you might want to use `if let` to ignore the variants that aren't matched
+ |
+LL | if let [0] = v4 { todo!() };
+ | ++ +++++++++++
+
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:18:13
+ |
+LL | let Refutable::A = v3;
+ | ^^^^^^^^^^^^ pattern `Refutable::B` not covered
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+note: `Refutable` defined here
+ --> $DIR/bad-pattern.rs:4:6
+ |
+LL | enum Refutable {
+ | ^^^^^^^^^
+LL | A,
+LL | B,
+ | - not covered
+ = note: the matched value is of type `Refutable`
+help: you might want to use `if let` to ignore the variant that isn't matched
+ |
+LL | if let Refutable::A = v3 { todo!() };
+ | ++ +++++++++++
+
+error[E0005]: refutable pattern in local binding
+ --> $DIR/bad-pattern.rs:19:13
+ |
+LL | let PAT = v1;
+ | ^^^
+ | |
+ | pattern `1_u32..=u32::MAX` not covered
+ | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable
+ | help: introduce a variable instead: `PAT_var`
+ |
+ = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+ = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+ = note: the matched value is of type `u32`
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0005`.
diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr b/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr
index 95f36fc04..1904faa95 100644
--- a/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr
+++ b/tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr
@@ -10,7 +10,7 @@ LL | **ref_mref_x = y;
help: consider changing this to be a mutable reference
|
LL | let ref_mref_x = &mut mref_x;
- | ~~~~~~~~~~~
+ | +++
error[E0596]: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference
--> $DIR/mut_ref.rs:26:13
diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr b/tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
index 9c2c43457..8c44229bc 100644
--- a/tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
+++ b/tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
@@ -4,7 +4,8 @@ error[E0793]: reference to packed field is unaligned
LL | println!("{}", foo.x);
| ^^^^^
|
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = note: packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
+ = note: creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
= 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)
diff --git a/tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr b/tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr
index ad061d93c..8a32f0d99 100644
--- a/tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr
+++ b/tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr
@@ -1,17 +1,3 @@
-error[E0004]: non-exhaustive patterns: type `u8` is non-empty
- --> $DIR/pattern-matching-should-fail.rs:67:23
- |
-LL | let c1 = || match x { };
- | ^
- |
- = note: the matched value is of type `u8`
-help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
- |
-LL ~ let c1 = || match x {
-LL + _ => todo!(),
-LL ~ };
- |
-
error[E0381]: used binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:8:23
|
@@ -69,6 +55,20 @@ LL | let t: !;
LL | match t { };
| ^ `t` used here but it isn't initialized
+error[E0004]: non-exhaustive patterns: type `u8` is non-empty
+ --> $DIR/pattern-matching-should-fail.rs:67:23
+ |
+LL | let c1 = || match x { };
+ | ^
+ |
+ = note: the matched value is of type `u8`
+help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
+ |
+LL ~ let c1 = || match x {
+LL + _ => todo!(),
+LL ~ };
+ |
+
error[E0381]: used binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:67:23
|
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 56f5ac44d..41b09ba03 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
@@ -1,6 +1,7 @@
// edition:2021
#![feature(rustc_attrs)]
+#![feature(stmt_expr_attributes)]
// Should capture the discriminant since a variant of a multivariant enum is
// mentioned in the match arm; the discriminant is captured by the closure regardless
@@ -8,9 +9,6 @@
fn test_1_should_capture() {
let variant = Some(2229);
let c = #[rustc_capture_analysis]
- //~^ ERROR: attributes on expressions are experimental
- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
-
|| {
//~^ First Pass analysis includes:
//~| Min Capture analysis includes:
@@ -29,8 +27,6 @@ fn test_1_should_capture() {
fn test_2_should_not_capture() {
let variant = Some(2229);
let c = #[rustc_capture_analysis]
- //~^ ERROR: attributes on expressions are experimental
- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|| {
//~^ First Pass analysis includes:
match variant {
@@ -50,8 +46,6 @@ enum SingleVariant {
fn test_3_should_not_capture_single_variant() {
let variant = SingleVariant::Points(1);
let c = #[rustc_capture_analysis]
- //~^ ERROR: attributes on expressions are experimental
- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|| {
//~^ First Pass analysis includes:
match variant {
@@ -66,8 +60,6 @@ fn test_3_should_not_capture_single_variant() {
fn test_6_should_capture_single_variant() {
let variant = SingleVariant::Points(1);
let c = #[rustc_capture_analysis]
- //~^ ERROR: attributes on expressions are experimental
- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|| {
//~^ First Pass analysis includes:
//~| Min Capture analysis includes:
@@ -88,8 +80,6 @@ fn test_6_should_capture_single_variant() {
fn test_4_should_not_capture_array() {
let array: [i32; 3] = [0; 3];
let c = #[rustc_capture_analysis]
- //~^ ERROR: attributes on expressions are experimental
- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|| {
//~^ First Pass analysis includes:
match array {
@@ -112,8 +102,6 @@ enum MVariant {
fn test_5_should_capture_multi_variant() {
let variant = MVariant::A;
let c = #[rustc_capture_analysis]
- //~^ ERROR: attributes on expressions are experimental
- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|| {
//~^ First Pass analysis includes:
//~| Min Capture analysis includes:
@@ -127,6 +115,62 @@ fn test_5_should_capture_multi_variant() {
c();
}
+// Even though all patterns are wild, we need to read the discriminant
+// in order to test the slice length
+fn test_7_should_capture_slice_len() {
+ let slice: &[i32] = &[1, 2, 3];
+ let c = #[rustc_capture_analysis]
+ || {
+ //~^ First Pass analysis includes:
+ //~| Min Capture analysis includes:
+ match slice {
+ //~^ NOTE: Capturing slice[] -> ImmBorrow
+ //~| NOTE: Min Capture slice[] -> ImmBorrow
+ [_,_,_] => {},
+ _ => {}
+ }
+ };
+ c();
+ let c = #[rustc_capture_analysis]
+ || {
+ //~^ First Pass analysis includes:
+ //~| Min Capture analysis includes:
+ match slice {
+ //~^ NOTE: Capturing slice[] -> ImmBorrow
+ //~| NOTE: Min Capture slice[] -> ImmBorrow
+ [] => {},
+ _ => {}
+ }
+ };
+ c();
+ let c = #[rustc_capture_analysis]
+ || {
+ //~^ First Pass analysis includes:
+ //~| Min Capture analysis includes:
+ match slice {
+ //~^ NOTE: Capturing slice[] -> ImmBorrow
+ //~| NOTE: Min Capture slice[] -> ImmBorrow
+ [_, .. ,_] => {},
+ _ => {}
+ }
+ };
+ c();
+}
+
+// Wild pattern that doesn't bind, so no capture
+fn test_8_capture_slice_wild() {
+ let slice: &[i32] = &[1, 2, 3];
+ let c = #[rustc_capture_analysis]
+ || {
+ //~^ First Pass analysis includes:
+ match slice {
+ [..] => {},
+ _ => {}
+ }
+ };
+ c();
+}
+
fn main() {
test_1_should_capture();
test_2_should_not_capture();
@@ -134,4 +178,6 @@ fn main() {
test_6_should_capture_single_variant();
test_4_should_not_capture_array();
test_5_should_capture_multi_variant();
+ test_7_should_capture_slice_len();
+ test_8_capture_slice_wild();
}
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 460813333..e137af1a0 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
@@ -1,59 +1,5 @@
-error[E0658]: attributes on expressions are experimental
- --> $DIR/patterns-capture-analysis.rs:10:14
- |
-LL | let c = #[rustc_capture_analysis]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
- = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
-
-error[E0658]: attributes on expressions are experimental
- --> $DIR/patterns-capture-analysis.rs:31:14
- |
-LL | let c = #[rustc_capture_analysis]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
- = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
-
-error[E0658]: attributes on expressions are experimental
- --> $DIR/patterns-capture-analysis.rs:52:14
- |
-LL | let c = #[rustc_capture_analysis]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
- = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
-
-error[E0658]: attributes on expressions are experimental
- --> $DIR/patterns-capture-analysis.rs:68:14
- |
-LL | let c = #[rustc_capture_analysis]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
- = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
-
-error[E0658]: attributes on expressions are experimental
- --> $DIR/patterns-capture-analysis.rs:90:14
- |
-LL | let c = #[rustc_capture_analysis]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
- = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
-
-error[E0658]: attributes on expressions are experimental
- --> $DIR/patterns-capture-analysis.rs:114:14
- |
-LL | let c = #[rustc_capture_analysis]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
- = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
-
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:14:5
+ --> $DIR/patterns-capture-analysis.rs:12:5
|
LL | / || {
LL | |
@@ -65,13 +11,13 @@ LL | | };
| |_____^
|
note: Capturing variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:17:15
+ --> $DIR/patterns-capture-analysis.rs:15:15
|
LL | match variant {
| ^^^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:14:5
+ --> $DIR/patterns-capture-analysis.rs:12:5
|
LL | / || {
LL | |
@@ -83,13 +29,13 @@ LL | | };
| |_____^
|
note: Min Capture variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:17:15
+ --> $DIR/patterns-capture-analysis.rs:15:15
|
LL | match variant {
| ^^^^^^^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:34:5
+ --> $DIR/patterns-capture-analysis.rs:30:5
|
LL | / || {
LL | |
@@ -100,7 +46,7 @@ LL | | };
| |_____^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:55:5
+ --> $DIR/patterns-capture-analysis.rs:49:5
|
LL | / || {
LL | |
@@ -111,7 +57,7 @@ LL | | };
| |_____^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:71:5
+ --> $DIR/patterns-capture-analysis.rs:63:5
|
LL | / || {
LL | |
@@ -123,18 +69,18 @@ LL | | };
| |_____^
|
note: Capturing variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:74:15
+ --> $DIR/patterns-capture-analysis.rs:66:15
|
LL | match variant {
| ^^^^^^^
note: Capturing variant[(0, 0)] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:74:15
+ --> $DIR/patterns-capture-analysis.rs:66:15
|
LL | match variant {
| ^^^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:71:5
+ --> $DIR/patterns-capture-analysis.rs:63:5
|
LL | / || {
LL | |
@@ -146,13 +92,13 @@ LL | | };
| |_____^
|
note: Min Capture variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:74:15
+ --> $DIR/patterns-capture-analysis.rs:66:15
|
LL | match variant {
| ^^^^^^^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:93:5
+ --> $DIR/patterns-capture-analysis.rs:83:5
|
LL | / || {
LL | |
@@ -163,7 +109,7 @@ LL | | };
| |_____^
error: First Pass analysis includes:
- --> $DIR/patterns-capture-analysis.rs:117:5
+ --> $DIR/patterns-capture-analysis.rs:105:5
|
LL | / || {
LL | |
@@ -175,13 +121,13 @@ LL | | };
| |_____^
|
note: Capturing variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:120:15
+ --> $DIR/patterns-capture-analysis.rs:108:15
|
LL | match variant {
| ^^^^^^^
error: Min Capture analysis includes:
- --> $DIR/patterns-capture-analysis.rs:117:5
+ --> $DIR/patterns-capture-analysis.rs:105:5
|
LL | / || {
LL | |
@@ -193,11 +139,130 @@ LL | | };
| |_____^
|
note: Min Capture variant[] -> ImmBorrow
- --> $DIR/patterns-capture-analysis.rs:120:15
+ --> $DIR/patterns-capture-analysis.rs:108:15
|
LL | match variant {
| ^^^^^^^
-error: aborting due to 15 previous errors
+error: First Pass analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:123:5
+ |
+LL | / || {
+LL | |
+LL | |
+LL | | match slice {
+... |
+LL | | }
+LL | | };
+ | |_____^
+ |
+note: Capturing slice[] -> ImmBorrow
+ --> $DIR/patterns-capture-analysis.rs:126:15
+ |
+LL | match slice {
+ | ^^^^^
+
+error: Min Capture analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:123:5
+ |
+LL | / || {
+LL | |
+LL | |
+LL | | match slice {
+... |
+LL | | }
+LL | | };
+ | |_____^
+ |
+note: Min Capture slice[] -> ImmBorrow
+ --> $DIR/patterns-capture-analysis.rs:126:15
+ |
+LL | match slice {
+ | ^^^^^
+
+error: First Pass analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:135:5
+ |
+LL | / || {
+LL | |
+LL | |
+LL | | match slice {
+... |
+LL | | }
+LL | | };
+ | |_____^
+ |
+note: Capturing slice[] -> ImmBorrow
+ --> $DIR/patterns-capture-analysis.rs:138:15
+ |
+LL | match slice {
+ | ^^^^^
+
+error: Min Capture analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:135:5
+ |
+LL | / || {
+LL | |
+LL | |
+LL | | match slice {
+... |
+LL | | }
+LL | | };
+ | |_____^
+ |
+note: Min Capture slice[] -> ImmBorrow
+ --> $DIR/patterns-capture-analysis.rs:138:15
+ |
+LL | match slice {
+ | ^^^^^
+
+error: First Pass analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:147:5
+ |
+LL | / || {
+LL | |
+LL | |
+LL | | match slice {
+... |
+LL | | }
+LL | | };
+ | |_____^
+ |
+note: Capturing slice[] -> ImmBorrow
+ --> $DIR/patterns-capture-analysis.rs:150:15
+ |
+LL | match slice {
+ | ^^^^^
+
+error: Min Capture analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:147:5
+ |
+LL | / || {
+LL | |
+LL | |
+LL | | match slice {
+... |
+LL | | }
+LL | | };
+ | |_____^
+ |
+note: Min Capture slice[] -> ImmBorrow
+ --> $DIR/patterns-capture-analysis.rs:150:15
+ |
+LL | match slice {
+ | ^^^^^
+
+error: First Pass analysis includes:
+ --> $DIR/patterns-capture-analysis.rs:164:5
+ |
+LL | / || {
+LL | |
+LL | | match slice {
+LL | | [..] => {},
+LL | | _ => {}
+LL | | }
+LL | | };
+ | |_____^
+
+error: aborting due to 16 previous errors
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs
index ff5d28461..98f8d5d47 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs
+++ b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs
@@ -1,6 +1,7 @@
// run-pass
#![warn(rust_2021_incompatible_closure_captures)]
+#![allow(dropping_references, dropping_copy_types)]
fn main() {
if let a = "" {
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr
index 36a80e694..2609e2951 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr
+++ b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr
@@ -1,5 +1,5 @@
warning: irrefutable `if let` pattern
- --> $DIR/issue-78720.rs:6:8
+ --> $DIR/issue-78720.rs:7:8
|
LL | if let a = "" {
| ^^^^^^^^^^
diff --git a/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs b/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs
index 033fd6f17..5496d0e5f 100644
--- a/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs
+++ b/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs
@@ -3,6 +3,7 @@
#![allow(unused)]
#![allow(dead_code)]
+#![allow(dropping_references)]
struct Int(i32);
struct B<'a>(&'a i32);
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs b/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs
index 477fdd613..b5e97ec1c 100644
--- a/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs
@@ -1,6 +1,8 @@
// edition:2021
// check-pass
+
#![feature(rustc_attrs)]
+#![allow(dropping_references)]
fn main() {
let mut x = 1;
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs b/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs
new file mode 100644
index 000000000..72652ef60
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs
@@ -0,0 +1,21 @@
+// Test precise capture of a multi-variant enum (when remaining variants are
+// visibly uninhabited).
+// edition:2021
+// run-pass
+#![feature(exhaustive_patterns)]
+#![feature(never_type)]
+
+pub fn main() {
+ let mut r = Result::<!, (u32, u32)>::Err((0, 0));
+ let mut f = || {
+ let Err((ref mut a, _)) = r;
+ *a = 1;
+ };
+ let mut g = || {
+ let Err((_, ref mut b)) = r;
+ *b = 2;
+ };
+ f();
+ g();
+ assert_eq!(r, Err((1, 2)));
+}
diff --git a/tests/ui/closures/binder/nested-closures-regions.stderr b/tests/ui/closures/binder/nested-closures-regions.stderr
index b385e0ed6..381aadb15 100644
--- a/tests/ui/closures/binder/nested-closures-regions.stderr
+++ b/tests/ui/closures/binder/nested-closures-regions.stderr
@@ -9,11 +9,11 @@ LL | for<'a> || -> () { for<'c> |_: &'a ()| -> () {}; };
extern "rust-call" fn((&(),)),
(),
]
- = note: late-bound region is '_#4r
- = note: late-bound region is '_#2r
+ = note: late-bound region is '?4
+ = note: late-bound region is '?2
= note: number of external vids: 3
- = note: where '_#1r: '_#2r
- = note: where '_#2r: '_#1r
+ = note: where '?1: '?2
+ = note: where '?2: '?1
note: no external requirements
--> $DIR/nested-closures-regions.rs:8:5
@@ -26,7 +26,7 @@ LL | for<'a> || -> () { for<'c> |_: &'a ()| -> () {}; };
extern "rust-call" fn(()),
(),
]
- = note: late-bound region is '_#2r
+ = note: late-bound region is '?2
note: no external requirements
--> $DIR/nested-closures-regions.rs:7:1
diff --git a/tests/ui/closures/issue-868.rs b/tests/ui/closures/issue-868.rs
new file mode 100644
index 000000000..ce0a3c7ca
--- /dev/null
+++ b/tests/ui/closures/issue-868.rs
@@ -0,0 +1,18 @@
+// run-pass
+#![allow(unused_parens)]
+// pretty-expanded FIXME #23616
+
+fn f<T, F>(g: F) -> T where F: FnOnce() -> T { g() }
+
+pub fn main() {
+ let _x = f( | | { 10 });
+ // used to be: cannot determine a type for this expression
+ f(| | { });
+ // ditto
+ f( | | { ()});
+ // always worked
+ let _: () = f(| | { });
+ // empty block with no type info should compile too
+ let _ = f(||{});
+ let _ = (||{});
+}
diff --git a/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr b/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr
index ff89dd340..381bb0c08 100644
--- a/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr
+++ b/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr
@@ -9,7 +9,7 @@ LL | let c1 : () = c;
| expected due to this
|
= note: expected unit type `()`
- found closure `[mod1::f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#16t, extern "rust-call" fn(()), _#15t]]`
+ found closure `[mod1::f<T>::{closure#0} closure_substs=(unavailable) substs=[T, ?16t, extern "rust-call" fn(()), ?15t]]`
help: use parentheses to call this closure
|
LL | let c1 : () = c();
diff --git a/tests/ui/closures/print/closure-print-generic-verbose-1.stderr b/tests/ui/closures/print/closure-print-generic-verbose-1.stderr
index 3ab7c66d1..9a1f18fa8 100644
--- a/tests/ui/closures/print/closure-print-generic-verbose-1.stderr
+++ b/tests/ui/closures/print/closure-print-generic-verbose-1.stderr
@@ -2,7 +2,7 @@ error[E0382]: use of moved value: `c`
--> $DIR/closure-print-generic-verbose-1.rs:17:5
|
LL | let c = to_fn_once(move|| {
- | - move occurs because `c` has type `[f<T>::{closure#0} closure_kind_ty=i32 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=(Foo<&'_#9r str>, T)]`, which does not implement the `Copy` trait
+ | - move occurs because `c` has type `[f<T>::{closure#0} closure_kind_ty=i32 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=(Foo<&'?9 str>, T)]`, which does not implement the `Copy` trait
...
LL | c();
| --- `c` moved due to this call
diff --git a/tests/ui/closures/print/closure-print-generic-verbose-2.stderr b/tests/ui/closures/print/closure-print-generic-verbose-2.stderr
index 5bbf84f96..2a4d16c48 100644
--- a/tests/ui/closures/print/closure-print-generic-verbose-2.stderr
+++ b/tests/ui/closures/print/closure-print-generic-verbose-2.stderr
@@ -9,7 +9,7 @@ LL | let c1 : () = c;
| expected due to this
|
= note: expected unit type `()`
- found closure `[f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#16t, extern "rust-call" fn(()), _#15t]]`
+ found closure `[f<T>::{closure#0} closure_substs=(unavailable) substs=[T, ?16t, extern "rust-call" fn(()), ?15t]]`
help: use parentheses to call this closure
|
LL | let c1 : () = c();
diff --git a/tests/ui/closures/print/closure-print-verbose.stderr b/tests/ui/closures/print/closure-print-verbose.stderr
index 083717b33..9e219435e 100644
--- a/tests/ui/closures/print/closure-print-verbose.stderr
+++ b/tests/ui/closures/print/closure-print-verbose.stderr
@@ -7,7 +7,7 @@ LL | let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
| expected due to this
|
= note: expected fn pointer `fn(u8) -> u8`
- found closure `[main::{closure#0} closure_substs=(unavailable) substs=[i8, extern "rust-call" fn((u8,)) -> u8, _#6t]]`
+ found closure `[main::{closure#0} closure_substs=(unavailable) substs=[i8, extern "rust-call" fn((u8,)) -> u8, ?6t]]`
note: closures can only be coerced to `fn` types if they do not capture any variables
--> $DIR/closure-print-verbose.rs:10:39
|
diff --git a/tests/ui/closures/static-closures-with-nonstatic-return.rs b/tests/ui/closures/static-closures-with-nonstatic-return.rs
new file mode 100644
index 000000000..b5f0684ba
--- /dev/null
+++ b/tests/ui/closures/static-closures-with-nonstatic-return.rs
@@ -0,0 +1,15 @@
+// check-pass
+// known-bug: #84366
+
+// Should fail. Associated types of 'static types should be `'static`, but
+// argument-free closures can be `'static` and return non-`'static` types.
+
+#[allow(dead_code)]
+fn foo<'a>() {
+ let closure = || -> &'a str { "" };
+ assert_static(closure);
+}
+
+fn assert_static<T: 'static>(_: T) {}
+
+fn main() {}