Add additional migrations to handle auto-traits and clone traits

Combine all 2229 migrations under one flag name
This commit is contained in:
Roxane 2021-04-08 19:09:08 -04:00
parent 109248a4eb
commit 9afea614bf
27 changed files with 666 additions and 83 deletions

View file

@ -0,0 +1,67 @@
// run-rustfix
#![deny(disjoint_capture_migration)]
use std::thread;
/* Test Send Trait */
struct SendPointer (*mut i32);
unsafe impl Send for SendPointer {}
fn test_send_trait() {
let mut f = 10;
let fptr = SendPointer(&mut f as *mut i32);
thread::spawn(move || { let _ = &fptr; unsafe {
//~^ ERROR: `Send` trait implementation affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0 = 20;
} });
}
/* Test Sync Trait */
struct CustomInt (*mut i32);
struct SyncPointer (CustomInt);
unsafe impl Sync for SyncPointer {}
unsafe impl Send for CustomInt {}
fn test_sync_trait() {
let mut f = 10;
let f = CustomInt(&mut f as *mut i32);
let fptr = SyncPointer(f);
thread::spawn(move || { let _ = &fptr; unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0.0 = 20;
} });
}
/* Test Clone Trait */
struct S(String);
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_clone_trait() {
let f = U(S(String::from("Hello World")), T(0));
let c = || { let _ = &f;
//~^ ERROR: `Clone` trait implementation, and drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `f` to be fully captured
let f_1 = f.1;
println!("{:?}", f_1.0);
};
let c_clone = c.clone();
c_clone();
}
fn main() {
test_send_trait();
test_sync_trait();
test_clone_trait();
}

View file

@ -0,0 +1,67 @@
// run-rustfix
#![deny(disjoint_capture_migration)]
use std::thread;
/* Test Send Trait */
struct SendPointer (*mut i32);
unsafe impl Send for SendPointer {}
fn test_send_trait() {
let mut f = 10;
let fptr = SendPointer(&mut f as *mut i32);
thread::spawn(move || unsafe {
//~^ ERROR: `Send` trait implementation affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0 = 20;
});
}
/* Test Sync Trait */
struct CustomInt (*mut i32);
struct SyncPointer (CustomInt);
unsafe impl Sync for SyncPointer {}
unsafe impl Send for CustomInt {}
fn test_sync_trait() {
let mut f = 10;
let f = CustomInt(&mut f as *mut i32);
let fptr = SyncPointer(f);
thread::spawn(move || unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0.0 = 20;
});
}
/* Test Clone Trait */
struct S(String);
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_clone_trait() {
let f = U(S(String::from("Hello World")), T(0));
let c = || {
//~^ ERROR: `Clone` trait implementation, and drop order affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `f` to be fully captured
let f_1 = f.1;
println!("{:?}", f_1.0);
};
let c_clone = c.clone();
c_clone();
}
fn main() {
test_send_trait();
test_sync_trait();
test_clone_trait();
}

View file

@ -0,0 +1,69 @@
error: `Send` trait implementation affected for closure because of `capture_disjoint_fields`
--> $DIR/auto_traits.rs:13:19
|
LL | thread::spawn(move || unsafe {
| ___________________^
LL | |
LL | |
LL | | *fptr.0 = 20;
LL | | });
| |_____^
|
note: the lint level is defined here
--> $DIR/auto_traits.rs:2:9
|
LL | #![deny(disjoint_capture_migration)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a dummy let to cause `fptr` to be fully captured
|
LL | thread::spawn(move || { let _ = &fptr; unsafe {
LL |
LL |
LL | *fptr.0 = 20;
LL | } });
|
error: `Sync`, `Send` trait implementation affected for closure because of `capture_disjoint_fields`
--> $DIR/auto_traits.rs:30:19
|
LL | thread::spawn(move || unsafe {
| ___________________^
LL | |
LL | |
LL | | *fptr.0.0 = 20;
LL | | });
| |_____^
|
help: add a dummy let to cause `fptr` to be fully captured
|
LL | thread::spawn(move || { let _ = &fptr; unsafe {
LL |
LL |
LL | *fptr.0.0 = 20;
LL | } });
|
error: `Clone` trait implementation, and drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/auto_traits.rs:51:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let f_1 = f.1;
LL | | println!("{:?}", f_1.0);
LL | | };
| |_____^
|
help: add a dummy let to cause `f` to be fully captured
|
LL | let c = || { let _ = &f;
LL |
LL |
LL | let f_1 = f.1;
LL | println!("{:?}", f_1.0);
LL | };
|
error: aborting due to 3 previous errors

View file

@ -1,6 +1,6 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
//~^ NOTE: the lint level is defined here
// Test cases for types that implement a insignificant drop (stlib defined)

View file

@ -1,6 +1,6 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
//~^ NOTE: the lint level is defined here
// Test cases for types that implement a insignificant drop (stlib defined)

View file

