Skip to content

Commit 3c95a28

Browse files
committed
Make disjoint_capture_migration an edition lint.
1 parent 4645679 commit 3c95a28

23 files changed

+198
-112
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -3001,8 +3001,7 @@ declare_lint! {
30013001

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

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

compiler/rustc_typeck/src/check/upvar.rs

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