Handle multi diagnostics

This commit is contained in:
Roxane 2021-07-08 17:04:58 -04:00
parent 59f634bc2d
commit ca44372957
7 changed files with 625 additions and 185 deletions

View file

@ -0,0 +1,138 @@
// run-rustfix
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE: the lint level is defined here
use std::thread;
struct S(String);
#[derive(Clone)]
struct T(i32);
struct U(S, T);
impl Clone for U {
fn clone(&self) -> Self {
U(S(String::from("Hello World")), T(0))
}
}
fn test_multi_issues() {
let f1 = U(S(String::from("foo")), T(0));
let f2 = U(S(String::from("bar")), T(0));
let c = || { let _ = (&f1, &f2);
//~^ ERROR: `Clone` trait implementation for closure, and drop order
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1`, `f2` to be fully captured
let _f_1 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_2 = f2.1;
//~^ NOTE: in Rust 2018, closure captures all of `f2`, but in Rust 2021, it only captures `f2.1`
};
let c_clone = c.clone();
c_clone();
}
//~^ NOTE: in Rust 2018, `f2` would be dropped here, but in Rust 2021, only `f2.1` would be dropped here alongside the closure
fn test_capturing_all_disjoint_fields_individually() {
let f1 = U(S(String::from("foo")), T(0));
let c = || { let _ = &f1;
//~^ ERROR: `Clone` trait implementation for closure
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_1 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_2 = f1.1;
};
let c_clone = c.clone();
c_clone();
}
struct U1(S, T, S);
impl Clone for U1 {
fn clone(&self) -> Self {
U1(S(String::from("foo")), T(0), S(String::from("bar")))
}
}
fn test_capturing_several_disjoint_fields_individually_1() {
let f1 = U1(S(String::from("foo")), T(0), S(String::from("bar")));
let c = || { let _ = &f1;
//~^ ERROR: `Clone` trait implementation for closure
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.2` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_2 = f1.2;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.2`
};
let c_clone = c.clone();
c_clone();
}
fn test_capturing_several_disjoint_fields_individually_2() {
let f1 = U1(S(String::from("foo")), T(0), S(String::from("bar")));
let c = || { let _ = &f1;
//~^ ERROR: `Clone` trait implementation for closure, and drop order
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_1 = f1.1;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.1`
};
let c_clone = c.clone();
c_clone();
}
//~^ NOTE: in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.1` would be dropped here alongside the closure
//~| NOTE: in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.0` would be dropped here alongside the closure
struct SendPointer(*mut i32);
unsafe impl Send for SendPointer {}
struct CustomInt(*mut i32);
struct SyncPointer(CustomInt);
unsafe impl Sync for SyncPointer {}
unsafe impl Send for CustomInt {}
fn test_multi_traits_issues() {
let mut f1 = 10;
let f1 = CustomInt(&mut f1 as *mut i32);
let fptr1 = SyncPointer(f1);
let mut f2 = 10;
let fptr2 = SendPointer(&mut f2 as *mut i32);
thread::spawn(move || { let _ = (&fptr1, &fptr2); unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation for closure
//~| NOTE: in Rust 2018, this closure would implement `Sync`, `Send` as `fptr1` implements `Sync`, `Send`, but in Rust 2021, this closure would no longer implement `Sync`, `Send` as `fptr1.0.0` does not implement `Sync`, `Send`
//~| NOTE: in Rust 2018, this closure would implement `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr2.0` does not implement `Send`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr1`, `fptr2` to be fully captured
*fptr1.0.0 = 20;
//~^ NOTE: in Rust 2018, closure captures all of `fptr1`, but in Rust 2021, it only captures `fptr1.0.0`
*fptr2.0 = 20;
//~^ NOTE: in Rust 2018, closure captures all of `fptr2`, but in Rust 2021, it only captures `fptr2.0`
} });
}
fn main() {
test_multi_issues();
test_capturing_all_disjoint_fields_individually();
test_capturing_several_disjoint_fields_individually_1();
test_capturing_several_disjoint_fields_individually_2();
test_multi_traits_issues();
}

View file

