Skip to content

Rollup of 11 pull requests #81553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77a9e3e
combine: stop eagerly evaluating consts
lcnr Jan 24, 2021
a398994
Account for existing `_` field pattern when suggesting `..`
estebank Jan 27, 2021
063b427
Bump rustfmt version
Mark-Simulacrum Jan 9, 2021
ada714d
Optimize udiv_1e19() function
Kogia-sima Jan 28, 2021
d1727ed
Add lint for 2229 migrations
arora-aman Dec 28, 2020
2c651eb
Process mentioned upvars for analysis first pass after ExprUseVisitor
arora-aman Nov 21, 2020
36352d2
Migrations first pass
arora-aman Dec 15, 2020
d30a5bf
Tests for 2229 lint
arora-aman Dec 30, 2020
9ac023d
Mark the lint doc as compile_fail
arora-aman Jan 3, 2021
f106e18
PR fixup
arora-aman Jan 19, 2021
11abaa1
New migration
arora-aman Jan 26, 2021
b421cd5
Restrict precision of captures with `capture_disjoint_fields` set
arora-aman Dec 4, 2020
3488082
Compute mutability of closure captures
arora-aman Dec 2, 2020
1373f98
Test cases for handling mutable references
arora-aman Dec 13, 2020
0897db5
Test for restricting capture precision
arora-aman Dec 14, 2020
604cbdc
Fix unused 'mut' warning for capture's root variable
arora-aman Dec 16, 2020
c748f32
Fix incorrect use mut diagnostics
arora-aman Dec 13, 2020
ffd5327
Add fixme for precise path diagnostics
arora-aman Jan 12, 2021
fadf03e
Fix typos
arora-aman Jan 29, 2021
0f4bab2
Fixme for closure origin when reborrow is implemented
arora-aman Jan 29, 2021
56c2736
Replace predecessor with range in collections documentation
LunaBorowska Jan 30, 2021
755be93
Rollup merge of #80092 - sexxi-goose:restrict_precision, r=nikomatsakis
m-ou-se Jan 30, 2021
16a4bb2
Rollup merge of #80629 - sexxi-goose:migrations_1, r=nikomatsakis
m-ou-se Jan 30, 2021
813739a
Rollup merge of #80843 - Mark-Simulacrum:fmt-bump, r=petrochenkov
m-ou-se Jan 30, 2021
1d117ab
Rollup merge of #81351 - lcnr:big-money-big-prices, r=oli-obk
m-ou-se Jan 30, 2021
ec066b3
Rollup merge of #81422 - estebank:dotdot_sugg, r=davidtwco
m-ou-se Jan 30, 2021
e3d9523
Rollup merge of #81484 - Kogia-sima:perf/optimize-udiv_1e19, r=nagisa
m-ou-se Jan 30, 2021
0330456
Rollup merge of #81550 - xfix:replace-mention-of-predecessor, r=jonas…
m-ou-se Jan 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests for 2229 lint
  • Loading branch information
arora-aman committed Jan 29, 2021
commit d30a5bf3282486f0e10c91c44dbb2de61383164c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#![deny(disjoint_capture_drop_reorder)]
//~^ NOTE: the lint level is defined here

// Test cases for types that implement a insignificant drop (stlib defined)

// `t` needs Drop because one of its elements needs drop,
// therefore precise capture might affect drop ordering
fn test1_all_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let t2 = (String::new(), String::new());

let c = || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t, t1, t2) = (t, t1, t2);
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2.0;
};

c();
}

// String implements drop and therefore should be migrated.
// But in this test cases, `t2` is completely captured and when it is dropped won't be affected
fn test2_only_precise_paths_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let t2 = (String::new(), String::new());

let c = || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t, t1) = (t, t1);
let _t = t.0;
let _t1 = t1.0;
let _t2 = t2;
};

c();
}

// If a variable would've not been captured by value then it would've not been
// dropped with the closure and therefore doesn't need migration.
fn test3_only_by_value_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let c = || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t) = (t);
let _t = t.0;
println!("{}", t1.1);
};

c();
}

// Copy types get copied into the closure instead of move. Therefore we don't need to
// migrate then as their drop order isn't tied to the closure.
fn test4_only_non_copy_types_need_migration() {
let t = (String::new(), String::new());

// `t1` is Copy because all of its elements are Copy
let t1 = (0i32, 0i32);

let c = || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t) = (t);
let _t = t.0;
let _t1 = t1.0;
};

c();
}

