Skip to content

Improves migrations lint for RFC2229 #86965

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

Merged
merged 9 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
10 changes: 5 additions & 5 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

if auto_trait_reasons.len() > 0 && drop_reason {
reasons = format!("{}, and ", reasons);
reasons = format!("{} and ", reasons);
}

if drop_reason {
Expand Down Expand Up @@ -886,12 +886,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// Combine all the captures responsible for needing migrations into one HashSet
let mut capture_disagnostic = drop_reorder_diagnostic.clone();
let mut capture_diagnostic = drop_reorder_diagnostic.clone();
for key in auto_trait_diagnostic.keys() {
capture_disagnostic.insert(key.clone());
capture_diagnostic.insert(key.clone());
}

for captured_info in capture_disagnostic.iter() {
for captured_info in capture_diagnostic.iter() {
// Get the auto trait reasons of why migration is needed because of that capture, if there are any
let capture_trait_reasons =
if let Some(reasons) = auto_trait_diagnostic.get(captured_info) {
Expand All @@ -917,7 +917,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
));
}

if capture_disagnostic.len() > 0 {
if capture_diagnostic.len() > 0 {
need_migrations.push((var_hir_id, responsible_captured_hir_ids));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Clone for U {
fn test_clone_trait() {
let f = U(S(String::from("Hello World")), T(0));
let c = || { let _ = &f;
//~^ ERROR: `Clone` trait implementation for closure, and drop order
//~^ ERROR: `Clone` trait implementation for closure and drop order
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f.1` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f` to be fully captured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Clone for U {
fn test_clone_trait() {
let f = U(S(String::from("Hello World")), T(0));
let c = || {
//~^ ERROR: `Clone` trait implementation for closure, and drop order
//~^ ERROR: `Clone` trait implementation for closure and drop order
//~| NOTE: in Rust 2018, this closure would implement `Clone` as `f` implements `Clone`, but in Rust 2021, this closure would no longer implement `Clone` as `f.1` does not implement `Clone`
//~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f` to be fully captured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LL |
LL | *fptr.0.0 = 20;
...

error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure, and drop order
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure and drop order
--> $DIR/auto_traits.rs:58:13
|
LL | let c = || {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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
//~^ 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
Expand Down Expand Up @@ -84,7 +84,7 @@ fn test_capturing_several_disjoint_fields_individually_1() {
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
//~^ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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
//~^ 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
Expand Down Expand Up @@ -84,7 +84,7 @@ fn test_capturing_several_disjoint_fields_individually_1() {
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
//~^ 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure, and drop order
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 = || {
Expand Down Expand Up @@ -75,7 +75,7 @@ LL |
LL |
...

error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure, and drop order
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 = || {
Expand All @@ -90,8 +90,8 @@ LL | let _f_1 = 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
| in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.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 `f1` to be fully captured
Expand Down