@ -0,0 +1,138 @@
// run-rustfix
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE: the lint level is defined here
use std::thread;
struct S(String);
#[derive(Clone)]
struct T(i32);
struct U(S, T);
impl Clone for U {
fn clone(&self) -> Self {
U(S(String::from("Hello World")), T(0))
}
}
fn test_multi_issues() {
let f1 = U(S(String::from("foo")), T(0));
let f2 = U(S(String::from("bar")), T(0));
let c = || {
//~^ ERROR: `Clone` trait implementation for closure, and drop order
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1`, `f2` to be fully captured
let _f_1 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_2 = f2.1;
//~^ NOTE: in Rust 2018, closure captures all of `f2`, but in Rust 2021, it only captures `f2.1`
};
let c_clone = c.clone();
c_clone();
}
//~^ NOTE: in Rust 2018, `f2` would be dropped here, but in Rust 2021, only `f2.1` would be dropped here alongside the closure
fn test_capturing_all_disjoint_fields_individually() {
let f1 = U(S(String::from("foo")), T(0));
let c = || {
//~^ ERROR: `Clone` trait implementation for closure
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_1 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_2 = f1.1;
};
let c_clone = c.clone();
c_clone();
}
struct U1(S, T, S);
impl Clone for U1 {
fn clone(&self) -> Self {
U1(S(String::from("foo")), T(0), S(String::from("bar")))
}
}
fn test_capturing_several_disjoint_fields_individually_1() {
let f1 = U1(S(String::from("foo")), T(0), S(String::from("bar")));
let c = || {
//~^ ERROR: `Clone` trait implementation for closure
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.2` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_2 = f1.2;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.2`
};
let c_clone = c.clone();
c_clone();
}
fn test_capturing_several_disjoint_fields_individually_2() {
let f1 = U1(S(String::from("foo")), T(0), S(String::from("bar")));
let c = || {
//~^ ERROR: `Clone` trait implementation for closure, and drop order
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
let _f_1 = f1.1;
//~^ NOTE: in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.1`
};
let c_clone = c.clone();
c_clone();
}
//~^ NOTE: in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.1` would be dropped here alongside the closure
//~| NOTE: in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.0` would be dropped here alongside the closure
struct SendPointer(*mut i32);
unsafe impl Send for SendPointer {}
struct CustomInt(*mut i32);
struct SyncPointer(CustomInt);
unsafe impl Sync for SyncPointer {}
unsafe impl Send for CustomInt {}
fn test_multi_traits_issues() {
let mut f1 = 10;
let f1 = CustomInt(&mut f1 as *mut i32);
let fptr1 = SyncPointer(f1);
let mut f2 = 10;
let fptr2 = SendPointer(&mut f2 as *mut i32);
thread::spawn(move || unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation for closure
//~| NOTE: in Rust 2018, this closure would implement `Sync`, `Send` as `fptr1` implements `Sync`, `Send`, but in Rust 2021, this closure would no longer implement `Sync`, `Send` as `fptr1.0.0` does not implement `Sync`, `Send`
//~| NOTE: in Rust 2018, this closure would implement `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr2.0` does not implement `Send`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr1`, `fptr2` to be fully captured
*fptr1.0.0 = 20;
//~^ NOTE: in Rust 2018, closure captures all of `fptr1`, but in Rust 2021, it only captures `fptr1.0.0`
*fptr2.0 = 20;
//~^ NOTE: in Rust 2018, closure captures all of `fptr2`, but in Rust 2021, it only captures `fptr2.0`
});
}
fn main() {
test_multi_issues();
test_capturing_all_disjoint_fields_individually();
test_capturing_several_disjoint_fields_individually_1();
test_capturing_several_disjoint_fields_individually_2();
test_multi_traits_issues();
}

View file

