1
Fork 0

Rollup merge of #90597 - nikomatsakis:issue-90465, r=wesleywiser

Warn for variables that are no longer captured

r? `@wesleywiser`

cc `@rust-lang/wg-rfc-2229`

Fixes #90465
This commit is contained in:
Matthias Krüger 2021-11-05 21:12:29 +01:00 committed by GitHub
commit 4b1cb73f1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 327 additions and 146 deletions

View file

@ -86,18 +86,55 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Intermediate format to store the hir_id pointing to the use that resulted in the /// Intermediate format to store the hir_id pointing to the use that resulted in the
/// corresponding place being captured and a String which contains the captured value's /// corresponding place being captured and a String which contains the captured value's
/// name (i.e: a.b.c) /// name (i.e: a.b.c)
type CapturesInfo = (Option<hir::HirId>, String); #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum UpvarMigrationInfo {
/// We previously captured all of `x`, but now we capture some sub-path.
CapturingPrecise { source_expr: Option<hir::HirId>, var_name: String },
CapturingNothing {
// where the variable appears in the closure (but is not captured)
use_span: Span,
},
}
/// Intermediate format to store information needed to generate migration lint. The tuple /// Reasons that we might issue a migration warning.
/// contains the hir_id pointing to the use that resulted in the #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
/// corresponding place being captured, a String which contains the captured value's struct MigrationWarningReason {
/// name (i.e: a.b.c) and a String which contains the reason why migration is needed for that /// When we used to capture `x` in its entirety, we implemented the auto-trait(s)
/// capture /// in this vec, but now we don't.
type MigrationNeededForCapture = (Option<hir::HirId>, String, String); auto_traits: Vec<&'static str>,
/// When we used to capture `x` in its entirety, we would execute some destructors
/// at a different time.
drop_order: bool,
}
impl MigrationWarningReason {
fn migration_message(&self) -> String {
let base = "changes to closure capture in Rust 2021 will affect";
if !self.auto_traits.is_empty() && self.drop_order {
format!("{} drop order and which traits the closure implements", base)
} else if self.drop_order {
format!("{} drop order", base)
} else {
format!("{} which traits the closure implements", base)
}
}
}
/// Intermediate format to store information needed to generate a note in the migration lint.
struct MigrationLintNote {
captures_info: UpvarMigrationInfo,
/// reasons why migration is needed for this capture
reason: MigrationWarningReason,
}
/// Intermediate format to store the hir id of the root variable and a HashSet containing /// Intermediate format to store the hir id of the root variable and a HashSet containing
/// information on why the root variable should be fully captured /// information on why the root variable should be fully captured
type MigrationDiagnosticInfo = (hir::HirId, Vec<MigrationNeededForCapture>); struct NeededMigration {
var_hir_id: hir::HirId,
diagnostics_info: Vec<MigrationLintNote>,
}
struct InferBorrowKindVisitor<'a, 'tcx> { struct InferBorrowKindVisitor<'a, 'tcx> {
fcx: &'a FnCtxt<'a, 'tcx>, fcx: &'a FnCtxt<'a, 'tcx>,
@ -707,47 +744,66 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
closure_head_span, closure_head_span,
|lint| { |lint| {
let mut diagnostics_builder = lint.build( let mut diagnostics_builder = lint.build(
format!( &reasons.migration_message(),
"changes to closure capture in Rust 2021 will affect {}",
reasons
)
.as_str(),
); );
for (var_hir_id, diagnostics_info) in need_migrations.iter() { for NeededMigration { var_hir_id, diagnostics_info } in &need_migrations {
// Labels all the usage of the captured variable and why they are responsible // Labels all the usage of the captured variable and why they are responsible
// for migration being needed // for migration being needed
for (captured_hir_id, captured_name, reasons) in diagnostics_info.iter() { for lint_note in diagnostics_info.iter() {
if let Some(captured_hir_id) = captured_hir_id { match &lint_note.captures_info {
let cause_span = self.tcx.hir().span(*captured_hir_id); UpvarMigrationInfo::CapturingPrecise { source_expr: Some(capture_expr_id), var_name: captured_name } => {
diagnostics_builder.span_label(cause_span, format!("in Rust 2018, this closure captures all of `{}`, but in Rust 2021, it will only capture `{}`", let cause_span = self.tcx.hir().span(*capture_expr_id);
self.tcx.hir().name(*var_hir_id), diagnostics_builder.span_label(cause_span, format!("in Rust 2018, this closure captures all of `{}`, but in Rust 2021, it will only capture `{}`",
captured_name, self.tcx.hir().name(*var_hir_id),
)); captured_name,
));
}
UpvarMigrationInfo::CapturingNothing { use_span } => {
diagnostics_builder.span_label(*use_span, format!("in Rust 2018, this causes the closure to capture `{}`, but in Rust 2021, it has no effect",
self.tcx.hir().name(*var_hir_id),
));
}
_ => { }
} }
// Add a label pointing to where a captured variable affected by drop order // Add a label pointing to where a captured variable affected by drop order
// is dropped // is dropped
if reasons.contains("drop order") { if lint_note.reason.drop_order {
let drop_location_span = drop_location_span(self.tcx, &closure_hir_id); let drop_location_span = drop_location_span(self.tcx, &closure_hir_id);
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", match &lint_note.captures_info {
self.tcx.hir().name(*var_hir_id), UpvarMigrationInfo::CapturingPrecise { var_name: captured_name, .. } => {
captured_name, 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",
)); self.tcx.hir().name(*var_hir_id),
captured_name,
));
}
UpvarMigrationInfo::CapturingNothing { use_span: _ } => {
diagnostics_builder.span_label(drop_location_span, format!("in Rust 2018, `{v}` is dropped here along with the closure, but in Rust 2021 `{v}` is not part of the closure",
v = self.tcx.hir().name(*var_hir_id),
));
}
}
} }
// Add a label explaining why a closure no longer implements a trait // Add a label explaining why a closure no longer implements a trait
if reasons.contains("trait implementation") { for &missing_trait in &lint_note.reason.auto_traits {
let missing_trait = &reasons[..reasons.find("trait implementation").unwrap() - 1]; // not capturing something anymore cannot cause a trait to fail to be implemented:
match &lint_note.captures_info {
UpvarMigrationInfo::CapturingPrecise { var_name: captured_name, .. } => {
let var_name = self.tcx.hir().name(*var_hir_id);
diagnostics_builder.span_label(closure_head_span, format!("\
in Rust 2018, this closure implements {missing_trait} \
as `{var_name}` implements {missing_trait}, but in Rust 2021, \
this closure will no longer implement {missing_trait} \
because `{var_name}` is not fully captured \
and `{captured_name}` does not implement {missing_trait}"));
}
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 {}", // Cannot happen: if we don't capture a variable, we impl strictly more traits
missing_trait, UpvarMigrationInfo::CapturingNothing { use_span } => span_bug!(*use_span, "missing trait from not capturing something"),
self.tcx.hir().name(*var_hir_id), }
missing_trait,
missing_trait,
captured_name,
missing_trait,
));
} }
} }
} }
@ -840,25 +896,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Combines all the reasons for 2229 migrations /// Combines all the reasons for 2229 migrations
fn compute_2229_migrations_reasons( fn compute_2229_migrations_reasons(
&self, &self,
auto_trait_reasons: FxHashSet<&str>, auto_trait_reasons: FxHashSet<&'static str>,
drop_reason: bool, drop_order: bool,
) -> String { ) -> MigrationWarningReason {
let mut reasons = String::new(); let mut reasons = MigrationWarningReason::default();
if !auto_trait_reasons.is_empty() { for auto_trait in auto_trait_reasons {
reasons = format!( reasons.auto_traits.push(auto_trait);
"{} trait implementation for closure",
auto_trait_reasons.clone().into_iter().collect::<Vec<&str>>().join(", ")
);
} }
if !auto_trait_reasons.is_empty() && drop_reason { reasons.drop_order = drop_order;
reasons = format!("{} and ", reasons);
}
if drop_reason {
reasons = format!("{}drop order", reasons);
}
reasons reasons
} }
@ -874,7 +921,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
var_hir_id: hir::HirId, var_hir_id: hir::HirId,
closure_clause: hir::CaptureBy, closure_clause: hir::CaptureBy,
) -> Option<FxHashMap<CapturesInfo, FxHashSet<&str>>> { ) -> Option<FxHashMap<UpvarMigrationInfo, FxHashSet<&'static str>>> {
let auto_traits_def_id = vec![ let auto_traits_def_id = vec![
self.tcx.lang_items().clone_trait(), self.tcx.lang_items().clone_trait(),
self.tcx.lang_items().sync_trait(), self.tcx.lang_items().sync_trait(),
@ -963,7 +1010,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !capture_problems.is_empty() { if !capture_problems.is_empty() {
problematic_captures.insert( problematic_captures.insert(
(capture.info.path_expr_id, capture.to_string(self.tcx)), UpvarMigrationInfo::CapturingPrecise {
source_expr: capture.info.path_expr_id,
var_name: capture.to_string(self.tcx),
},
capture_problems, capture_problems,
); );
} }
@ -986,6 +1036,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// This function only returns a HashSet of CapturesInfo for significant drops. If there /// This function only returns a HashSet of CapturesInfo for significant drops. If there
/// are no significant drops than None is returned /// are no significant drops than None is returned
#[instrument(level = "debug", skip(self))]
fn compute_2229_migrations_for_drop( fn compute_2229_migrations_for_drop(
&self, &self,
closure_def_id: DefId, closure_def_id: DefId,
@ -993,25 +1044,41 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
closure_clause: hir::CaptureBy, closure_clause: hir::CaptureBy,
var_hir_id: hir::HirId, var_hir_id: hir::HirId,
) -> Option<FxHashSet<CapturesInfo>> { ) -> Option<FxHashSet<UpvarMigrationInfo>> {
let ty = self.infcx.resolve_vars_if_possible(self.node_ty(var_hir_id)); let ty = self.infcx.resolve_vars_if_possible(self.node_ty(var_hir_id));
if !ty.has_significant_drop(self.tcx, self.tcx.param_env(closure_def_id.expect_local())) { if !ty.has_significant_drop(self.tcx, self.tcx.param_env(closure_def_id.expect_local())) {
debug!("does not have significant drop");
return None; return None;
} }
let Some(root_var_min_capture_list) = min_captures.and_then(|m| m.get(&var_hir_id)) else { let Some(root_var_min_capture_list) = min_captures.and_then(|m| m.get(&var_hir_id)) else {
// The upvar is mentioned within the closure but no path starting from it is // The upvar is mentioned within the closure but no path starting from it is
// used. // used. This occurs when you have (e.g.)
//
// ```
// let x = move || {
// let _ = y;
// });
// ```
debug!("no path starting from it is used");
match closure_clause { match closure_clause {
// Only migrate if closure is a move closure // Only migrate if closure is a move closure
hir::CaptureBy::Value => return Some(FxHashSet::default()), hir::CaptureBy::Value => {
let mut diagnostics_info = FxHashSet::default();
let upvars = self.tcx.upvars_mentioned(closure_def_id).expect("must be an upvar");
let upvar = upvars[&var_hir_id];
diagnostics_info.insert(UpvarMigrationInfo::CapturingNothing { use_span: upvar.span });
return Some(diagnostics_info);
}
hir::CaptureBy::Ref => {} hir::CaptureBy::Ref => {}
} }
return None; return None;
}; };
debug!(?root_var_min_capture_list);
let mut projections_list = Vec::new(); let mut projections_list = Vec::new();
let mut diagnostics_info = FxHashSet::default(); let mut diagnostics_info = FxHashSet::default();
@ -1021,19 +1088,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Only care about captures that are moved into the closure // Only care about captures that are moved into the closure
ty::UpvarCapture::ByValue(..) => { ty::UpvarCapture::ByValue(..) => {
projections_list.push(captured_place.place.projections.as_slice()); projections_list.push(captured_place.place.projections.as_slice());
diagnostics_info.insert(( diagnostics_info.insert(UpvarMigrationInfo::CapturingPrecise {
captured_place.info.path_expr_id, source_expr: captured_place.info.path_expr_id,
captured_place.to_string(self.tcx), var_name: captured_place.to_string(self.tcx),
)); });
} }
ty::UpvarCapture::ByRef(..) => {} ty::UpvarCapture::ByRef(..) => {}
} }
} }
debug!(?projections_list);
debug!(?diagnostics_info);
let is_moved = !projections_list.is_empty(); let is_moved = !projections_list.is_empty();
debug!(?is_moved);
let is_not_completely_captured = let is_not_completely_captured =
root_var_min_capture_list.iter().any(|capture| !capture.place.projections.is_empty()); root_var_min_capture_list.iter().any(|capture| !capture.place.projections.is_empty());
debug!(?is_not_completely_captured);
if is_moved if is_moved
&& is_not_completely_captured && is_not_completely_captured
@ -1066,15 +1138,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Returns a tuple containing a vector of MigrationDiagnosticInfo, as well as a String /// Returns a tuple containing a vector of MigrationDiagnosticInfo, as well as a String
/// containing the reason why root variables whose HirId is contained in the vector should /// containing the reason why root variables whose HirId is contained in the vector should
/// be captured /// be captured
#[instrument(level = "debug", skip(self))]
fn compute_2229_migrations( fn compute_2229_migrations(
&self, &self,
closure_def_id: DefId, closure_def_id: DefId,
closure_span: Span, closure_span: Span,
closure_clause: hir::CaptureBy, closure_clause: hir::CaptureBy,
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
) -> (Vec<MigrationDiagnosticInfo>, String) { ) -> (Vec<NeededMigration>, MigrationWarningReason) {
let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) else { let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) else {
return (Vec::new(), String::new()); return (Vec::new(), MigrationWarningReason::default());
}; };
let mut need_migrations = Vec::new(); let mut need_migrations = Vec::new();
@ -1083,7 +1156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Perform auto-trait analysis // Perform auto-trait analysis
for (&var_hir_id, _) in upvars.iter() { for (&var_hir_id, _) in upvars.iter() {
let mut responsible_captured_hir_ids = Vec::new(); let mut diagnostics_info = Vec::new();
let auto_trait_diagnostic = if let Some(diagnostics_info) = let auto_trait_diagnostic = if let Some(diagnostics_info) =
self.compute_2229_migrations_for_trait(min_captures, var_hir_id, closure_clause) self.compute_2229_migrations_for_trait(min_captures, var_hir_id, closure_clause)
@ -1115,34 +1188,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut capture_diagnostic = capture_diagnostic.into_iter().collect::<Vec<_>>(); let mut capture_diagnostic = capture_diagnostic.into_iter().collect::<Vec<_>>();
capture_diagnostic.sort(); capture_diagnostic.sort();
for captured_info in capture_diagnostic.iter() { for captures_info in capture_diagnostic {
// Get the auto trait reasons of why migration is needed because of that capture, if there are any // Get the auto trait reasons of why migration is needed because of that capture, if there are any
let capture_trait_reasons = let capture_trait_reasons =
if let Some(reasons) = auto_trait_diagnostic.get(captured_info) { if let Some(reasons) = auto_trait_diagnostic.get(&captures_info) {
reasons.clone() reasons.clone()
} else { } else {
FxHashSet::default() FxHashSet::default()
}; };
// Check if migration is needed because of drop reorder as a result of that capture // Check if migration is needed because of drop reorder as a result of that capture
let capture_drop_reorder_reason = drop_reorder_diagnostic.contains(captured_info); let capture_drop_reorder_reason = drop_reorder_diagnostic.contains(&captures_info);
// Combine all the reasons of why the root variable should be captured as a result of // Combine all the reasons of why the root variable should be captured as a result of
// auto trait implementation issues // auto trait implementation issues
auto_trait_migration_reasons.extend(capture_trait_reasons.clone()); auto_trait_migration_reasons.extend(capture_trait_reasons.clone());
responsible_captured_hir_ids.push(( diagnostics_info.push(MigrationLintNote {
captured_info.0, captures_info,
captured_info.1.clone(), reason: self.compute_2229_migrations_reasons(
self.compute_2229_migrations_reasons(
capture_trait_reasons, capture_trait_reasons,
capture_drop_reorder_reason, capture_drop_reorder_reason,
), ),
)); });
} }
if !capture_diagnostic.is_empty() { if !diagnostics_info.is_empty() {
need_migrations.push((var_hir_id, responsible_captured_hir_ids)); need_migrations.push(NeededMigration { var_hir_id, diagnostics_info });
} }
} }
( (
@ -2087,6 +2159,7 @@ fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> Symbol {
tcx.hir().name(var_hir_id) tcx.hir().name(var_hir_id)
} }
#[instrument(level = "debug", skip(tcx))]
fn should_do_rust_2021_incompatible_closure_captures_analysis( fn should_do_rust_2021_incompatible_closure_captures_analysis(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
closure_id: hir::HirId, closure_id: hir::HirId,
@ -2102,10 +2175,12 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
/// - s2: Comma separated names of the variables being migrated. /// - s2: Comma separated names of the variables being migrated.
fn migration_suggestion_for_2229( fn migration_suggestion_for_2229(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
need_migrations: &Vec<MigrationDiagnosticInfo>, need_migrations: &Vec<NeededMigration>,
) -> (String, String) { ) -> (String, String) {
let need_migrations_variables = let need_migrations_variables = need_migrations
need_migrations.iter().map(|(v, _)| var_name(tcx, *v)).collect::<Vec<_>>(); .iter()
.map(|NeededMigration { var_hir_id: v, .. }| var_name(tcx, *v))
.collect::<Vec<_>>();
let migration_ref_concat = let migration_ref_concat =
need_migrations_variables.iter().map(|v| format!("&{}", v)).collect::<Vec<_>>().join(", "); need_migrations_variables.iter().map(|v| format!("&{}", v)).collect::<Vec<_>>().join(", ");

View file

@ -0,0 +1,35 @@
// run-rustfix
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE lint level is defined here
fn main() {
struct Foo(u32);
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped {}", self.0);
}
}
let f0 = Foo(0);
let f1 = Foo(1);
let c0 = move || {
let _ = &f0;
//~^ ERROR changes to closure capture in Rust 2021 will affect drop order
//~| NOTE for more information
let _ = f0;
//~^ NOTE in Rust 2018, this causes the closure to capture `f0`, but in Rust 2021, it has no effect
};
let c1 = move || {
let _ = &f1;
};
println!("dropping 0");
drop(c0);
println!("dropping 1");
drop(c1);
println!("dropped all");
}
//~^ NOTE in Rust 2018, `f0` is dropped here along with the closure, but in Rust 2021 `f0` is not part of the closure

View file

@ -0,0 +1,34 @@
// run-rustfix
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE lint level is defined here
fn main() {
struct Foo(u32);
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped {}", self.0);
}
}
let f0 = Foo(0);
let f1 = Foo(1);
let c0 = move || {
//~^ ERROR changes to closure capture in Rust 2021 will affect drop order
//~| NOTE for more information
let _ = f0;
//~^ NOTE in Rust 2018, this causes the closure to capture `f0`, but in Rust 2021, it has no effect
};
let c1 = move || {
let _ = &f1;
};
println!("dropping 0");
drop(c0);
println!("dropping 1");
drop(c1);
println!("dropped all");
}
//~^ NOTE in Rust 2018, `f0` is dropped here along with the closure, but in Rust 2021 `f0` is not part of the closure

View file

@ -0,0 +1,26 @@
error: changes to closure capture in Rust 2021 will affect drop order
--> $DIR/issue-90465.rs:17:14
|
LL | let c0 = move || {
| ^^^^^^^
...
LL | let _ = f0;
| -- in Rust 2018, this causes the closure to capture `f0`, but in Rust 2021, it has no effect
...
LL | }
| - in Rust 2018, `f0` is dropped here along with the closure, but in Rust 2021 `f0` is not part of the closure
|
note: the lint level is defined here
--> $DIR/issue-90465.rs:3: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 `f0` to be fully captured
|
LL ~ let c0 = move || {
LL + let _ = &f0;
|
error: aborting due to previous error

View file

@ -20,8 +20,8 @@ fn test_send_trait() {
let mut f = 10; let mut f = 10;
let fptr = SendPointer(&mut f as *mut i32); let fptr = SendPointer(&mut f as *mut i32);
thread::spawn(move || { let _ = &fptr; unsafe { thread::spawn(move || { let _ = &fptr; unsafe {
//~^ ERROR: `Send` trait implementation for closure //~^ ERROR: changes to closure capture
//~| 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` //~| NOTE: in Rust 2018, this closure implements `Send`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr` to be fully captured //~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0 = 20; *fptr.0 = 20;
@ -40,8 +40,9 @@ fn test_sync_trait() {
let f = CustomInt(&mut f as *mut i32); let f = CustomInt(&mut f as *mut i32);
let fptr = SyncPointer(f); let fptr = SyncPointer(f);
thread::spawn(move || { let _ = &fptr; unsafe { thread::spawn(move || { let _ = &fptr; unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation for closure //~^ ERROR: changes to closure capture
//~| 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` //~| NOTE: in Rust 2018, this closure implements `Sync`
//~| NOTE: in Rust 2018, this closure implements `Send`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr` to be fully captured //~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0.0 = 20; *fptr.0.0 = 20;
@ -65,8 +66,8 @@ fn test_clone_trait() {
let f = U(S(Foo(0)), T(0)); let f = U(S(Foo(0)), T(0));
let c = || { let c = || {
let _ = &f; let _ = &f;
//~^ ERROR: `Clone` trait implementation for closure and drop order //~^ ERROR: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
//~| 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` //~| NOTE: in Rust 2018, this closure implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f` to be fully captured //~| HELP: add a dummy let to cause `f` to be fully captured
let f_1 = f.1; let f_1 = f.1;

View file

@ -20,8 +20,8 @@ fn test_send_trait() {
let mut f = 10; let mut f = 10;
let fptr = SendPointer(&mut f as *mut i32); let fptr = SendPointer(&mut f as *mut i32);
thread::spawn(move || unsafe { thread::spawn(move || unsafe {
//~^ ERROR: `Send` trait implementation for closure //~^ ERROR: changes to closure capture
//~| 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` //~| NOTE: in Rust 2018, this closure implements `Send`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr` to be fully captured //~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0 = 20; *fptr.0 = 20;
@ -40,8 +40,9 @@ fn test_sync_trait() {
let f = CustomInt(&mut f as *mut i32); let f = CustomInt(&mut f as *mut i32);
let fptr = SyncPointer(f); let fptr = SyncPointer(f);
thread::spawn(move || unsafe { thread::spawn(move || unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation for closure //~^ ERROR: changes to closure capture
//~| 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` //~| NOTE: in Rust 2018, this closure implements `Sync`
//~| NOTE: in Rust 2018, this closure implements `Send`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr` to be fully captured //~| HELP: add a dummy let to cause `fptr` to be fully captured
*fptr.0.0 = 20; *fptr.0.0 = 20;
@ -64,8 +65,8 @@ impl Clone for U {
fn test_clone_trait() { fn test_clone_trait() {
let f = U(S(Foo(0)), T(0)); let f = U(S(Foo(0)), T(0));
let c = || { let c = || {
//~^ ERROR: `Clone` trait implementation for closure and drop order //~^ ERROR: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
//~| 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` //~| NOTE: in Rust 2018, this closure implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f` to be fully captured //~| HELP: add a dummy let to cause `f` to be fully captured
let f_1 = f.1; let f_1 = f.1;

View file

@ -1,8 +1,8 @@
error: changes to closure capture in Rust 2021 will affect `Send` trait implementation for closure error: changes to closure capture in Rust 2021 will affect which traits the closure implements
--> $DIR/auto_traits.rs:22:19 --> $DIR/auto_traits.rs:22:19
| |
LL | thread::spawn(move || unsafe { LL | thread::spawn(move || unsafe {
| ^^^^^^^^^^^^^^ 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` | ^^^^^^^^^^^^^^ in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr` is not fully captured and `fptr.0` does not implement `Send`
... ...
LL | *fptr.0 = 20; LL | *fptr.0 = 20;
| ------- in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0` | ------- in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0`
@ -23,11 +23,14 @@ LL |
LL | *fptr.0 = 20; LL | *fptr.0 = 20;
... ...
error: changes to closure capture in Rust 2021 will affect `Sync`, `Send` trait implementation for closure error: changes to closure capture in Rust 2021 will affect which traits the closure implements
--> $DIR/auto_traits.rs:42:19 --> $DIR/auto_traits.rs:42:19
| |
LL | thread::spawn(move || unsafe { LL | thread::spawn(move || unsafe {
| ^^^^^^^^^^^^^^ 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` | ^^^^^^^^^^^^^^
| |
| in Rust 2018, this closure implements `Sync` as `fptr` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` because `fptr` is not fully captured and `fptr.0.0` does not implement `Sync`
| in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr` is not fully captured and `fptr.0.0` does not implement `Send`
... ...
LL | *fptr.0.0 = 20; LL | *fptr.0.0 = 20;
| --------- in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0.0` | --------- in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0.0`
@ -40,14 +43,14 @@ LL |
LL | LL |
LL | LL |
LL | LL |
LL | *fptr.0.0 = 20; 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 drop order and which traits the closure implements
--> $DIR/auto_traits.rs:66:13 --> $DIR/auto_traits.rs:67:13
| |
LL | let c = || { LL | let c = || {
| ^^ 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` | ^^ in Rust 2018, this closure implements `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f` is not fully captured and `f.1` does not implement `Clone`
... ...
LL | let f_1 = f.1; LL | let f_1 = f.1;
| --- in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.1` | --- in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.1`

View file

@ -19,8 +19,9 @@ where
let f = panic::AssertUnwindSafe(f); let f = panic::AssertUnwindSafe(f);
let result = panic::catch_unwind(move || { let result = panic::catch_unwind(move || {
let _ = &f; let _ = &f;
//~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
//~| NOTE: in Rust 2018, this closure implements `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe` //~| NOTE: in Rust 2018, this closure implements `UnwindSafe`
//~| NOTE: in Rust 2018, this closure implements `RefUnwindSafe`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f` to be fully captured //~| HELP: add a dummy let to cause `f` to be fully captured
f.0() f.0()

View file

@ -18,8 +18,9 @@ where
{ {
let f = panic::AssertUnwindSafe(f); let f = panic::AssertUnwindSafe(f);
let result = panic::catch_unwind(move || { let result = panic::catch_unwind(move || {
//~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
//~| NOTE: in Rust 2018, this closure implements `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe` //~| NOTE: in Rust 2018, this closure implements `UnwindSafe`
//~| NOTE: in Rust 2018, this closure implements `RefUnwindSafe`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f` to be fully captured //~| HELP: add a dummy let to cause `f` to be fully captured
f.0() f.0()

View file

@ -1,8 +1,11 @@
error: changes to closure capture in Rust 2021 will affect `UnwindSafe`, `RefUnwindSafe` trait implementation for closure error: changes to closure capture in Rust 2021 will affect which traits the closure implements
--> $DIR/mir_calls_to_shims.rs:20:38 --> $DIR/mir_calls_to_shims.rs:20:38
| |
LL | let result = panic::catch_unwind(move || { LL | let result = panic::catch_unwind(move || {
| ^^^^^^^ in Rust 2018, this closure implements `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe` | ^^^^^^^
| |
| in Rust 2018, this closure implements `UnwindSafe` as `f` implements `UnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe` because `f` is not fully captured and `f.0` does not implement `UnwindSafe`
| in Rust 2018, this closure implements `RefUnwindSafe` as `f` implements `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `RefUnwindSafe` because `f` is not fully captured and `f.0` does not implement `RefUnwindSafe`
... ...
LL | f.0() LL | f.0()
| --- in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.0` | --- in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.0`

View file

@ -18,7 +18,6 @@ impl Foo {
} }
} }
struct S(Foo); struct S(Foo);
#[derive(Clone)] #[derive(Clone)]
@ -37,8 +36,8 @@ fn test_multi_issues() {
let f2 = U(S(Foo::from("bar")), T(0)); let f2 = U(S(Foo::from("bar")), T(0));
let c = || { let c = || {
let _ = (&f1, &f2); let _ = (&f1, &f2);
//~^ ERROR: `Clone` trait implementation for closure and drop order //~^ ERROR: changes to closure capture in Rust 2021
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1`, `f2` to be fully captured //~| HELP: add a dummy let to cause `f1`, `f2` to be fully captured
let _f_1 = f1.0; let _f_1 = f1.0;
@ -57,8 +56,8 @@ fn test_capturing_all_disjoint_fields_individually() {
let f1 = U(S(Foo::from("foo")), T(0)); let f1 = U(S(Foo::from("foo")), T(0));
let c = || { let c = || {
let _ = &f1; let _ = &f1;
//~^ ERROR: `Clone` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured //~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_1 = f1.0; let _f_1 = f1.0;
@ -83,9 +82,9 @@ fn test_capturing_several_disjoint_fields_individually_1() {
let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar"))); let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar")));
let c = || { let c = || {
let _ = &f1; let _ = &f1;
//~^ ERROR: `Clone` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.2` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured //~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0; let _f_0 = f1.0;
@ -103,8 +102,8 @@ fn test_capturing_several_disjoint_fields_individually_2() {
let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar"))); let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar")));
let c = || { let c = || {
let _ = &f1; let _ = &f1;
//~^ ERROR: `Clone` trait implementation for closure and drop order //~^ ERROR: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured //~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0; let _f_0 = f1.0;
@ -136,9 +135,10 @@ fn test_multi_traits_issues() {
let mut f2 = 10; let mut f2 = 10;
let fptr2 = SendPointer(&mut f2 as *mut i32); let fptr2 = SendPointer(&mut f2 as *mut i32);
thread::spawn(move || { let _ = (&fptr1, &fptr2); unsafe { thread::spawn(move || { let _ = (&fptr1, &fptr2); unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021
//~| NOTE: in Rust 2018, this closure implements `Sync`, `Send` as `fptr1` implements `Sync`, `Send`, but in Rust 2021, this closure will no longer implement `Sync`, `Send` as `fptr1.0.0` does not implement `Sync`, `Send` //~| NOTE: in Rust 2018, this closure implements `Sync` as `fptr1` implements `Sync`
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr2.0` does not implement `Send` //~| NOTE: in Rust 2018, this closure implements `Send` as `fptr1` implements `Send`
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr1`, `fptr2` to be fully captured //~| HELP: add a dummy let to cause `fptr1`, `fptr2` to be fully captured
*fptr1.0.0 = 20; *fptr1.0.0 = 20;

View file

@ -18,7 +18,6 @@ impl Foo {
} }
} }
struct S(Foo); struct S(Foo);
#[derive(Clone)] #[derive(Clone)]
@ -36,8 +35,8 @@ fn test_multi_issues() {
let f1 = U(S(Foo::from("foo")), T(0)); let f1 = U(S(Foo::from("foo")), T(0));
let f2 = U(S(Foo::from("bar")), T(0)); let f2 = U(S(Foo::from("bar")), T(0));
let c = || { let c = || {
//~^ ERROR: `Clone` trait implementation for closure and drop order //~^ ERROR: changes to closure capture in Rust 2021
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1`, `f2` to be fully captured //~| HELP: add a dummy let to cause `f1`, `f2` to be fully captured
let _f_1 = f1.0; let _f_1 = f1.0;
@ -55,8 +54,8 @@ fn test_multi_issues() {
fn test_capturing_all_disjoint_fields_individually() { fn test_capturing_all_disjoint_fields_individually() {
let f1 = U(S(Foo::from("foo")), T(0)); let f1 = U(S(Foo::from("foo")), T(0));
let c = || { let c = || {
//~^ ERROR: `Clone` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured //~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_1 = f1.0; let _f_1 = f1.0;
@ -80,9 +79,9 @@ impl Clone for U1 {
fn test_capturing_several_disjoint_fields_individually_1() { fn test_capturing_several_disjoint_fields_individually_1() {
let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar"))); let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar")));
let c = || { let c = || {
//~^ ERROR: `Clone` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.2` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured //~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0; let _f_0 = f1.0;
@ -99,8 +98,8 @@ fn test_capturing_several_disjoint_fields_individually_1() {
fn test_capturing_several_disjoint_fields_individually_2() { fn test_capturing_several_disjoint_fields_individually_2() {
let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar"))); let f1 = U1(S(Foo::from("foo")), T(0), S(Foo::from("bar")));
let c = || { let c = || {
//~^ ERROR: `Clone` trait implementation for closure and drop order //~^ ERROR: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
//~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` //~| NOTE: in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `f1` to be fully captured //~| HELP: add a dummy let to cause `f1` to be fully captured
let _f_0 = f1.0; let _f_0 = f1.0;
@ -132,9 +131,10 @@ fn test_multi_traits_issues() {
let mut f2 = 10; let mut f2 = 10;
let fptr2 = SendPointer(&mut f2 as *mut i32); let fptr2 = SendPointer(&mut f2 as *mut i32);
thread::spawn(move || unsafe { thread::spawn(move || unsafe {
//~^ ERROR: `Sync`, `Send` trait implementation for closure //~^ ERROR: changes to closure capture in Rust 2021
//~| NOTE: in Rust 2018, this closure implements `Sync`, `Send` as `fptr1` implements `Sync`, `Send`, but in Rust 2021, this closure will no longer implement `Sync`, `Send` as `fptr1.0.0` does not implement `Sync`, `Send` //~| NOTE: in Rust 2018, this closure implements `Sync` as `fptr1` implements `Sync`
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr2.0` does not implement `Send` //~| NOTE: in Rust 2018, this closure implements `Send` as `fptr1` implements `Send`
//~| NOTE: in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`
//~| NOTE: for more information, see //~| NOTE: for more information, see
//~| HELP: add a dummy let to cause `fptr1`, `fptr2` to be fully captured //~| HELP: add a dummy let to cause `fptr1`, `fptr2` to be fully captured
*fptr1.0.0 = 20; *fptr1.0.0 = 20;

View file

@ -1,8 +1,8 @@
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 drop order and which traits the closure implements
--> $DIR/multi_diagnostics.rs:38:13 --> $DIR/multi_diagnostics.rs:37:13
| |
LL | let c = || { LL | let c = || {
| ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` | ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
... ...
LL | let _f_1 = f1.0; LL | let _f_1 = f1.0;
| ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0` | ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0`
@ -25,11 +25,11 @@ LL ~ let c = || {
LL + let _ = (&f1, &f2); LL + let _ = (&f1, &f2);
| |
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure error: changes to closure capture in Rust 2021 will affect which traits the closure implements
--> $DIR/multi_diagnostics.rs:57:13 --> $DIR/multi_diagnostics.rs:56:13
| |
LL | let c = || { LL | let c = || {
| ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` | ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
... ...
LL | let _f_1 = f1.0; LL | let _f_1 = f1.0;
| ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0` | ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0`
@ -41,14 +41,14 @@ LL ~ let c = || {
LL + let _ = &f1; LL + let _ = &f1;
| |
error: changes to closure capture in Rust 2021 will affect `Clone` trait implementation for closure error: changes to closure capture in Rust 2021 will affect which traits the closure implements
--> $DIR/multi_diagnostics.rs:82:13 --> $DIR/multi_diagnostics.rs:81:13
| |
LL | let c = || { LL | let c = || {
| ^^ | ^^
| | | |
| in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` | in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
| in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.2` does not implement `Clone` | in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.2` does not implement `Clone`
... ...
LL | let _f_0 = f1.0; LL | let _f_0 = f1.0;
| ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0` | ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0`
@ -63,11 +63,11 @@ LL ~ let c = || {
LL + let _ = &f1; LL + let _ = &f1;
| |
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 drop order and which traits the closure implements
--> $DIR/multi_diagnostics.rs:101:13 --> $DIR/multi_diagnostics.rs:100:13
| |
LL | let c = || { LL | let c = || {
| ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` as `f1.0` does not implement `Clone` | ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
... ...
LL | let _f_0 = f1.0; LL | let _f_0 = f1.0;
| ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0` | ---- in Rust 2018, this closure captures all of `f1`, but in Rust 2021, it will only capture `f1.0`
@ -88,14 +88,15 @@ LL ~ let c = || {
LL + let _ = &f1; LL + let _ = &f1;
| |
error: changes to closure capture in Rust 2021 will affect `Sync`, `Send` trait implementation for closure error: changes to closure capture in Rust 2021 will affect which traits the closure implements
--> $DIR/multi_diagnostics.rs:134:19 --> $DIR/multi_diagnostics.rs:133:19
| |
LL | thread::spawn(move || unsafe { LL | thread::spawn(move || unsafe {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
| | | |
| in Rust 2018, this closure implements `Sync`, `Send` as `fptr1` implements `Sync`, `Send`, but in Rust 2021, this closure will no longer implement `Sync`, `Send` as `fptr1.0.0` does not implement `Sync`, `Send` | in Rust 2018, this closure implements `Sync` as `fptr1` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` because `fptr1` is not fully captured and `fptr1.0.0` does not implement `Sync`
| in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr2.0` does not implement `Send` | in Rust 2018, this closure implements `Send` as `fptr1` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr1` is not fully captured and `fptr1.0.0` does not implement `Send`
| in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr2` is not fully captured and `fptr2.0` does not implement `Send`
... ...
LL | *fptr1.0.0 = 20; LL | *fptr1.0.0 = 20;
| ---------- in Rust 2018, this closure captures all of `fptr1`, but in Rust 2021, it will only capture `fptr1.0.0` | ---------- in Rust 2018, this closure captures all of `fptr1`, but in Rust 2021, it will only capture `fptr1.0.0`