fn test5_only_drop_types_need_migration() {
struct S(i32, i32);

let t = (String::new(), String::new());

// `s` doesn't implement Drop or any elements within it, and doesn't need migration
let s = S(0i32, 0i32);

let c = || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t) = (t);
let _t = t.0;
let _s = s.0;
};

c();
}

// Since we are using a move closure here, both `t` and `t1` get moved
// even though they are being used by ref inside the closure.
fn test6_move_closures_non_copy_types_might_need_migration() {
let t = (String::new(), String::new());
let t1 = (String::new(), String::new());
let c = move || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t1, t) = (t1, t);
println!("{} {}", t1.1, t.1);
};

c();
}

// Test migration analysis in case of Drop + Non Drop aggregates.
// Note we need migration here only because the non-copy (because Drop type) is captured,
// otherwise we won't need to, since we can get away with just by ref capture in that case.
fn test7_drop_non_drop_aggregate_need_migration() {
let t = (String::new(), 0i32);

let c = || {
//~^ERROR: Drop order affected for closure because of `capture_disjoint_fields`
//~| NOTE: let (t) = (t);
let _t = t.0;
};

c();
}

fn main() {
test1_all_need_migration();
test2_only_precise_paths_need_migration();
test3_only_by_value_need_migration();
test4_only_non_copy_types_need_migration();
test5_only_drop_types_need_migration();
test6_move_closures_non_copy_types_might_need_migration();
test7_drop_non_drop_aggregate_need_migration();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:13:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | let _t1 = t1.0;
LL | | let _t2 = t2.0;
LL | | };
| |_____^
|
note: the lint level is defined here
--> $DIR/insignificant_drop.rs:1:9
|
LL | #![deny(disjoint_capture_drop_reorder)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: let (t, t1, t2) = (t, t1, t2);

error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:31:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | let _t1 = t1.0;
LL | | let _t2 = t2;
LL | | };
| |_____^
|
= note: let (t, t1) = (t, t1);

error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:47:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | println!("{}", t1.1);
LL | | };
| |_____^
|
= note: let (t) = (t);

error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:65:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | let _t1 = t1.0;
LL | | };
| |_____^
|
= note: let (t) = (t);

error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:83:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | let _s = s.0;
LL | | };
| |_____^
|
= note: let (t) = (t);

error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:98:13
|
LL | let c = move || {
| _____________^
LL | |
LL | |
LL | | println!("{} {}", t1.1, t.1);
LL | | };
| |_____^
|
= note: let (t1, t) = (t1, t);

error: Drop order affected for closure because of `capture_disjoint_fields`
--> $DIR/insignificant_drop.rs:113:13
|
LL | let c = || {
| _____________^
LL | |
LL | |
LL | | let _t = t.0;
LL | | };
| |_____^
|
= note: let (t) = (t);

error: aborting due to 7 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// run-pass

// Set of test cases that don't need migrations

#![deny(disjoint_capture_drop_reorder)]


// Copy types as copied by the closure instead of being moved into the closure
// Therefore their drop order isn't tied to the closure and won't be requiring any
// migrations.
fn test1_only_copy_types() {
let t = (0i32, 0i32);

let c = || {
let _t = t.0;
};

c();
}

// Same as test1 but using a move closure
fn test2_only_copy_types_move_closure() {
let t = (0i32, 0i32);

let c = move || {
println!("{}", t.0);
};

c();
}

// Don't need to migrate if captured by ref
fn test3_only_copy_types_move_closure() {
let t = (String::new(), String::new());

let c = || {
println!("{}", t.0);
};

c();
}

// Test migration analysis in case of Insignificant Drop + Non Drop aggregates.
// Note in this test the closure captures a non Drop type and therefore the variable
// is only captured by ref.
fn test4_insignificant_drop_non_drop_aggregate() {
let t = (String::new(), 0i32);

let c = || {
let _t = t.1;
};

c();
}


struct Foo(i32);
impl Drop for Foo {
fn drop(&mut self) {
println!("{:?} dropped", self.0);
}
}

// Test migration analysis in case of Significant Drop + Non Drop aggregates.
// Note in this test the closure captures a non Drop type and therefore the variable
// is only captured by ref.
fn test5_significant_drop_non_drop_aggregate() {
let t = (Foo(0), 0i32);

let c = || {
let _t = t.1;
};

c();
}

fn main() {
test1_only_copy_types();
test2_only_copy_types_move_closure();
test3_only_copy_types_move_closure();
test4_insignificant_drop_non_drop_aggregate();
test5_significant_drop_non_drop_aggregate();

}
Loading