Skip to content

Commit 22f2332

Browse files
authored
Rollup merge of #86661 - sexxi-goose:edition_fix, r=nikomatsakis
Editon 2021 enables precise capture r? `@nikomatsakis`
2 parents 5028581 + 10a37bf commit 22f2332

File tree

141 files changed

+463
-1282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+463
-1282
lines changed

compiler/rustc_mir_build/src/build/expr/as_place.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
217217
ty::ClosureKind::FnOnce => {}
218218
}
219219

220+
// We won't be building MIR if the closure wasn't local
221+
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
222+
let closure_span = tcx.hir().span(closure_hir_id);
223+
220224
let (capture_index, capture) = if let Some(capture_details) =
221225
find_capture_matching_projections(
222226
typeck_results,
@@ -226,7 +230,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
226230
) {
227231
capture_details
228232
} else {
229-
if !tcx.features().capture_disjoint_fields {
233+
if !enable_precise_capture(tcx, closure_span) {
230234
bug!(
231235
"No associated capture found for {:?}[{:#?}] even though \
232236
capture_disjoint_fields isn't enabled",
@@ -242,8 +246,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
242246
return Err(from_builder);
243247
};
244248

245-
let closure_ty = typeck_results
246-
.node_type(tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()));
249+
let closure_ty = typeck_results.node_type(closure_hir_id);
247250

248251
let substs = match closure_ty.kind() {
249252
ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs),
@@ -780,3 +783,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
780783
}
781784
}
782785
}
786+
787+
/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
788+
/// user is using Rust Edition 2021 or higher.
789+
fn enable_precise_capture(tcx: TyCtxt<'_>, closure_span: Span) -> bool {
790+
tcx.features().capture_disjoint_fields || closure_span.rust_2021()
791+
}

src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3-
//~| `#[warn(incomplete_features)]` on by default
4-
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
1+
// edition:2021
52
#![feature(rustc_attrs)]
63

74
// Ensure that capture analysis results in arrays being completely captured.
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/arrays-completely-captured.rs:11:17
2+
--> $DIR/arrays-completely-captured.rs:8:17
33
|
44
LL | let mut c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99

10-
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
11-
--> $DIR/arrays-completely-captured.rs:1:12
12-
|
13-
LL | #![feature(capture_disjoint_fields)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: `#[warn(incomplete_features)]` on by default
17-
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
18-
1910
error: First Pass analysis includes:
20-
--> $DIR/arrays-completely-captured.rs:14:5
11+
--> $DIR/arrays-completely-captured.rs:11:5
2112
|
2213
LL | / || {
2314
LL | |
@@ -29,13 +20,13 @@ LL | | };
2920
| |_____^
3021
|
3122
note: Capturing m[] -> MutBorrow
32-
--> $DIR/arrays-completely-captured.rs:17:9
23+
--> $DIR/arrays-completely-captured.rs:14:9
3324
|
3425
LL | m[0] += 10;
3526
| ^
3627

3728
error: Min Capture analysis includes:
38-
--> $DIR/arrays-completely-captured.rs:14:5
29+
--> $DIR/arrays-completely-captured.rs:11:5
3930
|
4031
LL | / || {
4132
LL | |
@@ -47,11 +38,11 @@ LL | | };
4738
| |_____^
4839
|
4940
note: Min Capture m[] -> MutBorrow
50-
--> $DIR/arrays-completely-captured.rs:17:9
41+
--> $DIR/arrays-completely-captured.rs:14:9
5142
|
5243
LL | m[0] += 10;
5344
| ^
5445

55-
error: aborting due to 3 previous errors; 1 warning emitted
46+
error: aborting due to 3 previous errors
5647

5748
For more information about this error, try `rustc --explain E0658`.

src/test/ui/closures/2229_closure_analysis/by_value.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1+
// edition:2021
2+
13
// Test that we handle derferences properly when only some of the captures are being moved with
24
// `capture_disjoint_fields` enabled.
3-
4-
5-
#![feature(capture_disjoint_fields)]
6-
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
7-
//~| NOTE: `#[warn(incomplete_features)]` on by default
8-
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
95
#![feature(rustc_attrs)]
106

