Attempt to deal with nested closures properly

This commit is contained in:
Roxane 2021-02-21 10:20:40 -05:00
parent d4f8729c89
commit b6cf070eb4
12 changed files with 560 additions and 15 deletions

View file

@ -0,0 +1,21 @@
#![feature(capture_disjoint_fields)]
#![feature(rustc_attrs)]
fn main() {
let _z = 9;
let t = (String::from("Hello"), String::from("World"));
let g = (String::from("Mr"), String::from("Goose"));
let a = #[rustc_capture_analysis] || {
let (_, g2) = g;
println!("{}", g2);
let c = #[rustc_capture_analysis] || {
let (_, t2) = t;
println!("{}", t2);
};
c();
};
a();
}

View file

@ -0,0 +1,110 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/destructure-pattern-closure-within-closure.rs:9:13
|
LL | let a = #[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/destructure-pattern-closure-within-closure.rs:12:17
|
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
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/destructure-pattern-closure-within-closure.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
error: First Pass analysis includes:
--> $DIR/destructure-pattern-closure-within-closure.rs:12:43
|
LL | let c = #[rustc_capture_analysis] || {
| ___________________________________________^
LL | | let (_, t2) = t;
LL | | println!("{}", t2);
LL | | };
| |_________^
|
note: Capturing t[(1, 0)] -> ByValue
--> $DIR/destructure-pattern-closure-within-closure.rs:13:27
|
LL | let (_, t2) = t;
| ^
error: Min Capture analysis includes:
--> $DIR/destructure-pattern-closure-within-closure.rs:12:43
|
LL | let c = #[rustc_capture_analysis] || {
| ___________________________________________^
LL | | let (_, t2) = t;
LL | | println!("{}", t2);
LL | | };
| |_________^
|
note: Min Capture t[(1, 0)] -> ByValue
--> $DIR/destructure-pattern-closure-within-closure.rs:13:27
|
LL | let (_, t2) = t;
| ^
error: First Pass analysis includes:
--> $DIR/destructure-pattern-closure-within-closure.rs:9:39
|
LL | let a = #[rustc_capture_analysis] || {
| _______________________________________^
LL | | let (_, g2) = g;
LL | | println!("{}", g2);
LL | | let c = #[rustc_capture_analysis] || {
... |
LL | | c();
LL | | };
| |_____^
|
note: Capturing g[(1, 0)] -> ByValue
--> $DIR/destructure-pattern-closure-within-closure.rs:10:23
|
LL | let (_, g2) = g;
| ^
note: Capturing t[(1, 0)] -> ByValue
--> $DIR/destructure-pattern-closure-within-closure.rs:13:27
|
LL | let (_, t2) = t;
| ^
error: Min Capture analysis includes:
--> $DIR/destructure-pattern-closure-within-closure.rs:9:39
|
LL | let a = #[rustc_capture_analysis] || {
| _______________________________________^
LL | | let (_, g2) = g;
LL | | println!("{}", g2);
LL | | let c = #[rustc_capture_analysis] || {
... |
LL | | c();
LL | | };
| |_____^
|
note: Min Capture g[(1, 0)] -> ByValue
--> $DIR/destructure-pattern-closure-within-closure.rs:10:23
|
LL | let (_, g2) = g;
| ^
note: Min Capture t[(1, 0)] -> ByValue
--> $DIR/destructure-pattern-closure-within-closure.rs:13:27
|
LL | let (_, t2) = t;
| ^
error: aborting due to 6 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0658`.

View file

@ -0,0 +1,118 @@
//check-pass
#![feature(capture_disjoint_fields)]
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
#![warn(unused)]
struct Point {
x: u32,
y: u32,
}
fn test1() {
let _z = 9;
let t = (String::from("Hello"), String::from("World"));
let c = || {
let (t1, t2) = t;
println!("{} {}", t1, t2);
};
c();
}
fn test2() {
let _z = 9;
let t = (String::from("Hello"), String::from("World"));
let c = || {
let (t1, _) = t;
println!("{}", t1);
};
c();
}
fn test3() {
let _z = 9;
let t = (String::from("Hello"), String::from("World"));
let c = || {
let (_, t2) = t;
println!("{}", t2);
};
c();
}
fn test4() {
let _z = 9;
let t = (String::from("Hello"), String::from("World"));
//~^ WARN unused variable: `t`
let c = || {
let (_, _) = t;
};
c();
}
fn test5() {
let _z = 9;
let t = (String::new(), String::new());
let _c = || {
let _a = match t {
(t1, _) => t1,
};
};
}
fn test6() {
let _z = 9;
let t = (String::new(), String::new());
let _c = || {
let _a = match t {
(_, t2) => t2,
};
};
}
fn test7() {
let x = 0;
//~^ WARN unused variable: `x`
let tup = (1, 2);
//~^ WARN unused variable: `tup`
let p = Point { x: 10, y: 20 };
let c = || {
let _ = x;
let Point { x, y } = p; // 1
//~^ WARN unused variable: `x`
println!("{}", y);
let (_, _) = tup; // 2
};
c();
}
fn test8() {
let _z = 9;
let t = (String::from("Hello"), String::from("World"));
let c = || {
let (_, t) = t;
println!("{}", t);
};
c();
}
fn main() {
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
}

View file

@ -0,0 +1,42 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/destructure_patterns-1.rs:2:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
warning: unused variable: `t`
--> $DIR/destructure_patterns-1.rs:49:9
|
LL | let t = (String::from("Hello"), String::from("World"));
| ^ help: if this is intentional, prefix it with an underscore: `_t`
|
note: the lint level is defined here
--> $DIR/destructure_patterns-1.rs:4:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
warning: unused variable: `x`
--> $DIR/destructure_patterns-1.rs:88:21
|
LL | let Point { x, y } = p; // 1
| ^ help: try ignoring the field: `x: _`
warning: unused variable: `x`
--> $DIR/destructure_patterns-1.rs:80:9
|
LL | let x = 0;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
warning: unused variable: `tup`
--> $DIR/destructure_patterns-1.rs:82:9
|
LL | let tup = (1, 2);
| ^^^ help: if this is intentional, prefix it with an underscore: `_tup`
warning: 5 warnings emitted

View file

@ -0,0 +1,52 @@
#![feature(capture_disjoint_fields)]
#![feature(rustc_attrs)]
struct S {
a: String,
b: String,
}
fn main() {
let t = (String::new(), String::new());
let s = S {
a: String::new(),
b: String::new(),
};
let c = #[rustc_capture_analysis] || {
let (t1, t2) = t;
};
// MIR Build
//
// Create place for the initalizer in let which is `t`
//
// I'm reading Field 1 from `t`, so apply Field projections;
//
// new place -> t[1]
//
// I'm reading Field 2 from `t`, so apply Field projections;
//
// new place -> t[2]
//
// New
// ---------
//
// I'm building something starting at `t`
//
// I read field 1 from `t`
//
// I need to use `t[1]`, therefore the place must be constructable
//
// Find the capture index for `t[1]` for this closure.
//
// I read field 2 from `t`
//
// I need to use `t[2]`, therefore the place must be constructable
//
// Find the capture index for `t[2]` for this closure.
c();
}

View file

@ -0,0 +1,61 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/destructure_patterns.rs:17:13
|
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
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/destructure_patterns.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
error: First Pass analysis includes:
--> $DIR/destructure_patterns.rs:17:39
|
LL | let c = #[rustc_capture_analysis] || {
| _______________________________________^
LL | | let (t1, t2) = t;
LL | | };
| |_____^
|
note: Capturing t[(0, 0)] -> ByValue
--> $DIR/destructure_patterns.rs:18:24
|
LL | let (t1, t2) = t;
| ^
note: Capturing t[(1, 0)] -> ByValue
--> $DIR/destructure_patterns.rs:18:24
|
LL | let (t1, t2) = t;
| ^
error: Min Capture analysis includes:
--> $DIR/destructure_patterns.rs:17:39
|
LL | let c = #[rustc_capture_analysis] || {
| _______________________________________^
LL | | let (t1, t2) = t;
LL | | };
| |_____^
|
note: Min Capture t[(0, 0)] -> ByValue
--> $DIR/destructure_patterns.rs:18:24
|
LL | let (t1, t2) = t;
| ^
note: Min Capture t[(1, 0)] -> ByValue
--> $DIR/destructure_patterns.rs:18:24
|
LL | let (t1, t2) = t;
| ^
error: aborting due to 3 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0658`.