@ -14,8 +14,8 @@ LL | | };
note: the lint level is defined here
--> $DIR/insignificant_drop.rs:3:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #![deny(disjoint_capture_migration)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a dummy let to cause `t`, `t1`, `t2` to be fully captured
|
LL | let c = || { let _ = (&t, &t1, &t2);

View file

@ -1,6 +1,6 @@
// run-pass
#![warn(disjoint_capture_drop_reorder)]
#![warn(disjoint_capture_migration)]
fn main() {
if let a = "" {

View file

@ -1,5 +1,5 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
//~^ NOTE: the lint level is defined here
// Test the two possible cases for automated migartion using rustfix

View file

@ -1,5 +1,5 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
//~^ NOTE: the lint level is defined here
// Test the two possible cases for automated migartion using rustfix

View file

@ -12,8 +12,8 @@ LL | | };
note: the lint level is defined here
--> $DIR/migrations_rustfix.rs:2:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #![deny(disjoint_capture_migration)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a dummy let to cause `t` to be fully captured
|
LL | let c = || { let _ = &t;

View file

@ -0,0 +1,39 @@
// run-rustfix
#![deny(disjoint_capture_migration)]
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(fn_traits)]
#![feature(never_type)]
use std::panic;
fn foo_diverges() -> ! { panic!() }
fn assert_panics<F>(f: F) where F: FnOnce() {
let f = panic::AssertUnwindSafe(f);
let result = panic::catch_unwind(move || { let _ = &f;
//~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `f` to be fully captured
f.0()
});
if let Ok(..) = result {
panic!("diverging function returned");
}
}
fn test_fn_ptr_panic<T>(mut t: T)
where T: Fn() -> !
{
let as_fn = <T as Fn<()>>::call;
assert_panics(|| as_fn(&t, ()));
let as_fn_mut = <T as FnMut<()>>::call_mut;
assert_panics(|| as_fn_mut(&mut t, ()));
let as_fn_once = <T as FnOnce<()>>::call_once;
assert_panics(|| as_fn_once(t, ()));
}
fn main() {
test_fn_ptr_panic(foo_diverges);
test_fn_ptr_panic(foo_diverges as fn() -> !);
}

View file

@ -0,0 +1,39 @@
// run-rustfix
#![deny(disjoint_capture_migration)]
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(fn_traits)]
#![feature(never_type)]
use std::panic;
fn foo_diverges() -> ! { panic!() }
fn assert_panics<F>(f: F) where F: FnOnce() {
let f = panic::AssertUnwindSafe(f);
let result = panic::catch_unwind(move || {
//~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation affected for closure because of `capture_disjoint_fields`
//~| HELP: add a dummy let to cause `f` to be fully captured
f.0()
});
if let Ok(..) = result {
panic!("diverging function returned");
}
}
fn test_fn_ptr_panic<T>(mut t: T)
where T: Fn() -> !
{
let as_fn = <T as Fn<()>>::call;
assert_panics(|| as_fn(&t, ()));
let as_fn_mut = <T as FnMut<()>>::call_mut;
assert_panics(|| as_fn_mut(&mut t, ()));
let as_fn_once = <T as FnOnce<()>>::call_once;
assert_panics(|| as_fn_once(t, ()));
}
fn main() {
test_fn_ptr_panic(foo_diverges);
test_fn_ptr_panic(foo_diverges as fn() -> !);
}

View file

@ -0,0 +1,27 @@
error: `UnwindSafe`, `RefUnwindSafe` trait implementation affected for closure because of `capture_disjoint_fields`
--> $DIR/mir_calls_to_shims.rs:15:38
|
LL | let result = panic::catch_unwind(move || {
| ______________________________________^
LL | |
LL | |
LL | | f.0()
LL | | });
| |_____^
|
note: the lint level is defined here
--> $DIR/mir_calls_to_shims.rs:3:9
|
LL | #![deny(disjoint_capture_migration)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a dummy let to cause `f` to be fully captured
|
LL | let result = panic::catch_unwind(move || { let _ = &f;
LL |
LL |
LL | f.0()
LL | });
|
error: aborting due to previous error

View file

@ -2,7 +2,7 @@
// Set of test cases that don't need migrations
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
// Copy types as copied by the closure instead of being moved into the closure

View file

@ -1,6 +1,6 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
#[derive(Debug)]
struct Foo(i32);

View file

@ -1,6 +1,6 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
#[derive(Debug)]
struct Foo(i32);

View file

@ -13,8 +13,8 @@ LL | | };
note: the lint level is defined here
--> $DIR/precise.rs:3:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #![deny(disjoint_capture_migration)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a dummy let to cause `t` to be fully captured
|
LL | let c = || { let _ = &t;

View file

@ -1,6 +1,6 @@
// run-pass
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
#[derive(Debug)]
struct Foo(i32);

View file

@ -1,5 +1,5 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
//~^ NOTE: the lint level is defined here
// Test cases for types that implement a significant drop (user defined)

View file

@ -1,5 +1,5 @@
// run-rustfix
#![deny(disjoint_capture_drop_reorder)]
#![deny(disjoint_capture_migration)]
//~^ NOTE: the lint level is defined here
// Test cases for types that implement a significant drop (user defined)

View file

@ -14,8 +14,8 @@ LL | | };
note: the lint level is defined here
--> $DIR/significant_drop.rs:2:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #![deny(disjoint_capture_migration)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a dummy let to cause `t`, `t1`, `t2` to be fully captured
|
LL | let c = || { let _ = (&t, &t1, &t2);