Skip to content

Commit af3c154

Browse files
authored
Rollup merge of #86673 - m-ou-se:disjoint-capture-edition-lint, r=nikomatsakis
Make disjoint_capture_migration an edition lint. This turns the disjoint capture lint into an edition lint, and changes all the wording to refer to the edition. This includes the same first commit as #86671. See #86671. Fixes most of rust-lang/project-rfc-2229#43 (comment)
2 parents 14f3335 + 3c95a28 commit af3c154

23 files changed

+198
-112
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -3002,8 +3002,7 @@ declare_lint! {
30023002

30033003
declare_lint! {
30043004
/// The `disjoint_capture_migration` lint detects variables that aren't completely
3005-
/// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
3006-
/// order of at least one path starting at this variable.
3005+
/// captured in Rust 2021 and affect the Drop order of at least one path starting at this variable.
30073006
/// It can also detect when a variable implements a trait, but one of its field does not and
30083007
/// the field is captured by a closure and used with the assumption that said field implements
30093008
/// the same trait as the root variable.
@@ -3040,16 +3039,16 @@ declare_lint! {
30403039
///
30413040
/// ### Explanation
30423041
///
3043-
/// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
3044-
/// the feature `capture_disjoint_fields` is enabled.
3042+
/// In the above example, `p.y` will be dropped at the end of `f` instead of
3043+
/// with `c` in Rust 2021.
30453044
///
30463045
/// ### Example of auto-trait
30473046
///
30483047
/// ```rust,compile_fail
30493048
/// #![deny(disjoint_capture_migration)]
30503049
/// use std::thread;
30513050
///
3052-
/// struct Pointer (*mut i32);
3051+
/// struct Pointer(*mut i32);
30533052
/// unsafe impl Send for Pointer {}
30543053
///
30553054
/// fn main() {
@@ -3065,12 +3064,16 @@ declare_lint! {
30653064
///
30663065
/// ### Explanation
30673066
///
3068-
/// In the above example `fptr.0` is captured when feature `capture_disjoint_fields` is enabled.
3067+
/// In the above example, only `fptr.0` is captured in Rust 2021.
30693068
/// The field is of type *mut i32 which doesn't implement Send, making the code invalid as the
30703069
/// field cannot be sent between thread safely.
30713070
pub DISJOINT_CAPTURE_MIGRATION,
30723071
Allow,
3073-
"Drop reorder and auto traits error because of `capture_disjoint_fields`"
3072+
"detects closures affected by Rust 2021 changes",
3073+
@future_incompatible = FutureIncompatibleInfo {
3074+
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
3075+
explain_reason: false,
3076+
};
30743077
}
30753078

30763079
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);

compiler/rustc_typeck/src/check/upvar.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
495495
|lint| {
496496
let mut diagnostics_builder = lint.build(
497497
format!(
498-
"{} affected for closure because of `capture_disjoint_fields`",
498+
"{} will change in Rust 2021",
499499
reasons
500500
)
501501
.as_str(),
502502
);
503+
diagnostics_builder.note("for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>");
503504
let closure_body_span = self.tcx.hir().span(body_id.hir_id);
504505
let (sugg, app) =
505506
match self.tcx.sess.source_map().span_to_snippet(closure_body_span) {

src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test_send_trait() {
1111
let mut f = 10;
1212
let fptr = SendPointer(&mut f as *mut i32);
1313
thread::spawn(move || { let _ = &fptr; unsafe {
14-
//~^ ERROR: `Send` trait implementation affected for closure because of `capture_disjoint_fields`
14+
//~^ ERROR: `Send` trait implementation
1515
//~| HELP: add a dummy let to cause `fptr` to be fully captured
1616
*fptr.0 = 20;
1717
} });
@@ -28,7 +28,7 @@ fn test_sync_trait() {
2828
let f = CustomInt(&mut f as *mut i32);
2929
let fptr = SyncPointer(f);
3030
thread::spawn(move || { let _ = &fptr; unsafe {
31-
//~^ ERROR: `Sync`, `Send` trait implementation affected for closure because of `capture_disjoint_fields`
31+
//~^ ERROR: `Sync`, `Send` trait implementation
3232
//~| HELP: add a dummy let to cause `fptr` to be fully captured
3333
*fptr.0.0 = 20;
3434
} });
@@ -49,7 +49,7 @@ impl Clone for U {
4949
fn test_clone_trait() {
5050
let f = U(S(String::from("Hello World")), T(0));
5151
let c = || { let _ = &f;
52-
//~^ ERROR: `Clone` trait implementation, and drop order affected for closure because of `capture_disjoint_fields`
52+
//~^ ERROR: `Clone` trait implementation, and drop order
5353
//~| HELP: add a dummy let to cause `f` to be fully captured
5454
let f_1 = f.1;
5555
println!("{:?}", f_1.0);

src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test_send_trait() {
1111
let mut f = 10;
1212
let fptr = SendPointer(&mut f as *mut i32);
1313
thread::spawn(move || unsafe {
14-
//~^ ERROR: `Send` trait implementation affected for closure because of `capture_disjoint_fields`
14+
//~^ ERROR: `Send` trait implementation
1515
//~| HELP: add a dummy let to cause `fptr` to be fully captured
1616
*fptr.0 = 20;
1717
});
@@ -28,7 +28,7 @@ fn test_sync_trait() {
2828
let f = CustomInt(&mut f as *mut i32);
2929
let fptr = SyncPointer(f);
3030
thread::spawn(move || unsafe {
31-
//~^ ERROR: `Sync`, `Send` trait implementation affected for closure because of `capture_disjoint_fields`
31+
//~^ ERROR: `Sync`, `Send` trait implementation
3232
//~| HELP: add a dummy let to cause `fptr` to be fully captured
3333
*fptr.0.0 = 20;
3434
});
@@ -49,7 +49,7 @@ impl Clone for U {
4949
fn test_clone_trait() {
5050
let f = U(S(String::from("Hello World")), T(0));
5151
let c = || {
52-
//~^ ERROR: `Clone` trait implementation, and drop order affected for closure because of `capture_disjoint_fields`
52+
//~^ ERROR: `Clone` trait implementation, and drop order
5353
//~| HELP: add a dummy let to cause `f` to be fully captured
5454
let f_1 = f.1;
5555
println!("{:?}", f_1.0);

src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `Send` trait implementation affected for closure because of `capture_disjoint_fields`
1+
error: `Send` trait implementation will change in Rust 2021
22
--> $DIR/auto_traits.rs:13:19
33
|
44
LL | thread::spawn(move || unsafe {
@@ -14,6 +14,7 @@ note: the lint level is defined here
1414
|
1515
LL | #![deny(disjoint_capture_migration)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
1718
help: add a dummy let to cause `fptr` to be fully captured
1819
|
1920
LL | thread::spawn(move || { let _ = &fptr; unsafe {
@@ -23,7 +24,7 @@ LL | *fptr.0 = 20;
2324
LL | } });
2425
|
2526

26-
error: `Sync`, `Send` trait implementation affected for closure because of `capture_disjoint_fields`
27+
error: `Sync`, `Send` trait implementation will change in Rust 2021
2728
--> $DIR/auto_traits.rs:30:19
2829
|
2930
LL | thread::spawn(move || unsafe {
@@ -34,6 +35,7 @@ LL | | *fptr.0.0 = 20;
3435
LL | | });
3536
| |_____^
3637
|
38+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
3739
help: add a dummy let to cause `fptr` to be fully captured
3840
|
3941
LL | thread::spawn(move || { let _ = &fptr; unsafe {
@@ -43,7 +45,7 @@ LL | *fptr.0.0 = 20;
4345
LL | } });
4446
|
4547

46-
error: `Clone` trait implementation, and drop order affected for closure because of `capture_disjoint_fields`
48+
error: `Clone` trait implementation, and drop order will change in Rust 2021
4749
--> $DIR/auto_traits.rs:51:13
4850
|
4951
LL | let c = || {
@@ -55,6 +57,7 @@ LL | | println!("{:?}", f_1.0);
5557
LL | | };
5658
| |_____^
5759
|
60+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
5861
help: add a dummy let to cause `f` to be fully captured
5962
|
6063
LL | let c = || { let _ = &f;

src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.fixed

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fn test1_all_need_migration() {
1313
let t2 = (String::new(), String::new());
1414

1515
let c = || { let _ = (&t, &t1, &t2);
16-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
16+
//~^ ERROR: drop order
17+
//~| NOTE: for more information, see
1718
//~| HELP: add a dummy let to cause `t`, `t1`, `t2` to be fully captured
1819

1920
let _t = t.0;
@@ -32,7 +33,8 @@ fn test2_only_precise_paths_need_migration() {
3233
let t2 = (String::new(), String::new());
3334

3435
let c = || { let _ = (&t, &t1);
35-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
36+
//~^ ERROR: drop order
37+
//~| NOTE: for more information, see
3638
//~| HELP: add a dummy let to cause `t`, `t1` to be fully captured
3739
let _t = t.0;
3840
let _t1 = t1.0;
@@ -48,7 +50,8 @@ fn test3_only_by_value_need_migration() {
4850
let t = (String::new(), String::new());
4951
let t1 = (String::new(), String::new());
5052
let c = || { let _ = &t;
51-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
53+
//~^ ERROR: drop order
54+
//~| NOTE: for more information, see
5255
//~| HELP: add a dummy let to cause `t` to be fully captured
5356
let _t = t.0;
5457
println!("{}", t1.1);
@@ -66,7 +69,8 @@ fn test4_only_non_copy_types_need_migration() {
6669
let t1 = (0i32, 0i32);
6770

6871
let c = || { let _ = &t;
69-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
72+
//~^ ERROR: drop order
73+
//~| NOTE: for more information, see
7074
//~| HELP: add a dummy let to cause `t` to be fully captured
7175
let _t = t.0;
7276
let _t1 = t1.0;
@@ -84,7 +88,8 @@ fn test5_only_drop_types_need_migration() {
8488
let s = S(0i32, 0i32);
8589

8690
let c = || { let _ = &t;
87-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
91+
//~^ ERROR: drop order
92+
//~| NOTE: for more information, see
8893
//~| HELP: add a dummy let to cause `t` to be fully captured
8994
let _t = t.0;
9095
let _s = s.0;
@@ -99,7 +104,8 @@ fn test6_move_closures_non_copy_types_might_need_migration() {
99104
let t = (String::new(), String::new());
100105
let t1 = (String::new(), String::new());
101106
let c = move || { let _ = (&t1, &t);
102-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
107+
//~^ ERROR: drop order
108+
//~| NOTE: for more information, see
103109
//~| HELP: add a dummy let to cause `t1`, `t` to be fully captured
104110
println!("{} {}", t1.1, t.1);
105111
};
@@ -114,7 +120,8 @@ fn test7_drop_non_drop_aggregate_need_migration() {
114120
let t = (String::new(), String::new(), 0i32);
115121

116122
let c = || { let _ = &t;
117-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
123+
//~^ ERROR: drop order
124+
//~| NOTE: for more information, see
118125
//~| HELP: add a dummy let to cause `t` to be fully captured
119126
let _t = t.0;
120127
};

src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fn test1_all_need_migration() {
1313
let t2 = (String::new(), String::new());
1414

1515
let c = || {
16-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
16+
//~^ ERROR: drop order
17+
//~| NOTE: for more information, see
1718
//~| HELP: add a dummy let to cause `t`, `t1`, `t2` to be fully captured
1819

1920
let _t = t.0;
@@ -32,7 +33,8 @@ fn test2_only_precise_paths_need_migration() {
3233
let t2 = (String::new(), String::new());
3334

3435
let c = || {
35-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
36+
//~^ ERROR: drop order
37+
//~| NOTE: for more information, see
3638
//~| HELP: add a dummy let to cause `t`, `t1` to be fully captured
3739
let _t = t.0;
3840
let _t1 = t1.0;
@@ -48,7 +50,8 @@ fn test3_only_by_value_need_migration() {
4850
let t = (String::new(), String::new());
4951
let t1 = (String::new(), String::new());
5052
let c = || {
51-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
53+
//~^ ERROR: drop order
54+
//~| NOTE: for more information, see
5255
//~| HELP: add a dummy let to cause `t` to be fully captured
5356
let _t = t.0;
5457
println!("{}", t1.1);
@@ -66,7 +69,8 @@ fn test4_only_non_copy_types_need_migration() {
6669
let t1 = (0i32, 0i32);
6770

6871
let c = || {
69-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
72+
//~^ ERROR: drop order
73+
//~| NOTE: for more information, see
7074
//~| HELP: add a dummy let to cause `t` to be fully captured
7175
let _t = t.0;
7276
let _t1 = t1.0;
@@ -84,7 +88,8 @@ fn test5_only_drop_types_need_migration() {
8488
let s = S(0i32, 0i32);
8589

8690
let c = || {
87-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
91+
//~^ ERROR: drop order
92+
//~| NOTE: for more information, see
8893
//~| HELP: add a dummy let to cause `t` to be fully captured
8994
let _t = t.0;
9095
let _s = s.0;
@@ -99,7 +104,8 @@ fn test6_move_closures_non_copy_types_might_need_migration() {
99104
let t = (String::new(), String::new());
100105
let t1 = (String::new(), String::new());
101106
let c = move || {
102-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
107+
//~^ ERROR: drop order
108+
//~| NOTE: for more information, see
103109
//~| HELP: add a dummy let to cause `t1`, `t` to be fully captured
104110
println!("{} {}", t1.1, t.1);
105111
};
@@ -114,7 +120,8 @@ fn test7_drop_non_drop_aggregate_need_migration() {
114120
let t = (String::new(), String::new(), 0i32);
115121

116122
let c = || {
117-
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
123+
//~^ ERROR: drop order
124+
//~| NOTE: for more information, see
118125
//~| HELP: add a dummy let to cause `t` to be fully captured
119126
let _t = t.0;
120127
};

0 commit comments

Comments
 (0)