View file

@ -0,0 +1,12 @@
#![feature(capture_disjoint_fields)]
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]
fn main() {
let foo = [1, 2, 3];
let c = #[rustc_capture_analysis] || {
//~^ ERROR: attributes on expressions are experimental
//~| ERROR: First Pass analysis includes:
match foo { _ => () };
};
}

View file

@ -0,0 +1,32 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/no_capture_with_wildcard_match.rs:7:13
|
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
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/no_capture_with_wildcard_match.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
error: First Pass analysis includes:
--> $DIR/no_capture_with_wildcard_match.rs:7:39
|
LL | let c = #[rustc_capture_analysis] || {
| _______________________________________^
LL | |
LL | |
LL | | match foo { _ => () };
LL | | };
| |_____^
error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0658`.

View file

@ -0,0 +1,23 @@
#![feature(capture_disjoint_fields)]
#![feature(rustc_attrs)]
struct S {
a: String,
b: String,
}
fn main() {
let s = S {
a: String::new(),
b: String::new(),
};
let c = #[rustc_capture_analysis] || {
let s2 = S {
a: format!("New a"),
..s
};
};
c();
}

View file

@ -0,0 +1,57 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/struct_update_syntax.rs:15:13
|
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
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/struct_update_syntax.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
error: First Pass analysis includes:
--> $DIR/struct_update_syntax.rs:15:39
|
LL | let c = #[rustc_capture_analysis] || {
| _______________________________________^
LL | | let s2 = S {
LL | | a: format!("New a"),
LL | | ..s
LL | | };
LL | | };
| |_____^
|
note: Capturing s[(1, 0)] -> ByValue
--> $DIR/struct_update_syntax.rs:18:15
|
LL | ..s
| ^
error: Min Capture analysis includes:
--> $DIR/struct_update_syntax.rs:15:39
|
LL | let c = #[rustc_capture_analysis] || {
| _______________________________________^
LL | | let s2 = S {
LL | | a: format!("New a"),
LL | | ..s
LL | | };
LL | | };
| |_____^
|
note: Min Capture s[(1, 0)] -> ByValue
--> $DIR/struct_update_syntax.rs:18:15
|
LL | ..s
| ^
error: aborting due to 3 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0658`.