@ -0,0 +1,134 @@
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure, and drop order
--> $DIR/multi_diagnostics.rs:23:13
|
LL | let c = || {
| ^^ in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
...
LL | let _f_1 = f1.0;
| ---- in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
LL |
LL | let _f_2 = f2.1;
| ---- in Rust 2018, closure captures all of `f2`, but in Rust 2021, it only captures `f2.1`
...
LL | }
| - in Rust 2018, `f2` would be dropped here, but in Rust 2021, only `f2.1` would be dropped here alongside the closure
|
note: the lint level is defined here
--> $DIR/multi_diagnostics.rs:2:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f1`, `f2` to be fully captured
|
LL | let c = || { let _ = (&f1, &f2);
LL |
LL |
LL |
LL |
LL | let _f_1 = f1.0;
...
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure
--> $DIR/multi_diagnostics.rs:42:13
|
LL | let c = || {
| ^^ in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
...
LL | let _f_1 = f1.0;
| ---- in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f1` to be fully captured
|
LL | let c = || { let _ = &f1;
LL |
LL |
LL |
LL |
LL | let _f_1 = f1.0;
...
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure
--> $DIR/multi_diagnostics.rs:67:13
|
LL | let c = || {
| ^^
| |
| in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
| in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.2` does not implement `Clone`
...
LL | let _f_0 = f1.0;
| ---- in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
LL |
LL | let _f_2 = f1.2;
| ---- in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.2`
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f1` to be fully captured
|
LL | let c = || { let _ = &f1;
LL |
LL |
LL |
LL |
LL |
...
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure, and drop order
--> $DIR/multi_diagnostics.rs:86:13
|
LL | let c = || {
| ^^ in Rust 2018, this closure would implement `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f1.0` does not implement `Clone`
...
LL | let _f_0 = f1.0;
| ---- in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.0`
LL |
LL | let _f_1 = f1.1;
| ---- in Rust 2018, closure captures all of `f1`, but in Rust 2021, it only captures `f1.1`
...
LL | }
| -
| |
| in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.0` would be dropped here alongside the closure
| in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.1` would be dropped here alongside the closure
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f1` to be fully captured
|
LL | let c = || { let _ = &f1;
LL |
LL |
LL |
LL |
LL | let _f_0 = f1.0;
...
error: changes to closure capture in Rust 2021 will affect `Sync`, `Send` trait implementation for closure
--> $DIR/multi_diagnostics.rs:119:19
|
LL | thread::spawn(move || unsafe {
| ^^^^^^^^^^^^^^
| |
| in Rust 2018, this closure would implement `Sync`, `Send` as `fptr1` implements `Sync`, `Send`, but in Rust 2021, this closure would no longer implement `Sync`, `Send` as `fptr1.0.0` does not implement `Sync`, `Send`
| in Rust 2018, this closure would implement `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr2.0` does not implement `Send`
...
LL | *fptr1.0.0 = 20;
| ---------- in Rust 2018, closure captures all of `fptr1`, but in Rust 2021, it only captures `fptr1.0.0`
LL |
LL | *fptr2.0 = 20;
| -------- in Rust 2018, closure captures all of `fptr2`, but in Rust 2021, it only captures `fptr2.0`
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `fptr1`, `fptr2` to be fully captured
|
LL | thread::spawn(move || { let _ = (&fptr1, &fptr2); unsafe {
LL |
LL |
LL |
LL |
LL |
...
error: aborting due to 5 previous errors

View file

@ -1,6 +1,7 @@
// run-rustfix
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE: the lint level is defined here
#[derive(Debug)]
struct Foo(i32);
@ -18,13 +19,16 @@ fn test_precise_analysis_drop_paths_not_captured_by_move() {
let c = || { let _ = &t;
//~^ ERROR: drop order
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `t` to be fully captured
let _t = t.0;
//~^ NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0`
let _t = &t.1;
};
c();
}
//~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.0` would be dropped here alongside the closure
struct S;
impl Drop for S {
@ -40,14 +44,22 @@ fn test_precise_analysis_long_path_missing() {
let c = || { let _ = &u;
//~^ ERROR: drop order
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `u` to be fully captured
let _x = u.0.0;
//~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.0`
let _x = u.0.1;
//~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.1`
let _x = u.1.0;
//~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.1.0`
};
c();
}
//~^ NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.0` would be dropped here alongside the closure
//~| NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1` would be dropped here alongside the closure
//~| NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.1.0` would be dropped here alongside the closure
fn main() {
test_precise_analysis_drop_paths_not_captured_by_move();

View file

@ -1,6 +1,7 @@
// run-rustfix
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE: the lint level is defined here
#[derive(Debug)]
struct Foo(i32);
@ -18,13 +19,16 @@ fn test_precise_analysis_drop_paths_not_captured_by_move() {
let c = || {
//~^ ERROR: drop order
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `t` to be fully captured
let _t = t.0;
//~^ NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0`
let _t = &t.1;
};
c();
}
//~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.0` would be dropped here alongside the closure
struct S;
impl Drop for S {
@ -40,14 +44,22 @@ fn test_precise_analysis_long_path_missing() {
let c = || {
//~^ ERROR: drop order
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `u` to be fully captured
let _x = u.0.0;
//~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.0`
let _x = u.0.1;
//~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.1`
let _x = u.1.0;
//~^ NOTE: in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.1.0`
};
c();
}
//~^ NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.0` would be dropped here alongside the closure
//~| NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1` would be dropped here alongside the closure
//~| NOTE: in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.1.0` would be dropped here alongside the closure
fn main() {
test_precise_analysis_drop_paths_not_captured_by_move();

View file

@ -1,5 +1,5 @@
error: changes to closure capture in Rust 2021 will affect drop order
--> $DIR/precise.rs:19:13
--> $DIR/precise.rs:20:13
|
LL | let c = || {
| ^^
@ -21,26 +21,32 @@ help: add a dummy let to cause `t` to be fully captured
LL | let c = || { let _ = &t;
LL |
LL |
LL |
LL | let _t = t.0;
LL | let _t = &t.1;
LL | };
|
LL |
...
error: changes to closure capture in Rust 2021 will affect drop order
--> $DIR/precise.rs:41:13
--> $DIR/precise.rs:45:13
|
LL | let c = || {
| ^^
...
LL | let _x = u.0.0;
| ----- in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.0`
LL |
LL | let _x = u.0.1;
| ----- in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.0.1`
LL |
LL | let _x = u.1.0;
| ----- in Rust 2018, closure captures all of `u`, but in Rust 2021, it only captures `u.1.0`
...
LL | }
| - in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1`, `u.0.0`, `u.1.0` would be dropped here alongside the closure
| -
| |
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1` would be dropped here alongside the closure
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.0` would be dropped here alongside the closure
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.1.0` would be dropped here alongside the closure
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `u` to be fully captured
@ -48,9 +54,9 @@ help: add a dummy let to cause `u` to be fully captured
LL | let c = || { let _ = &u;
LL |
LL |
LL |
LL | let _x = u.0.0;
LL | let _x = u.0.1;
LL | let _x = u.1.0;
LL |
...
error: aborting due to 2 previous errors