117
#[derive(Debug, Default)]
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/by_value.rs:22:13
2+
--> $DIR/by_value.rs:18:13
33
|
44
LL | let c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99

10-
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
11-
--> $DIR/by_value.rs:5:12
12-
|
13-
LL | #![feature(capture_disjoint_fields)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: `#[warn(incomplete_features)]` on by default
17-
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
18-
1910
error: First Pass analysis includes:
20-
--> $DIR/by_value.rs:25:5
11+
--> $DIR/by_value.rs:21:5
2112
|
2213
LL | / || {
2314
LL | |
@@ -29,23 +20,23 @@ LL | | };
2920
| |_____^
3021
|
3122
note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
32-
--> $DIR/by_value.rs:28:17
23+
--> $DIR/by_value.rs:24:17
3324
|
3425
LL | let p = t.0.0;
3526
| ^^^^^
3627
note: Capturing t[(0, 0)] -> ByValue
37-
--> $DIR/by_value.rs:28:17
28+
--> $DIR/by_value.rs:24:17
3829
|
3930
LL | let p = t.0.0;
4031
| ^^^^^
4132
note: Capturing t[(1, 0)] -> ImmBorrow
42-
--> $DIR/by_value.rs:32:29
33+
--> $DIR/by_value.rs:28:29
4334
|
4435
LL | println!("{} {:?}", t.1, p);
4536
| ^^^
4637

4738
error: Min Capture analysis includes:
48-
--> $DIR/by_value.rs:25:5
39+
--> $DIR/by_value.rs:21:5
4940
|
5041
LL | / || {
5142
LL | |
@@ -57,16 +48,16 @@ LL | | };
5748
| |_____^
5849
|
5950
note: Min Capture t[(0, 0)] -> ByValue
60-
--> $DIR/by_value.rs:28:17
51+
--> $DIR/by_value.rs:24:17
6152
|
6253
LL | let p = t.0.0;
6354
| ^^^^^
6455
note: Min Capture t[(1, 0)] -> ImmBorrow
65-
--> $DIR/by_value.rs:32:29
56+
--> $DIR/by_value.rs:28:29
6657
|
6758
LL | println!("{} {:?}", t.1, p);
6859
| ^^^
6960

70-
error: aborting due to 3 previous errors; 1 warning emitted
61+
error: aborting due to 3 previous errors
7162

7263
For more information about this error, try `rustc --explain E0658`.

src/test/ui/closures/2229_closure_analysis/capture-analysis-1.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3-
//~| NOTE: `#[warn(incomplete_features)]` on by default
4-
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
1+
// edition:2021
2+
53
#![feature(rustc_attrs)]
64

75
#[derive(Debug)]
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/capture-analysis-1.rs:17:13
2+
--> $DIR/capture-analysis-1.rs:15:13
33
|
44
LL | let c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99

10-
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
11-
--> $DIR/capture-analysis-1.rs:1:12
12-
|
13-
LL | #![feature(capture_disjoint_fields)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: `#[warn(incomplete_features)]` on by default
17-
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
18-
1910
error: First Pass analysis includes:
20-
--> $DIR/capture-analysis-1.rs:20:5
11+
--> $DIR/capture-analysis-1.rs:18:5
2112
|
2213
LL | / || {
2314
LL | |
@@ -29,28 +20,28 @@ LL | | };
2920
| |_____^
3021
|
3122
note: Capturing p[] -> ImmBorrow
32-
--> $DIR/capture-analysis-1.rs:23:26
23+
--> $DIR/capture-analysis-1.rs:21:26
3324
|
3425
LL | println!("{:?}", p);
3526
| ^
3627
note: Capturing p[(0, 0)] -> ImmBorrow
37-
--> $DIR/capture-analysis-1.rs:26:26
28+
--> $DIR/capture-analysis-1.rs:24:26
3829
|
3930
LL | println!("{:?}", p.x);
4031
| ^^^
4132
note: Capturing q[(0, 0)] -> ImmBorrow
42-
--> $DIR/capture-analysis-1.rs:29:26
33+
--> $DIR/capture-analysis-1.rs:27:26
4334
|
4435
LL | println!("{:?}", q.x);
4536
| ^^^
4637
note: Capturing q[] -> ImmBorrow
47-
--> $DIR/capture-analysis-1.rs:31:26
38+
--> $DIR/capture-analysis-1.rs:29:26
4839
|
4940
LL | println!("{:?}", q);
5041
| ^
5142

