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
let cause_span = self.tcx.hir().span(*capture_expr_id);
756
+
diagnostics_builder.span_label(cause_span,format!("in Rust 2018, this closure captures all of `{}`, but in Rust 2021, it will only capture `{}`",
757
+
self.tcx.hir().name(*var_hir_id),
758
+
captured_name,
759
+
));
760
+
}
761
+
_ => {}
729
762
}
730
763
731
764
// Add a label pointing to where a captured variable affected by drop order
732
765
// is dropped
733
-
ifreasons.contains("drop order"){
766
+
iflint_note.reason.drop_order{
734
767
let drop_location_span = drop_location_span(self.tcx,&closure_hir_id);
735
768
736
-
diagnostics_builder.span_label(drop_location_span,format!("in Rust 2018, `{}` is dropped here, but in Rust 2021, only `{}` will be dropped here as part of the closure",
diagnostics_builder.span_label(drop_location_span,format!("in Rust 2018, `{}` is dropped here, but in Rust 2021, only `{}` will be dropped here as part of the closure",
772
+
self.tcx.hir().name(*var_hir_id),
773
+
captured_name,
774
+
));
775
+
}
776
+
}
740
777
}
741
778
742
779
// Add a label explaining why a closure no longer implements a trait
743
-
if reasons.contains("trait implementation"){
744
-
let missing_trait = &reasons[..reasons.find("trait implementation").unwrap() - 1];
745
-
746
-
diagnostics_builder.span_label(closure_head_span,format!("in Rust 2018, this closure implements {} as `{}` implements {}, but in Rust 2021, this closure will no longer implement {} as `{}` does not implement {}",
diagnostics_builder.span_label(closure_head_span,format!("in Rust 2018, this closure implements {missing_trait} as `{x}` implements {missing_trait}, but in Rust 2021, this closure will no longer implement {missing_trait} as `{p}` does not implement {missing_trait}",
Copy file name to clipboardExpand all lines: src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ fn test_send_trait() {
20
20
let mut f = 10;
21
21
let fptr = SendPointer(&mut f as *mut i32);
22
22
thread::spawn(move || { let _ = &fptr; unsafe {
23
-
//~^ ERROR: `Send` trait implementation for closure
23
+
//~^ ERROR: changes to closure capture
24
24
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0` does not implement `Send`
25
25
//~| NOTE: for more information, see
26
26
//~| HELP: add a dummy let to cause `fptr` to be fully captured
@@ -40,8 +40,9 @@ fn test_sync_trait() {
40
40
let f = CustomInt(&mut f as *mut i32);
41
41
let fptr = SyncPointer(f);
42
42
thread::spawn(move || { let _ = &fptr; unsafe {
43
-
//~^ ERROR: `Sync`, `Send` trait implementation for closure
44
-
//~| NOTE: in Rust 2018, this closure implements `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`
43
+
//~^ ERROR: changes to closure capture
44
+
//~| NOTE: in Rust 2018, this closure implements `Sync` as `fptr` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` as `fptr.0.0` does not implement `Sync`
45
+
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0.0` does not implement `Send`
45
46
//~| NOTE: for more information, see
46
47
//~| HELP: add a dummy let to cause `fptr` to be fully captured
47
48
*fptr.0.0 = 20;
@@ -65,7 +66,7 @@ fn test_clone_trait() {
65
66
let f = U(S(Foo(0)), T(0));
66
67
let c = || {
67
68
let _ = &f;
68
-
//~^ ERROR: `Clone` trait implementation for closure and drop order
69
+
//~^ ERROR: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
69
70
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f.1` does not implement `Clone`
70
71
//~| NOTE: for more information, see
71
72
//~| 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
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ fn test_send_trait() {
20
20
letmut f = 10;
21
21
let fptr = SendPointer(&mut f as*muti32);
22
22
thread::spawn(move || unsafe{
23
-
//~^ ERROR: `Send` trait implementation for closure
23
+
//~^ ERROR: changes to closure capture
24
24
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0` does not implement `Send`
25
25
//~| NOTE: for more information, see
26
26
//~| HELP: add a dummy let to cause `fptr` to be fully captured
@@ -40,8 +40,9 @@ fn test_sync_trait() {
40
40
let f = CustomInt(&mut f as*muti32);
41
41
let fptr = SyncPointer(f);
42
42
thread::spawn(move || unsafe{
43
-
//~^ ERROR: `Sync`, `Send` trait implementation for closure
44
-
//~| NOTE: in Rust 2018, this closure implements `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`
43
+
//~^ ERROR: changes to closure capture
44
+
//~| NOTE: in Rust 2018, this closure implements `Sync` as `fptr` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` as `fptr.0.0` does not implement `Sync`
45
+
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0.0` does not implement `Send`
45
46
//~| NOTE: for more information, see
46
47
//~| HELP: add a dummy let to cause `fptr` to be fully captured
47
48
*fptr.0.0 = 20;
@@ -64,7 +65,7 @@ impl Clone for U {
64
65
fntest_clone_trait(){
65
66
let f = U(S(Foo(0)),T(0));
66
67
let c = || {
67
-
//~^ ERROR: `Clone` trait implementation for closure and drop order
68
+
//~^ ERROR: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
68
69
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f.1` does not implement `Clone`
69
70
//~| NOTE: for more information, see
70
71
//~| HELP: add a dummy let to cause `f` to be fully captured
0 commit comments