You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if reasons.contains("closure trait implementation"){
540
+
let closure_body_span = self.tcx.hir().span(body_id.hir_id);
541
+
let closure_ending_span = self.tcx.sess.source_map().guess_head_span(closure_body_span).shrink_to_lo();
542
+
543
+
let missing_trait = &reasons[..reasons.find("closure trait implementation").unwrap() - 1];
544
+
545
+
diagnostics_builder.span_label(closure_ending_span,format!("in Rust 2018, this closure would implement {} as `{}` implements {}, but in Rust 2021, this closure will no longer implement {} as {} does not implement {}",
546
+
missing_trait,
547
+
self.tcx.hir().name(*var_hir_id),
548
+
missing_trait,
549
+
missing_trait,
550
+
captured_names,
551
+
missing_trait,
552
+
));
553
+
}
538
554
}
539
555
diagnostics_builder.note("for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>");
540
556
let closure_body_span = self.tcx.hir().span(body_id.hir_id);
Copy file name to clipboardExpand all lines: src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ fn test_send_trait() {
13
13
let fptr = SendPointer(&mut f as *mut i32);
14
14
thread::spawn(move || { let _ = &fptr; unsafe {
15
15
//~^ ERROR: `Send` closure trait implementation
16
+
//~| NOTE: in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0` does not implement `Send`
16
17
//~| NOTE: for more information, see
17
18
//~| HELP: add a dummy let to cause `fptr` to be fully captured
//~| NOTE: in Rust 2018, this closure would implement `Sync`, `Send` as `fptr` implements `Sync`, `Send`, but in Rust 2021, this closure will no longer implement `Sync`, `Send` as `fptr.0.0` does not implement `Sync`, `Send`
35
37
//~| NOTE: for more information, see
36
38
//~| HELP: add a dummy let to cause `fptr` to be fully captured
37
39
*fptr.0.0 = 20;
@@ -55,6 +57,7 @@ fn test_clone_trait() {
55
57
let f = U(S(String::from("Hello World")), T(0));
56
58
let c = || { let _ = &f;
57
59
//~^ ERROR: `Clone` closure trait implementation, and drop order
60
+
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f.1` does not implement `Clone`
58
61
//~| NOTE: for more information, see
59
62
//~| HELP: add a dummy let to cause `f` to be fully captured
Copy file name to clipboardExpand all lines: src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.rs
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ fn test_send_trait() {
13
13
let fptr = SendPointer(&mut f as*muti32);
14
14
thread::spawn(move || unsafe{
15
15
//~^ ERROR: `Send` closure trait implementation
16
+
//~| NOTE: in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0` does not implement `Send`
16
17
//~| NOTE: for more information, see
17
18
//~| HELP: add a dummy let to cause `fptr` to be fully captured
//~| NOTE: in Rust 2018, this closure would implement `Sync`, `Send` as `fptr` implements `Sync`, `Send`, but in Rust 2021, this closure will no longer implement `Sync`, `Send` as `fptr.0.0` does not implement `Sync`, `Send`
35
37
//~| NOTE: for more information, see
36
38
//~| HELP: add a dummy let to cause `fptr` to be fully captured
37
39
*fptr.0.0 = 20;
@@ -55,6 +57,7 @@ fn test_clone_trait() {
55
57
let f = U(S(String::from("Hello World")),T(0));
56
58
let c = || {
57
59
//~^ ERROR: `Clone` closure trait implementation, and drop order
60
+
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f.1` does not implement `Clone`
58
61
//~| NOTE: for more information, see
59
62
//~| HELP: add a dummy let to cause `f` to be fully captured
Copy file name to clipboardExpand all lines: src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,10 @@ error: changes to closure capture in Rust 2021 will affect `Send` closure trait
2
2
--> $DIR/auto_traits.rs:14:19
3
3
|
4
4
LL | thread::spawn(move || unsafe {
5
-
| ___________________^
5
+
| ^ - in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0` does not implement `Send`
error: changes to closure capture in Rust 2021 will affect `Sync`, `Send` closure trait implementation
32
-
--> $DIR/auto_traits.rs:33:19
35
+
--> $DIR/auto_traits.rs:34:19
33
36
|
34
37
LL | thread::spawn(move || unsafe {
35
-
| ___________________^
38
+
| ^ - in Rust 2018, this closure would implement `Sync`, `Send` as `fptr` implements `Sync`, `Send`, but in Rust 2021, this closure will no longer implement `Sync`, `Send` as `fptr.0.0` does not implement `Sync`, `Send`
error: changes to closure capture in Rust 2021 will affect `Clone` closure trait implementation, and drop order
57
-
--> $DIR/auto_traits.rs:56:13
63
+
--> $DIR/auto_traits.rs:58:13
58
64
|
59
65
LL | let c = || {
60
-
| _____________^
66
+
| ^ - in Rust 2018, this closure would implement `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f.1` does not implement `Clone`
//~| NOTE: in Rust 2018, this closure would implement `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe`
22
23
//~| NOTE: for more information, see
23
24
//~| HELP: add a dummy let to cause `f` to be fully captured
//~| NOTE: in Rust 2018, this closure would implement `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe`
22
23
//~| NOTE: for more information, see
23
24
//~| HELP: add a dummy let to cause `f` to be fully captured
Copy file name to clipboardExpand all lines: src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,10 @@ error: changes to closure capture in Rust 2021 will affect `UnwindSafe`, `RefUnw
2
2
--> $DIR/mir_calls_to_shims.rs:20:38
3
3
|
4
4
LL | let result = panic::catch_unwind(move || {
5
-
| ______________________________________^
5
+
| ^ - in Rust 2018, this closure would implement `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe`
6
+
| ______________________________________|
7
+
| |
8
+
LL | |
6
9
LL | |
7
10
LL | |
8
11
LL | |
@@ -24,8 +27,8 @@ LL | let result = panic::catch_unwind(move || { let _ = &f;
0 commit comments