5243
error: Min Capture analysis includes:
53-
--> $DIR/capture-analysis-1.rs:20:5
44+
--> $DIR/capture-analysis-1.rs:18:5
5445
|
5546
LL | / || {
5647
LL | |
@@ -62,16 +53,16 @@ LL | | };
6253
| |_____^
6354
|
6455
note: Min Capture p[] -> ImmBorrow
65-
--> $DIR/capture-analysis-1.rs:23:26
56+
--> $DIR/capture-analysis-1.rs:21:26
6657
|
6758
LL | println!("{:?}", p);
6859
| ^
6960
note: Min Capture q[] -> ImmBorrow
70-
--> $DIR/capture-analysis-1.rs:31:26
61+
--> $DIR/capture-analysis-1.rs:29:26
7162
|
7263
LL | println!("{:?}", q);
7364
| ^
7465

75-
error: aborting due to 3 previous errors; 1 warning emitted
66+
error: aborting due to 3 previous errors
7667

7768
For more information about this error, try `rustc --explain E0658`.

src/test/ui/closures/2229_closure_analysis/capture-analysis-2.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3-
//~| NOTE: `#[warn(incomplete_features)]` on by default
4-
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
1+
// edition:2021
2+
53
#![feature(rustc_attrs)]
64

75
#[derive(Debug)]
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/capture-analysis-2.rs:16:13
2+
--> $DIR/capture-analysis-2.rs:14:13
33
|
44
LL | let c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99

10-
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
11-
--> $DIR/capture-analysis-2.rs:1:12
12-
|
13-
LL | #![feature(capture_disjoint_fields)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: `#[warn(incomplete_features)]` on by default
17-
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
18-
1910
error: First Pass analysis includes:
20-
--> $DIR/capture-analysis-2.rs:19:5
11+
--> $DIR/capture-analysis-2.rs:17:5
2112
|
2213
LL | / || {
2314
LL | |
@@ -29,18 +20,18 @@ LL | | };
2920
| |_____^
3021
|
3122
note: Capturing p[(0, 0)] -> ByValue
32-
--> $DIR/capture-analysis-2.rs:22:18
23+
--> $DIR/capture-analysis-2.rs:20:18
3324
|
3425
LL | let _x = p.x;
3526
| ^^^
3627
note: Capturing p[] -> ImmBorrow
37-
--> $DIR/capture-analysis-2.rs:25:26
28+
--> $DIR/capture-analysis-2.rs:23:26
3829
|
3930
LL | println!("{:?}", p);
4031
| ^
4132

4233
error: Min Capture analysis includes:
43-
--> $DIR/capture-analysis-2.rs:19:5
34+
--> $DIR/capture-analysis-2.rs:17:5
4435
|
4536
LL | / || {
4637
LL | |
@@ -52,14 +43,14 @@ LL | | };
5243
| |_____^
5344
|
5445
note: Min Capture p[] -> ByValue
55-
--> $DIR/capture-analysis-2.rs:22:18
46+
--> $DIR/capture-analysis-2.rs:20:18
5647
|
5748
LL | let _x = p.x;
5849
| ^^^ p[] captured as ByValue here
5950
...
6051
LL | println!("{:?}", p);
6152
| ^ p[] used here
6253

63-
error: aborting due to 3 previous errors; 1 warning emitted
54+
error: aborting due to 3 previous errors
6455

6556
For more information about this error, try `rustc --explain E0658`.

src/test/ui/closures/2229_closure_analysis/capture-analysis-3.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3-
//~| NOTE: `#[warn(incomplete_features)]` on by default
4-
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
1+
// edition:2021
2+
53
#![feature(rustc_attrs)]
64

75
#[derive(Debug)]

0 commit comments

Comments
 (0)