From 7b1013329789e1902577af6bda220dc5a8ac7f37 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Wed, 1 Aug 2018 23:53:28 -0700 Subject: [PATCH 01/27] Fix some random stuff --- src/librustc/mir/mod.rs | 10 +++++----- src/librustc_mir/borrow_check/move_errors.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index dae5709ba114a..6b9cd2956216f 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -429,8 +429,8 @@ pub enum BorrowKind { /// Data must be immutable but not aliasable. This kind of borrow /// cannot currently be expressed by the user and is used only in - /// implicit closure bindings. It is needed when you the closure - /// is borrowing or mutating a mutable referent, e.g.: + /// implicit closure bindings. It is needed when the closure is + /// borrowing or mutating a mutable referent, e.g.: /// /// let x: &mut isize = ...; /// let y = || *x += 5; @@ -443,7 +443,7 @@ pub enum BorrowKind { /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn /// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// - /// This is then illegal because you cannot mutate a `&mut` found + /// This is then illegal because you cannot mutate an `&mut` found /// in an aliasable location. To solve, you'd have to translate with /// an `&mut` borrow: /// @@ -673,7 +673,7 @@ pub struct LocalDecl<'tcx> { /// ROOT SCOPE /// │{ argument x: &str } /// │ - /// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes + /// │ │{ #[allow(unused_mut)] } // this is actually split into 2 scopes /// │ │ // in practice because I'm lazy. /// │ │ /// │ │← x.source_info.scope @@ -906,7 +906,7 @@ pub enum TerminatorKind<'tcx> { /// Drop the Place and assign the new value over it. This ensures /// that the assignment to `P` occurs *even if* the destructor for - /// place unwinds. Its semantics are best explained by by the + /// place unwinds. Its semantics are best explained by the /// elaboration: /// /// ``` diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index d3524e841b223..5bbedbcfeee4e 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -155,7 +155,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { statement_span: Span, ) { debug!( - "append_to_grouped_errors(match_place={:?}, match_span={:?})", + "append_binding_error(match_place={:?}, match_span={:?})", match_place, match_span ); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 6b6ec749bcbe6..ebf9631831c88 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -321,9 +321,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block.unit() } - /// Declares the bindings of the given pattern and returns the visibility scope - /// for the bindings in this patterns, if such a scope had to be created. - /// NOTE: Declaring the bindings should always be done in their drop scope. + /// Declares the bindings of the given patterns and returns the visibility + /// scope for the bindings in these patterns, if such a scope had to be + /// created. NOTE: Declaring the bindings should always be done in their + /// drop scope. pub fn declare_bindings(&mut self, mut visibility_scope: Option, scope_span: Span, From a05f82fd2d6ffdaa4f220e3f1c1a060fe6886dfd Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 7 Aug 2018 01:02:39 -0700 Subject: [PATCH 02/27] Suggest match ergonomics, not `ref`/`ref mut` --- src/librustc/mir/mod.rs | 7 +- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_mir/borrow_check/move_errors.rs | 187 ++--- .../borrow_check/mutability_errors.rs | 6 +- src/librustc_mir/build/matches/mod.rs | 7 +- src/librustc_mir/build/mod.rs | 1 + src/librustc_mir/lib.rs | 1 + src/librustc_mir/util/mod.rs | 8 +- src/test/ui/suggestions/dont-suggest-ref.rs | 267 +++++++ .../ui/suggestions/dont-suggest-ref.stderr | 666 ++++++++++++++++++ 10 files changed, 1055 insertions(+), 97 deletions(-) create mode 100644 src/test/ui/suggestions/dont-suggest-ref.rs create mode 100644 src/test/ui/suggestions/dont-suggest-ref.stderr diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 6b9cd2956216f..8ceff303774b5 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -523,6 +523,8 @@ pub struct VarBindingForm<'tcx> { /// (b) it gives a way to separate this case from the remaining cases /// for diagnostics. pub opt_match_place: Option<(Option>, Span)>, + /// Span of the pattern in which this variable was bound. + pub pat_span: Span, } #[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] @@ -540,7 +542,8 @@ CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, } impl_stable_hash_for!(struct self::VarBindingForm<'tcx> { binding_mode, opt_ty_info, - opt_match_place + opt_match_place, + pat_span }); mod binding_form_impl { @@ -710,6 +713,7 @@ impl<'tcx> LocalDecl<'tcx> { binding_mode: ty::BindingMode::BindByValue(_), opt_ty_info: _, opt_match_place: _, + pat_span: _, }))) => true, // FIXME: might be able to thread the distinction between @@ -729,6 +733,7 @@ impl<'tcx> LocalDecl<'tcx> { binding_mode: ty::BindingMode::BindByValue(_), opt_ty_info: _, opt_match_place: _, + pat_span: _, }))) => true, Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf)) => true, diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 098149c36ce43..5b08400eb112d 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1235,7 +1235,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { ty::BindByReference(..) => { let let_span = self.tcx.hir.span(node_id); let suggestion = suggest_ref_mut(self.tcx, let_span); - if let Some((let_span, replace_str)) = suggestion { + if let Some(replace_str) = suggestion { db.span_suggestion( let_span, "use a mutable reference instead", diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 5bbedbcfeee4e..b89a8fa88b3e6 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustc::hir; +use core::unicode::property::Pattern_White_Space; use rustc::mir::*; use rustc::ty; use rustc_errors::DiagnosticBuilder; @@ -36,18 +36,18 @@ use util::borrowck_errors::{BorrowckErrors, Origin}; // let (&x, &y) = (&String::new(), &String::new()); #[derive(Debug)] enum GroupedMoveError<'tcx> { - // Match place can't be moved from + // Place expression can't be moved from, // e.g. match x[0] { s => (), } where x: &[String] - MovesFromMatchPlace { + MovesFromPlace { original_path: Place<'tcx>, span: Span, move_from: Place<'tcx>, kind: IllegalMoveOriginKind<'tcx>, binds_to: Vec, }, - // Part of a pattern can't be moved from, + // Part of a value expression can't be moved from, // e.g. match &String::new() { &x => (), } - MovesFromPattern { + MovesFromValue { original_path: Place<'tcx>, span: Span, move_from: MovePathIndex, @@ -55,6 +55,8 @@ enum GroupedMoveError<'tcx> { binds_to: Vec, }, // Everything that isn't from pattern matching. + // FIXME(ashtneoi): I think this is only for moves into temporaries, as + // when returning a value. Clarification needed. OtherIllegalMove { original_path: Place<'tcx>, span: Span, @@ -119,6 +121,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { opt_match_place: Some((ref opt_match_place, match_span)), binding_mode: _, opt_ty_info: _, + pat_span: _, }))) = local_decl.is_user_variable { self.append_binding_error( @@ -166,7 +169,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { // Error with the match place LookupResult::Parent(_) => { for ge in &mut *grouped_errors { - if let GroupedMoveError::MovesFromMatchPlace { span, binds_to, .. } = ge { + if let GroupedMoveError::MovesFromPlace { span, binds_to, .. } = ge { if match_span == *span { debug!("appending local({:?}) to list", bind_to); if !binds_to.is_empty() { @@ -184,7 +187,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } else { (vec![bind_to], match_span) }; - grouped_errors.push(GroupedMoveError::MovesFromMatchPlace { + grouped_errors.push(GroupedMoveError::MovesFromPlace { span, move_from: match_place.clone(), original_path, @@ -200,7 +203,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { _ => unreachable!("Probably not unreachable..."), }; for ge in &mut *grouped_errors { - if let GroupedMoveError::MovesFromPattern { + if let GroupedMoveError::MovesFromValue { span, move_from: other_mpi, binds_to, @@ -215,7 +218,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } debug!("found a new move error location"); - grouped_errors.push(GroupedMoveError::MovesFromPattern { + grouped_errors.push(GroupedMoveError::MovesFromValue { span: match_span, move_from: mpi, original_path, @@ -230,13 +233,13 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { let (mut err, err_span) = { let (span, original_path, kind): (Span, &Place<'tcx>, &IllegalMoveOriginKind) = match error { - GroupedMoveError::MovesFromMatchPlace { + GroupedMoveError::MovesFromPlace { span, ref original_path, ref kind, .. } | - GroupedMoveError::MovesFromPattern { span, ref original_path, ref kind, .. } | + GroupedMoveError::MovesFromValue { span, ref original_path, ref kind, .. } | GroupedMoveError::OtherIllegalMove { span, ref original_path, ref kind } => { (span, original_path, kind) }, @@ -331,111 +334,119 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { err: &mut DiagnosticBuilder<'a>, span: Span, ) { + let snippet = self.tcx.sess.codemap().span_to_snippet(span).unwrap(); match error { - GroupedMoveError::MovesFromMatchPlace { + GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { - // Ok to suggest a borrow, since the target can't be moved from - // anyway. - if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) { - match move_from { - Place::Projection(ref proj) - if self.suitable_to_remove_deref(proj, &snippet) => - { + let mut suggest_change_head_expr = false; + match move_from { + Place::Projection(box PlaceProjection { + elem: ProjectionElem::Deref, + .. + }) => { + // This is false for (e.g.) index expressions `a[b]`, + // which roughly desugar to `*Index::index(&a, b)` or + // `*IndexMut::index_mut(&mut a, b)`. + if snippet.starts_with('*') { err.span_suggestion( span, "consider removing this dereference operator", (&snippet[1..]).to_owned(), ); - } - _ => { - err.span_suggestion( - span, - "consider using a reference instead", - format!("&{}", snippet), - ); + suggest_change_head_expr = true; } } - - binds_to.sort(); - binds_to.dedup(); - for local in binds_to { - let bind_to = &self.mir.local_decls[local]; - let binding_span = bind_to.source_info.span; - err.span_label( - binding_span, - format!( - "move occurs because {} has type `{}`, \ - which does not implement the `Copy` trait", - bind_to.name.unwrap(), - bind_to.ty - ), + _ => { + err.span_suggestion( + span, + "consider using a reference instead", + format!("&{}", snippet), ); + suggest_change_head_expr = true; } } + binds_to.sort(); + binds_to.dedup(); + if !suggest_change_head_expr { + self.add_move_error_suggestions(err, &binds_to); + } + self.add_move_error_labels(err, &binds_to); } - GroupedMoveError::MovesFromPattern { mut binds_to, .. } => { - // Suggest ref, since there might be a move in - // another match arm + GroupedMoveError::MovesFromValue { mut binds_to, .. } => { binds_to.sort(); binds_to.dedup(); - let mut multipart_suggestion = Vec::with_capacity(binds_to.len()); - for (j, local) in binds_to.into_iter().enumerate() { - let bind_to = &self.mir.local_decls[local]; - let binding_span = bind_to.source_info.span; + self.add_move_error_suggestions(err, &binds_to); + self.add_move_error_labels(err, &binds_to); + } + // No binding. Nothing to suggest. + GroupedMoveError::OtherIllegalMove { .. } => (), + } + } - // Suggest ref mut when the user has already written mut. - let ref_kind = match bind_to.mutability { - Mutability::Not => "ref", - Mutability::Mut => "ref mut", - }; - if j == 0 { - err.span_label(binding_span, format!("data moved here")); + fn add_move_error_suggestions( + &self, + err: &mut DiagnosticBuilder<'a>, + binds_to: &[Local], + ) { + for local in binds_to { + let bind_to = &self.mir.local_decls[*local]; + if let Some( + ClearCrossCrate::Set(BindingForm::Var(VarBindingForm { + pat_span, + .. + })) + ) = bind_to.is_user_variable { + let pat_snippet = self + .tcx.sess.codemap() + .span_to_snippet(pat_span) + .unwrap(); + if pat_snippet.starts_with('&') { + let pat_snippet = &pat_snippet[1..]; + let suggestion; + if pat_snippet.starts_with("mut") + && pat_snippet["mut".len()..].starts_with(Pattern_White_Space) + { + suggestion = pat_snippet["mut".len()..].trim_left(); } else { - err.span_label(binding_span, format!("... and here")); - } - match bind_to.name { - Some(name) => { - multipart_suggestion.push((binding_span, - format!("{} {}", ref_kind, name))); - } - None => { - err.span_label( - span, - format!("Local {:?} is not suitable for ref", bind_to), - ); - } + suggestion = pat_snippet; } + err.span_suggestion( + pat_span, + "consider removing this borrow operator", + suggestion.to_owned(), + ); } - err.multipart_suggestion("to prevent move, use ref or ref mut", - multipart_suggestion); } - // Nothing to suggest. - GroupedMoveError::OtherIllegalMove { .. } => (), } } - fn suitable_to_remove_deref(&self, proj: &PlaceProjection<'tcx>, snippet: &str) -> bool { - let is_shared_ref = |ty: ty::Ty| match ty.sty { - ty::TypeVariants::TyRef(.., hir::Mutability::MutImmutable) => true, - _ => false, - }; + fn add_move_error_labels( + &self, + err: &mut DiagnosticBuilder<'a>, + binds_to: &[Local], + ) { + for (j, local) in binds_to.into_iter().enumerate() { + let bind_to = &self.mir.local_decls[*local]; + let binding_span = bind_to.source_info.span; - proj.elem == ProjectionElem::Deref && snippet.starts_with('*') && match proj.base { - Place::Local(local) => { - let local_decl = &self.mir.local_decls[local]; - // If this is a temporary, then this could be from an - // overloaded * operator. - local_decl.is_user_variable.is_some() && is_shared_ref(local_decl.ty) + if j == 0 { + err.span_label(binding_span, format!("data moved here")); + } else { + err.span_label(binding_span, format!("... and here")); } - Place::Promoted(_) => true, - Place::Static(ref st) => is_shared_ref(st.ty), - Place::Projection(ref proj) => match proj.elem { - ProjectionElem::Field(_, ty) => is_shared_ref(ty), - _ => false, - }, + + err.span_note( + binding_span, + &format!( + "move occurs because {} has type `{}`, \ + which does not implement the `Copy` trait", + bind_to.name.unwrap(), + bind_to.ty + ), + ); } } } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 283cccd51174a..f11135fc026f5 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -329,7 +329,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { ClearCrossCrate::Set(mir::BindingForm::Var(mir::VarBindingForm { binding_mode: ty::BindingMode::BindByReference(_), .. - })) => suggest_ref_mut(self.tcx, local_decl.source_info.span), + })) => { + let pattern_span = local_decl.source_info.span; + suggest_ref_mut(self.tcx, pattern_span) + .map(|replacement| (pattern_span, replacement)) + } // ClearCrossCrate::Set(mir::BindingForm::RefForGuard) => unreachable!(), diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index ebf9631831c88..b317bb7cff0e3 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -357,7 +357,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let visibility_scope = visibility_scope.unwrap(); this.declare_binding(source_info, visibility_scope, mutability, name, mode, num_patterns, var, ty, has_guard, - opt_match_place.map(|(x, y)| (x.cloned(), y))); + opt_match_place.map(|(x, y)| (x.cloned(), y)), + patterns[0].span); }); visibility_scope } @@ -1182,7 +1183,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { var_id: NodeId, var_ty: Ty<'tcx>, has_guard: ArmHasGuard, - opt_match_place: Option<(Option>, Span)>) + opt_match_place: Option<(Option>, Span)>, + pat_span: Span) { debug!("declare_binding(var_id={:?}, name={:?}, mode={:?}, var_ty={:?}, \ visibility_scope={:?}, source_info={:?})", @@ -1208,6 +1210,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // Instead, just abandon providing diagnostic info. opt_ty_info: None, opt_match_place, + pat_span, }))), }; let for_arm_body = self.local_decls.push(local.clone()); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 054bd69c361b9..c0c431804d8c1 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -763,6 +763,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { binding_mode, opt_ty_info, opt_match_place: Some((Some(place.clone()), span)), + pat_span: span, }))) }; self.var_indices.insert(var, LocalsForNode::One(local)); diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 42682c34407ca..bda80ff562c75 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -35,6 +35,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(try_trait)] #![feature(unicode_internals)] #![feature(step_trait)] +#![feature(slice_concat_ext)] #![recursion_limit="256"] diff --git a/src/librustc_mir/util/mod.rs b/src/librustc_mir/util/mod.rs index 78e9dd23e83ae..fe6fefe89fd66 100644 --- a/src/librustc_mir/util/mod.rs +++ b/src/librustc_mir/util/mod.rs @@ -31,14 +31,14 @@ pub use self::graphviz::write_node_label as write_graphviz_node_label; /// If possible, suggest replacing `ref` with `ref mut`. pub fn suggest_ref_mut<'cx, 'gcx, 'tcx>( tcx: ty::TyCtxt<'cx, 'gcx, 'tcx>, - pattern_span: Span, -) -> Option<(Span, String)> { - let hi_src = tcx.sess.codemap().span_to_snippet(pattern_span).unwrap(); + binding_span: Span, +) -> Option<(String)> { + let hi_src = tcx.sess.codemap().span_to_snippet(binding_span).unwrap(); if hi_src.starts_with("ref") && hi_src["ref".len()..].starts_with(Pattern_White_Space) { let replacement = format!("ref mut{}", &hi_src["ref".len()..]); - Some((pattern_span, replacement)) + Some(replacement) } else { None } diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs new file mode 100644 index 0000000000000..cdf5503f2a951 --- /dev/null +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -0,0 +1,267 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(nll)] + +enum Either { + One(X), + Two(X), +} + +struct X(Y); + +struct Y; + +pub fn main() { + let e = Either::One(X(Y)); + let mut em = Either::One(X(Y)); + + let r = &e; + let rm = &mut Either::One(X(Y)); + + let x = X(Y); + let mut xm = X(Y); + + let s = &x; + let sm = &mut X(Y); + + // -------- + + let X(_t) = *s; + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION s + if let Either::One(_t) = *r { } + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION r + while let Either::One(_t) = *r { } + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION r + match *r { + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION r + Either::One(_t) + | Either::Two(_t) => (), + } + match *r { + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION r + // (invalid but acceptable) + Either::One(_t) => (), + Either::Two(ref _t) => (), + } + + let X(_t) = *sm; + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION sm + if let Either::One(_t) = *rm { } + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION rm + while let Either::One(_t) = *rm { } + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION rm + match *rm { + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION rm + Either::One(_t) + | Either::Two(_t) => (), + } + match *rm { + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION rm + // (invalid but acceptable) + Either::One(_t) => (), + Either::Two(ref _t) => (), + } + match *rm { + //~^ ERROR cannot move + //~| HELP consider removing this dereference operator + //~| SUGGESTION rm + // (invalid but acceptable) + Either::One(_t) => (), + Either::Two(ref mut _t) => (), + } + + // -------- + + let &X(_t) = s; + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION X(_t) + if let &Either::One(_t) = r { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + while let &Either::One(_t) = r { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + match r { + //~^ ERROR cannot move + &Either::One(_t) + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + | &Either::Two(_t) => (), + // TODO: would really like a suggestion here too + } + match r { + //~^ ERROR cannot move + &Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &Either::Two(ref _t) => (), + } + match r { + //~^ ERROR cannot move + &Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + Either::Two(_t) => (), + } + fn f1(&X(_t): &X) { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION X(_t) + + let &mut X(_t) = sm; + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION X(_t) + if let &mut Either::One(_t) = rm { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + while let &mut Either::One(_t) = rm { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + match rm { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &mut Either::Two(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::Two(_t) + } + match rm { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &mut Either::Two(ref _t) => (), + } + match rm { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &mut Either::Two(ref mut _t) => (), + } + match rm { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + Either::Two(_t) => (), + } + fn f2(&mut X(_t): &mut X) { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION X(_t) + + // -------- + + let &X(_t) = &x; + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION X(_t) + if let &Either::One(_t) = &e { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + while let &Either::One(_t) = &e { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + match &e { + //~^ ERROR cannot move + &Either::One(_t) + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + | &Either::Two(_t) => (), + // TODO: would really like a suggestion here too + } + match &e { + //~^ ERROR cannot move + &Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &Either::Two(ref _t) => (), + } + match &e { + //~^ ERROR cannot move + &Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + Either::Two(_t) => (), + } + + let &mut X(_t) = &mut xm; + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION X(_t) + if let &mut Either::One(_t) = &mut em { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + while let &mut Either::One(_t) = &mut em { } + //~^ ERROR cannot move + //~| HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + match &mut em { + //~^ ERROR cannot move + &mut Either::One(_t) + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + | &mut Either::Two(_t) => (), + // TODO: would really like a suggestion here too + } + match &mut em { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &mut Either::Two(ref _t) => (), + } + match &mut em { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + &mut Either::Two(ref mut _t) => (), + } + match &mut em { + //~^ ERROR cannot move + &mut Either::One(_t) => (), + //~^ HELP consider removing this borrow operator + //~| SUGGESTION Either::One(_t) + Either::Two(_t) => (), + } +} diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr new file mode 100644 index 0000000000000..682ba88f55565 --- /dev/null +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -0,0 +1,666 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:37:17 + | +LL | let X(_t) = *s; + | -- ^^ + | | | + | | cannot move out of borrowed content + | | help: consider removing this dereference operator: `s` + | data moved here + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:37:11 + | +LL | let X(_t) = *s; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:41:30 + | +LL | if let Either::One(_t) = *r { } + | -- ^^ + | | | + | | cannot move out of borrowed content + | | help: consider removing this dereference operator: `r` + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:41:24 + | +LL | if let Either::One(_t) = *r { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:45:33 + | +LL | while let Either::One(_t) = *r { } + | -- ^^ + | | | + | | cannot move out of borrowed content + | | help: consider removing this dereference operator: `r` + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:45:27 + | +LL | while let Either::One(_t) = *r { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:49:11 + | +LL | match *r { + | ^^ + | | + | cannot move out of borrowed content + | help: consider removing this dereference operator: `r` +... +LL | Either::One(_t) + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:53:21 + | +LL | Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:56:11 + | +LL | match *r { + | ^^ + | | + | cannot move out of borrowed content + | help: consider removing this dereference operator: `r` +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:61:21 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:65:17 + | +LL | let X(_t) = *sm; + | -- ^^^ + | | | + | | cannot move out of borrowed content + | | help: consider removing this dereference operator: `sm` + | data moved here + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:65:11 + | +LL | let X(_t) = *sm; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:69:30 + | +LL | if let Either::One(_t) = *rm { } + | -- ^^^ + | | | + | | cannot move out of borrowed content + | | help: consider removing this dereference operator: `rm` + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:69:24 + | +LL | if let Either::One(_t) = *rm { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:73:33 + | +LL | while let Either::One(_t) = *rm { } + | -- ^^^ + | | | + | | cannot move out of borrowed content + | | help: consider removing this dereference operator: `rm` + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:73:27 + | +LL | while let Either::One(_t) = *rm { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:77:11 + | +LL | match *rm { + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing this dereference operator: `rm` +... +LL | Either::One(_t) + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:81:21 + | +LL | Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:84:11 + | +LL | match *rm { + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing this dereference operator: `rm` +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:89:21 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:92:11 + | +LL | match *rm { + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing this dereference operator: `rm` +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:97:21 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:103:18 + | +LL | let &X(_t) = s; + | ------ ^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `X(_t)` + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:103:12 + | +LL | let &X(_t) = s; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:107:31 + | +LL | if let &Either::One(_t) = r { } + | ---------------- ^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:107:25 + | +LL | if let &Either::One(_t) = r { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:111:34 + | +LL | while let &Either::One(_t) = r { } + | ---------------- ^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:111:28 + | +LL | while let &Either::One(_t) = r { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:115:11 + | +LL | match r { + | ^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &Either::One(_t) + | ---------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:117:22 + | +LL | &Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:123:11 + | +LL | match r { + | ^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &Either::One(_t) => (), + | ---------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:125:22 + | +LL | &Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:130:11 + | +LL | match r { + | ^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &Either::One(_t) => (), + | ---------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:132:22 + | +LL | &Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:142:22 + | +LL | let &mut X(_t) = sm; + | ---------- ^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `X(_t)` + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:142:16 + | +LL | let &mut X(_t) = sm; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:146:35 + | +LL | if let &mut Either::One(_t) = rm { } + | -------------------- ^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:146:29 + | +LL | if let &mut Either::One(_t) = rm { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:150:38 + | +LL | while let &mut Either::One(_t) = rm { } + | -------------------- ^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:150:32 + | +LL | while let &mut Either::One(_t) = rm { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:154:11 + | +LL | match rm { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -- data moved here +... +LL | &mut Either::Two(_t) => (), + | -- ... and here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:156:26 + | +LL | &mut Either::One(_t) => (), + | ^^ +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:159:26 + | +LL | &mut Either::Two(_t) => (), + | ^^ +help: consider removing this borrow operator + | +LL | Either::One(_t) => (), + | ^^^^^^^^^^^^^^^ +help: consider removing this borrow operator + | +LL | Either::Two(_t) => (), + | ^^^^^^^^^^^^^^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:163:11 + | +LL | match rm { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:165:26 + | +LL | &mut Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:170:11 + | +LL | match rm { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:172:26 + | +LL | &mut Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:177:11 + | +LL | match rm { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:179:26 + | +LL | &mut Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:191:18 + | +LL | let &X(_t) = &x; + | ------ ^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `X(_t)` + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:191:12 + | +LL | let &X(_t) = &x; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:195:31 + | +LL | if let &Either::One(_t) = &e { } + | ---------------- ^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:195:25 + | +LL | if let &Either::One(_t) = &e { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:199:34 + | +LL | while let &Either::One(_t) = &e { } + | ---------------- ^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:199:28 + | +LL | while let &Either::One(_t) = &e { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:203:11 + | +LL | match &e { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &Either::One(_t) + | ---------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:205:22 + | +LL | &Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:211:11 + | +LL | match &e { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &Either::One(_t) => (), + | ---------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:213:22 + | +LL | &Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:218:11 + | +LL | match &e { + | ^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &Either::One(_t) => (), + | ---------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:220:22 + | +LL | &Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:226:22 + | +LL | let &mut X(_t) = &mut xm; + | ---------- ^^^^^^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `X(_t)` + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:226:16 + | +LL | let &mut X(_t) = &mut xm; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:230:35 + | +LL | if let &mut Either::One(_t) = &mut em { } + | -------------------- ^^^^^^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:230:29 + | +LL | if let &mut Either::One(_t) = &mut em { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:234:38 + | +LL | while let &mut Either::One(_t) = &mut em { } + | -------------------- ^^^^^^^ cannot move out of borrowed content + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:234:32 + | +LL | while let &mut Either::One(_t) = &mut em { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:238:11 + | +LL | match &mut em { + | ^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:240:26 + | +LL | &mut Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:246:11 + | +LL | match &mut em { + | ^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:248:26 + | +LL | &mut Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:253:11 + | +LL | match &mut em { + | ^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:255:26 + | +LL | &mut Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:260:11 + | +LL | match &mut em { + | ^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut Either::One(_t) => (), + | -------------------- + | | | + | | data moved here + | help: consider removing this borrow operator: `Either::One(_t)` + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:262:26 + | +LL | &mut Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:137:11 + | +LL | fn f1(&X(_t): &X) { } + | ^^^--^ + | | | + | | data moved here + | cannot move out of borrowed content + | help: consider removing this borrow operator: `X(_t)` + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:137:14 + | +LL | fn f1(&X(_t): &X) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:184:11 + | +LL | fn f2(&mut X(_t): &mut X) { } + | ^^^^^^^--^ + | | | + | | data moved here + | cannot move out of borrowed content + | help: consider removing this borrow operator: `X(_t)` + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:184:18 + | +LL | fn f2(&mut X(_t): &mut X) { } + | ^^ + +error: aborting due to 39 previous errors + +For more information about this error, try `rustc --explain E0507`. From 3a5812bdd97ee0ad961fa6680f91f26c34a94018 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 7 Aug 2018 01:27:04 -0700 Subject: [PATCH 03/27] Add more TODOs --- src/test/ui/suggestions/dont-suggest-ref.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index cdf5503f2a951..2cec232b20895 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -57,9 +57,9 @@ pub fn main() { //~^ ERROR cannot move //~| HELP consider removing this dereference operator //~| SUGGESTION r - // (invalid but acceptable) Either::One(_t) => (), Either::Two(ref _t) => (), + // TODO: should suggest removing `ref` too } let X(_t) = *sm; @@ -85,17 +85,17 @@ pub fn main() { //~^ ERROR cannot move //~| HELP consider removing this dereference operator //~| SUGGESTION rm - // (invalid but acceptable) Either::One(_t) => (), Either::Two(ref _t) => (), + // TODO: should suggest removing `ref` too } match *rm { //~^ ERROR cannot move //~| HELP consider removing this dereference operator //~| SUGGESTION rm - // (invalid but acceptable) Either::One(_t) => (), Either::Two(ref mut _t) => (), + // TODO: should suggest removing `ref mut` too } // -------- From 1e87908c5284bd9d9d952a0ce98bfac2c0339a40 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 7 Aug 2018 16:16:37 -0700 Subject: [PATCH 04/27] Accept whitespace between `&` and `mut` --- src/librustc_mir/borrow_check/move_errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index b89a8fa88b3e6..c641e960ac5aa 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -404,7 +404,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { .span_to_snippet(pat_span) .unwrap(); if pat_snippet.starts_with('&') { - let pat_snippet = &pat_snippet[1..]; + let pat_snippet = pat_snippet[1..].trim_left(); let suggestion; if pat_snippet.starts_with("mut") && pat_snippet["mut".len()..].starts_with(Pattern_White_Space) From 54ddb36ce7b4d403e986cc8fe9b121bb3c74a8ff Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 7 Aug 2018 23:34:01 -0700 Subject: [PATCH 05/27] Test move errors for index expressions --- src/test/ui/suggestions/dont-suggest-ref.rs | 74 ++++ .../ui/suggestions/dont-suggest-ref.stderr | 319 +++++++++++++----- 2 files changed, 313 insertions(+), 80 deletions(-) diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index 2cec232b20895..c9a5985b8bb6d 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -32,6 +32,16 @@ pub fn main() { let s = &x; let sm = &mut X(Y); + let ve = vec![Either::One(X(Y))]; + + let vr = &ve; + let vrm = &mut vec![Either::One(X(Y))]; + + let vx = vec![X(Y)]; + + let vs_ = &vx; + let vsm = &mut vec![X(Y)]; + // -------- let X(_t) = *s; @@ -98,6 +108,70 @@ pub fn main() { // TODO: should suggest removing `ref mut` too } + let X(_t) = vs_[0]; + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vs_[0] + if let Either::One(_t) = vr[0] { } + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vr[0] + while let Either::One(_t) = vr[0] { } + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vr[0] + match vr[0] { + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vr[0] + Either::One(_t) + | Either::Two(_t) => (), + } + match vr[0] { + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vr[0] + Either::One(_t) => (), + Either::Two(ref _t) => (), + // TODO: should suggest removing `ref` too + } + + let X(_t) = vsm[0]; + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vsm[0] + if let Either::One(_t) = vrm[0] { } + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vrm[0] + while let Either::One(_t) = vrm[0] { } + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vrm[0] + match vrm[0] { + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vrm[0] + Either::One(_t) + | Either::Two(_t) => (), + } + match vrm[0] { + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vrm[0] + Either::One(_t) => (), + Either::Two(ref _t) => (), + // TODO: should suggest removing `ref` too + } + match vrm[0] { + //~^ ERROR cannot move + //~| HELP consider using a reference instead + //~| SUGGESTION &vrm[0] + Either::One(_t) => (), + Either::Two(ref mut _t) => (), + // TODO: should suggest removing `ref mut` too + } + // -------- let &X(_t) = s; diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 682ba88f55565..d27c028fe47d3 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:37:17 + --> $DIR/dont-suggest-ref.rs:47:17 | LL | let X(_t) = *s; | -- ^^ @@ -9,13 +9,13 @@ LL | let X(_t) = *s; | data moved here | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:37:11 + --> $DIR/dont-suggest-ref.rs:47:11 | LL | let X(_t) = *s; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:41:30 + --> $DIR/dont-suggest-ref.rs:51:30 | LL | if let Either::One(_t) = *r { } | -- ^^ @@ -25,13 +25,13 @@ LL | if let Either::One(_t) = *r { } | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:41:24 + --> $DIR/dont-suggest-ref.rs:51:24 | LL | if let Either::One(_t) = *r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:45:33 + --> $DIR/dont-suggest-ref.rs:55:33 | LL | while let Either::One(_t) = *r { } | -- ^^ @@ -41,13 +41,13 @@ LL | while let Either::One(_t) = *r { } | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:45:27 + --> $DIR/dont-suggest-ref.rs:55:27 | LL | while let Either::One(_t) = *r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:49:11 + --> $DIR/dont-suggest-ref.rs:59:11 | LL | match *r { | ^^ @@ -59,13 +59,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:53:21 + --> $DIR/dont-suggest-ref.rs:63:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:56:11 + --> $DIR/dont-suggest-ref.rs:66:11 | LL | match *r { | ^^ @@ -77,13 +77,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:61:21 + --> $DIR/dont-suggest-ref.rs:70:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:65:17 + --> $DIR/dont-suggest-ref.rs:75:17 | LL | let X(_t) = *sm; | -- ^^^ @@ -93,13 +93,13 @@ LL | let X(_t) = *sm; | data moved here | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:65:11 + --> $DIR/dont-suggest-ref.rs:75:11 | LL | let X(_t) = *sm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:69:30 + --> $DIR/dont-suggest-ref.rs:79:30 | LL | if let Either::One(_t) = *rm { } | -- ^^^ @@ -109,13 +109,13 @@ LL | if let Either::One(_t) = *rm { } | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:69:24 + --> $DIR/dont-suggest-ref.rs:79:24 | LL | if let Either::One(_t) = *rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:73:33 + --> $DIR/dont-suggest-ref.rs:83:33 | LL | while let Either::One(_t) = *rm { } | -- ^^^ @@ -125,13 +125,13 @@ LL | while let Either::One(_t) = *rm { } | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:73:27 + --> $DIR/dont-suggest-ref.rs:83:27 | LL | while let Either::One(_t) = *rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:77:11 + --> $DIR/dont-suggest-ref.rs:87:11 | LL | match *rm { | ^^^ @@ -143,13 +143,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:81:21 + --> $DIR/dont-suggest-ref.rs:91:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:84:11 + --> $DIR/dont-suggest-ref.rs:94:11 | LL | match *rm { | ^^^ @@ -161,13 +161,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:89:21 + --> $DIR/dont-suggest-ref.rs:98:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:92:11 + --> $DIR/dont-suggest-ref.rs:102:11 | LL | match *rm { | ^^^ @@ -179,13 +179,172 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:97:21 + --> $DIR/dont-suggest-ref.rs:106:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:103:18 + --> $DIR/dont-suggest-ref.rs:111:17 + | +LL | let X(_t) = vs_[0]; + | -- ^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:111:11 + | +LL | let X(_t) = vs_[0]; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:115:30 + | +LL | if let Either::One(_t) = vr[0] { } + | -- ^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:115:24 + | +LL | if let Either::One(_t) = vr[0] { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:119:33 + | +LL | while let Either::One(_t) = vr[0] { } + | -- ^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:119:27 + | +LL | while let Either::One(_t) = vr[0] { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:123:11 + | +LL | match vr[0] { + | ^^^^^ cannot move out of borrowed content +... +LL | Either::One(_t) + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:127:21 + | +LL | Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:130:11 + | +LL | match vr[0] { + | ^^^^^ cannot move out of borrowed content +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:134:21 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:139:17 + | +LL | let X(_t) = vsm[0]; + | -- ^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because _t has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:139:11 + | +LL | let X(_t) = vsm[0]; + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:143:30 + | +LL | if let Either::One(_t) = vrm[0] { } + | -- ^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:143:24 + | +LL | if let Either::One(_t) = vrm[0] { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:147:33 + | +LL | while let Either::One(_t) = vrm[0] { } + | -- ^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:147:27 + | +LL | while let Either::One(_t) = vrm[0] { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:151:11 + | +LL | match vrm[0] { + | ^^^^^^ cannot move out of borrowed content +... +LL | Either::One(_t) + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:155:21 + | +LL | Either::One(_t) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:158:11 + | +LL | match vrm[0] { + | ^^^^^^ cannot move out of borrowed content +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:162:21 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:166:11 + | +LL | match vrm[0] { + | ^^^^^^ cannot move out of borrowed content +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because _t has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:170:21 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:177:18 | LL | let &X(_t) = s; | ------ ^ cannot move out of borrowed content @@ -194,13 +353,13 @@ LL | let &X(_t) = s; | help: consider removing this borrow operator: `X(_t)` | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:103:12 + --> $DIR/dont-suggest-ref.rs:177:12 | LL | let &X(_t) = s; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:107:31 + --> $DIR/dont-suggest-ref.rs:181:31 | LL | if let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content @@ -209,13 +368,13 @@ LL | if let &Either::One(_t) = r { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:107:25 + --> $DIR/dont-suggest-ref.rs:181:25 | LL | if let &Either::One(_t) = r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:111:34 + --> $DIR/dont-suggest-ref.rs:185:34 | LL | while let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content @@ -224,13 +383,13 @@ LL | while let &Either::One(_t) = r { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:111:28 + --> $DIR/dont-suggest-ref.rs:185:28 | LL | while let &Either::One(_t) = r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:115:11 + --> $DIR/dont-suggest-ref.rs:189:11 | LL | match r { | ^ cannot move out of borrowed content @@ -242,13 +401,13 @@ LL | &Either::One(_t) | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:117:22 + --> $DIR/dont-suggest-ref.rs:191:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:123:11 + --> $DIR/dont-suggest-ref.rs:197:11 | LL | match r { | ^ cannot move out of borrowed content @@ -260,13 +419,13 @@ LL | &Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:125:22 + --> $DIR/dont-suggest-ref.rs:199:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:130:11 + --> $DIR/dont-suggest-ref.rs:204:11 | LL | match r { | ^ cannot move out of borrowed content @@ -278,13 +437,13 @@ LL | &Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:132:22 + --> $DIR/dont-suggest-ref.rs:206:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:142:22 + --> $DIR/dont-suggest-ref.rs:216:22 | LL | let &mut X(_t) = sm; | ---------- ^^ cannot move out of borrowed content @@ -293,13 +452,13 @@ LL | let &mut X(_t) = sm; | help: consider removing this borrow operator: `X(_t)` | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:142:16 + --> $DIR/dont-suggest-ref.rs:216:16 | LL | let &mut X(_t) = sm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:146:35 + --> $DIR/dont-suggest-ref.rs:220:35 | LL | if let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content @@ -308,13 +467,13 @@ LL | if let &mut Either::One(_t) = rm { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:146:29 + --> $DIR/dont-suggest-ref.rs:220:29 | LL | if let &mut Either::One(_t) = rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:150:38 + --> $DIR/dont-suggest-ref.rs:224:38 | LL | while let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content @@ -323,13 +482,13 @@ LL | while let &mut Either::One(_t) = rm { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:150:32 + --> $DIR/dont-suggest-ref.rs:224:32 | LL | while let &mut Either::One(_t) = rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:154:11 + --> $DIR/dont-suggest-ref.rs:228:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -341,12 +500,12 @@ LL | &mut Either::Two(_t) => (), | -- ... and here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:156:26 + --> $DIR/dont-suggest-ref.rs:230:26 | LL | &mut Either::One(_t) => (), | ^^ note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:159:26 + --> $DIR/dont-suggest-ref.rs:233:26 | LL | &mut Either::Two(_t) => (), | ^^ @@ -360,7 +519,7 @@ LL | Either::Two(_t) => (), | ^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:163:11 + --> $DIR/dont-suggest-ref.rs:237:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -372,13 +531,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:165:26 + --> $DIR/dont-suggest-ref.rs:239:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:170:11 + --> $DIR/dont-suggest-ref.rs:244:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -390,13 +549,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:172:26 + --> $DIR/dont-suggest-ref.rs:246:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:177:11 + --> $DIR/dont-suggest-ref.rs:251:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -408,13 +567,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:179:26 + --> $DIR/dont-suggest-ref.rs:253:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:191:18 + --> $DIR/dont-suggest-ref.rs:265:18 | LL | let &X(_t) = &x; | ------ ^^ cannot move out of borrowed content @@ -423,13 +582,13 @@ LL | let &X(_t) = &x; | help: consider removing this borrow operator: `X(_t)` | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:191:12 + --> $DIR/dont-suggest-ref.rs:265:12 | LL | let &X(_t) = &x; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:195:31 + --> $DIR/dont-suggest-ref.rs:269:31 | LL | if let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -438,13 +597,13 @@ LL | if let &Either::One(_t) = &e { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:195:25 + --> $DIR/dont-suggest-ref.rs:269:25 | LL | if let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:199:34 + --> $DIR/dont-suggest-ref.rs:273:34 | LL | while let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -453,13 +612,13 @@ LL | while let &Either::One(_t) = &e { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:199:28 + --> $DIR/dont-suggest-ref.rs:273:28 | LL | while let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:203:11 + --> $DIR/dont-suggest-ref.rs:277:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -471,13 +630,13 @@ LL | &Either::One(_t) | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:205:22 + --> $DIR/dont-suggest-ref.rs:279:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:211:11 + --> $DIR/dont-suggest-ref.rs:285:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -489,13 +648,13 @@ LL | &Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:213:22 + --> $DIR/dont-suggest-ref.rs:287:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:218:11 + --> $DIR/dont-suggest-ref.rs:292:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -507,13 +666,13 @@ LL | &Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:220:22 + --> $DIR/dont-suggest-ref.rs:294:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:226:22 + --> $DIR/dont-suggest-ref.rs:300:22 | LL | let &mut X(_t) = &mut xm; | ---------- ^^^^^^^ cannot move out of borrowed content @@ -522,13 +681,13 @@ LL | let &mut X(_t) = &mut xm; | help: consider removing this borrow operator: `X(_t)` | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:226:16 + --> $DIR/dont-suggest-ref.rs:300:16 | LL | let &mut X(_t) = &mut xm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:230:35 + --> $DIR/dont-suggest-ref.rs:304:35 | LL | if let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -537,13 +696,13 @@ LL | if let &mut Either::One(_t) = &mut em { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:230:29 + --> $DIR/dont-suggest-ref.rs:304:29 | LL | if let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:234:38 + --> $DIR/dont-suggest-ref.rs:308:38 | LL | while let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -552,13 +711,13 @@ LL | while let &mut Either::One(_t) = &mut em { } | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:234:32 + --> $DIR/dont-suggest-ref.rs:308:32 | LL | while let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:238:11 + --> $DIR/dont-suggest-ref.rs:312:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -570,13 +729,13 @@ LL | &mut Either::One(_t) | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:240:26 + --> $DIR/dont-suggest-ref.rs:314:26 | LL | &mut Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:246:11 + --> $DIR/dont-suggest-ref.rs:320:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -588,13 +747,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:248:26 + --> $DIR/dont-suggest-ref.rs:322:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:253:11 + --> $DIR/dont-suggest-ref.rs:327:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -606,13 +765,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:255:26 + --> $DIR/dont-suggest-ref.rs:329:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:260:11 + --> $DIR/dont-suggest-ref.rs:334:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -624,13 +783,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing this borrow operator: `Either::One(_t)` | note: move occurs because _t has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:262:26 + --> $DIR/dont-suggest-ref.rs:336:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:137:11 + --> $DIR/dont-suggest-ref.rs:211:11 | LL | fn f1(&X(_t): &X) { } | ^^^--^ @@ -640,13 +799,13 @@ LL | fn f1(&X(_t): &X) { } | help: consider removing this borrow operator: `X(_t)` | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:137:14 + --> $DIR/dont-suggest-ref.rs:211:14 | LL | fn f1(&X(_t): &X) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:184:11 + --> $DIR/dont-suggest-ref.rs:258:11 | LL | fn f2(&mut X(_t): &mut X) { } | ^^^^^^^--^ @@ -656,11 +815,11 @@ LL | fn f2(&mut X(_t): &mut X) { } | help: consider removing this borrow operator: `X(_t)` | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:184:18 + --> $DIR/dont-suggest-ref.rs:258:18 | LL | fn f2(&mut X(_t): &mut X) { } | ^^ -error: aborting due to 39 previous errors +error: aborting due to 50 previous errors For more information about this error, try `rustc --explain E0507`. From 8080bdf275e7c12b8629c3b598c6ab18748957ee Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 7 Aug 2018 23:44:35 -0700 Subject: [PATCH 06/27] Fix move errors for index expressions The suggestion logic gave up too early, which kept it from suggesting borrowing index expressions. --- src/librustc_mir/borrow_check/move_errors.rs | 46 ++++++-------- .../ui/suggestions/dont-suggest-ref.stderr | 61 +++++++++++++------ 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index c641e960ac5aa..961d8eb7b948b 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -341,38 +341,32 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { move_from, .. } => { - let mut suggest_change_head_expr = false; - match move_from { + let try_remove_deref = match move_from { Place::Projection(box PlaceProjection { elem: ProjectionElem::Deref, .. - }) => { - // This is false for (e.g.) index expressions `a[b]`, - // which roughly desugar to `*Index::index(&a, b)` or - // `*IndexMut::index_mut(&mut a, b)`. - if snippet.starts_with('*') { - err.span_suggestion( - span, - "consider removing this dereference operator", - (&snippet[1..]).to_owned(), - ); - suggest_change_head_expr = true; - } - } - _ => { - err.span_suggestion( - span, - "consider using a reference instead", - format!("&{}", snippet), - ); - suggest_change_head_expr = true; - } + }) => true, + _ => false, + }; + if try_remove_deref && snippet.starts_with('*') { + // This is false for (e.g.) index expressions `a[b]`, + // which roughly desugar to `*Index::index(&a, b)` or + // `*IndexMut::index_mut(&mut a, b)`. + err.span_suggestion( + span, + "consider removing this dereference operator", + snippet[1..].to_owned(), + ); + } else { + err.span_suggestion( + span, + "consider using a reference instead", + format!("&{}", snippet), + ); } + binds_to.sort(); binds_to.dedup(); - if !suggest_change_head_expr { - self.add_move_error_suggestions(err, &binds_to); - } self.add_move_error_labels(err, &binds_to); } GroupedMoveError::MovesFromValue { mut binds_to, .. } => { diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index d27c028fe47d3..16f11f9b10ab2 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -188,8 +188,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:111:17 | LL | let X(_t) = vs_[0]; - | -- ^^^^^^ cannot move out of borrowed content - | | + | -- ^^^^^^ + | | | + | | cannot move out of borrowed content + | | help: consider using a reference instead: `&vs_[0]` | data moved here | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait @@ -202,8 +204,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:115:30 | LL | if let Either::One(_t) = vr[0] { } - | -- ^^^^^ cannot move out of borrowed content - | | + | -- ^^^^^ + | | | + | | cannot move out of borrowed content + | | help: consider using a reference instead: `&vr[0]` | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait @@ -216,8 +220,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:119:33 | LL | while let Either::One(_t) = vr[0] { } - | -- ^^^^^ cannot move out of borrowed content - | | + | -- ^^^^^ + | | | + | | cannot move out of borrowed content + | | help: consider using a reference instead: `&vr[0]` | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait @@ -230,7 +236,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:123:11 | LL | match vr[0] { - | ^^^^^ cannot move out of borrowed content + | ^^^^^ + | | + | cannot move out of borrowed content + | help: consider using a reference instead: `&vr[0]` ... LL | Either::One(_t) | -- data moved here @@ -245,7 +254,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:130:11 | LL | match vr[0] { - | ^^^^^ cannot move out of borrowed content + | ^^^^^ + | | + | cannot move out of borrowed content + | help: consider using a reference instead: `&vr[0]` ... LL | Either::One(_t) => (), | -- data moved here @@ -260,8 +272,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:139:17 | LL | let X(_t) = vsm[0]; - | -- ^^^^^^ cannot move out of borrowed content - | | + | -- ^^^^^^ + | | | + | | cannot move out of borrowed content + | | help: consider using a reference instead: `&vsm[0]` | data moved here | note: move occurs because _t has type `Y`, which does not implement the `Copy` trait @@ -274,8 +288,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:143:30 | LL | if let Either::One(_t) = vrm[0] { } - | -- ^^^^^^ cannot move out of borrowed content - | | + | -- ^^^^^^ + | | | + | | cannot move out of borrowed content + | | help: consider using a reference instead: `&vrm[0]` | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait @@ -288,8 +304,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:147:33 | LL | while let Either::One(_t) = vrm[0] { } - | -- ^^^^^^ cannot move out of borrowed content - | | + | -- ^^^^^^ + | | | + | | cannot move out of borrowed content + | | help: consider using a reference instead: `&vrm[0]` | data moved here | note: move occurs because _t has type `X`, which does not implement the `Copy` trait @@ -302,7 +320,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:151:11 | LL | match vrm[0] { - | ^^^^^^ cannot move out of borrowed content + | ^^^^^^ + | | + | cannot move out of borrowed content + | help: consider using a reference instead: `&vrm[0]` ... LL | Either::One(_t) | -- data moved here @@ -317,7 +338,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:158:11 | LL | match vrm[0] { - | ^^^^^^ cannot move out of borrowed content + | ^^^^^^ + | | + | cannot move out of borrowed content + | help: consider using a reference instead: `&vrm[0]` ... LL | Either::One(_t) => (), | -- data moved here @@ -332,7 +356,10 @@ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:166:11 | LL | match vrm[0] { - | ^^^^^^ cannot move out of borrowed content + | ^^^^^^ + | | + | cannot move out of borrowed content + | help: consider using a reference instead: `&vrm[0]` ... LL | Either::One(_t) => (), | -- data moved here From b05e9a7f7724281c43ee7225c4f43cff9e05e617 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Sun, 12 Aug 2018 13:14:03 -0700 Subject: [PATCH 07/27] Add backquotes around variable name --- src/librustc_mir/borrow_check/move_errors.rs | 2 +- .../ui/suggestions/dont-suggest-ref.stderr | 102 +++++++++--------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 961d8eb7b948b..7ddb5a4536b23 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -435,7 +435,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { err.span_note( binding_span, &format!( - "move occurs because {} has type `{}`, \ + "move occurs because `{}` has type `{}`, \ which does not implement the `Copy` trait", bind_to.name.unwrap(), bind_to.ty diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 16f11f9b10ab2..0493a9fa6e8ac 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -8,7 +8,7 @@ LL | let X(_t) = *s; | | help: consider removing this dereference operator: `s` | data moved here | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:47:11 | LL | let X(_t) = *s; @@ -24,7 +24,7 @@ LL | if let Either::One(_t) = *r { } | | help: consider removing this dereference operator: `r` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:51:24 | LL | if let Either::One(_t) = *r { } @@ -40,7 +40,7 @@ LL | while let Either::One(_t) = *r { } | | help: consider removing this dereference operator: `r` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:55:27 | LL | while let Either::One(_t) = *r { } @@ -58,7 +58,7 @@ LL | match *r { LL | Either::One(_t) | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:63:21 | LL | Either::One(_t) @@ -76,7 +76,7 @@ LL | match *r { LL | Either::One(_t) => (), | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:70:21 | LL | Either::One(_t) => (), @@ -92,7 +92,7 @@ LL | let X(_t) = *sm; | | help: consider removing this dereference operator: `sm` | data moved here | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:75:11 | LL | let X(_t) = *sm; @@ -108,7 +108,7 @@ LL | if let Either::One(_t) = *rm { } | | help: consider removing this dereference operator: `rm` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:79:24 | LL | if let Either::One(_t) = *rm { } @@ -124,7 +124,7 @@ LL | while let Either::One(_t) = *rm { } | | help: consider removing this dereference operator: `rm` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:83:27 | LL | while let Either::One(_t) = *rm { } @@ -142,7 +142,7 @@ LL | match *rm { LL | Either::One(_t) | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:91:21 | LL | Either::One(_t) @@ -160,7 +160,7 @@ LL | match *rm { LL | Either::One(_t) => (), | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:98:21 | LL | Either::One(_t) => (), @@ -178,7 +178,7 @@ LL | match *rm { LL | Either::One(_t) => (), | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:106:21 | LL | Either::One(_t) => (), @@ -194,7 +194,7 @@ LL | let X(_t) = vs_[0]; | | help: consider using a reference instead: `&vs_[0]` | data moved here | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:111:11 | LL | let X(_t) = vs_[0]; @@ -210,7 +210,7 @@ LL | if let Either::One(_t) = vr[0] { } | | help: consider using a reference instead: `&vr[0]` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:115:24 | LL | if let Either::One(_t) = vr[0] { } @@ -226,7 +226,7 @@ LL | while let Either::One(_t) = vr[0] { } | | help: consider using a reference instead: `&vr[0]` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:119:27 | LL | while let Either::One(_t) = vr[0] { } @@ -244,7 +244,7 @@ LL | match vr[0] { LL | Either::One(_t) | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:127:21 | LL | Either::One(_t) @@ -262,7 +262,7 @@ LL | match vr[0] { LL | Either::One(_t) => (), | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:134:21 | LL | Either::One(_t) => (), @@ -278,7 +278,7 @@ LL | let X(_t) = vsm[0]; | | help: consider using a reference instead: `&vsm[0]` | data moved here | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:139:11 | LL | let X(_t) = vsm[0]; @@ -294,7 +294,7 @@ LL | if let Either::One(_t) = vrm[0] { } | | help: consider using a reference instead: `&vrm[0]` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:143:24 | LL | if let Either::One(_t) = vrm[0] { } @@ -310,7 +310,7 @@ LL | while let Either::One(_t) = vrm[0] { } | | help: consider using a reference instead: `&vrm[0]` | data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:147:27 | LL | while let Either::One(_t) = vrm[0] { } @@ -328,7 +328,7 @@ LL | match vrm[0] { LL | Either::One(_t) | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:155:21 | LL | Either::One(_t) @@ -346,7 +346,7 @@ LL | match vrm[0] { LL | Either::One(_t) => (), | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:162:21 | LL | Either::One(_t) => (), @@ -364,7 +364,7 @@ LL | match vrm[0] { LL | Either::One(_t) => (), | -- data moved here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:170:21 | LL | Either::One(_t) => (), @@ -379,7 +379,7 @@ LL | let &X(_t) = s; | | data moved here | help: consider removing this borrow operator: `X(_t)` | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:177:12 | LL | let &X(_t) = s; @@ -394,7 +394,7 @@ LL | if let &Either::One(_t) = r { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:181:25 | LL | if let &Either::One(_t) = r { } @@ -409,7 +409,7 @@ LL | while let &Either::One(_t) = r { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:185:28 | LL | while let &Either::One(_t) = r { } @@ -427,7 +427,7 @@ LL | &Either::One(_t) | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:191:22 | LL | &Either::One(_t) @@ -445,7 +445,7 @@ LL | &Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:199:22 | LL | &Either::One(_t) => (), @@ -463,7 +463,7 @@ LL | &Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:206:22 | LL | &Either::One(_t) => (), @@ -478,7 +478,7 @@ LL | let &mut X(_t) = sm; | | data moved here | help: consider removing this borrow operator: `X(_t)` | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:216:16 | LL | let &mut X(_t) = sm; @@ -493,7 +493,7 @@ LL | if let &mut Either::One(_t) = rm { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:220:29 | LL | if let &mut Either::One(_t) = rm { } @@ -508,7 +508,7 @@ LL | while let &mut Either::One(_t) = rm { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:224:32 | LL | while let &mut Either::One(_t) = rm { } @@ -526,12 +526,12 @@ LL | &mut Either::One(_t) => (), LL | &mut Either::Two(_t) => (), | -- ... and here | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:230:26 | LL | &mut Either::One(_t) => (), | ^^ -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:233:26 | LL | &mut Either::Two(_t) => (), @@ -557,7 +557,7 @@ LL | &mut Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:239:26 | LL | &mut Either::One(_t) => (), @@ -575,7 +575,7 @@ LL | &mut Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:246:26 | LL | &mut Either::One(_t) => (), @@ -593,7 +593,7 @@ LL | &mut Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:253:26 | LL | &mut Either::One(_t) => (), @@ -608,7 +608,7 @@ LL | let &X(_t) = &x; | | data moved here | help: consider removing this borrow operator: `X(_t)` | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:265:12 | LL | let &X(_t) = &x; @@ -623,7 +623,7 @@ LL | if let &Either::One(_t) = &e { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:269:25 | LL | if let &Either::One(_t) = &e { } @@ -638,7 +638,7 @@ LL | while let &Either::One(_t) = &e { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:273:28 | LL | while let &Either::One(_t) = &e { } @@ -656,7 +656,7 @@ LL | &Either::One(_t) | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:279:22 | LL | &Either::One(_t) @@ -674,7 +674,7 @@ LL | &Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:287:22 | LL | &Either::One(_t) => (), @@ -692,7 +692,7 @@ LL | &Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:294:22 | LL | &Either::One(_t) => (), @@ -707,7 +707,7 @@ LL | let &mut X(_t) = &mut xm; | | data moved here | help: consider removing this borrow operator: `X(_t)` | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:300:16 | LL | let &mut X(_t) = &mut xm; @@ -722,7 +722,7 @@ LL | if let &mut Either::One(_t) = &mut em { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:304:29 | LL | if let &mut Either::One(_t) = &mut em { } @@ -737,7 +737,7 @@ LL | while let &mut Either::One(_t) = &mut em { } | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:308:32 | LL | while let &mut Either::One(_t) = &mut em { } @@ -755,7 +755,7 @@ LL | &mut Either::One(_t) | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:314:26 | LL | &mut Either::One(_t) @@ -773,7 +773,7 @@ LL | &mut Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:322:26 | LL | &mut Either::One(_t) => (), @@ -791,7 +791,7 @@ LL | &mut Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:329:26 | LL | &mut Either::One(_t) => (), @@ -809,7 +809,7 @@ LL | &mut Either::One(_t) => (), | | data moved here | help: consider removing this borrow operator: `Either::One(_t)` | -note: move occurs because _t has type `X`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:336:26 | LL | &mut Either::One(_t) => (), @@ -825,7 +825,7 @@ LL | fn f1(&X(_t): &X) { } | cannot move out of borrowed content | help: consider removing this borrow operator: `X(_t)` | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:211:14 | LL | fn f1(&X(_t): &X) { } @@ -841,7 +841,7 @@ LL | fn f2(&mut X(_t): &mut X) { } | cannot move out of borrowed content | help: consider removing this borrow operator: `X(_t)` | -note: move occurs because _t has type `Y`, which does not implement the `Copy` trait +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:258:18 | LL | fn f2(&mut X(_t): &mut X) { } From 701c74e067a76e84725b8efeaae7234512058667 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Sun, 12 Aug 2018 13:27:14 -0700 Subject: [PATCH 08/27] Make move error suggestions clearer --- src/librustc_mir/borrow_check/move_errors.rs | 7 +- src/test/ui/suggestions/dont-suggest-ref.rs | 80 +++++++++---------- .../ui/suggestions/dont-suggest-ref.stderr | 80 +++++++++---------- 3 files changed, 85 insertions(+), 82 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 7ddb5a4536b23..ce7206be4c32c 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -354,7 +354,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { // `*IndexMut::index_mut(&mut a, b)`. err.span_suggestion( span, - "consider removing this dereference operator", + "consider removing the `*`", snippet[1..].to_owned(), ); } else { @@ -400,16 +400,19 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { if pat_snippet.starts_with('&') { let pat_snippet = pat_snippet[1..].trim_left(); let suggestion; + let to_remove; if pat_snippet.starts_with("mut") && pat_snippet["mut".len()..].starts_with(Pattern_White_Space) { suggestion = pat_snippet["mut".len()..].trim_left(); + to_remove = "&mut"; } else { suggestion = pat_snippet; + to_remove = "&"; } err.span_suggestion( pat_span, - "consider removing this borrow operator", + &format!("consider removing the `{}`", to_remove), suggestion.to_owned(), ); } diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index c9a5985b8bb6d..b7047b01af045 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -46,26 +46,26 @@ pub fn main() { let X(_t) = *s; //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION s if let Either::One(_t) = *r { } //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION r while let Either::One(_t) = *r { } //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION r match *r { //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION r Either::One(_t) | Either::Two(_t) => (), } match *r { //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION r Either::One(_t) => (), Either::Two(ref _t) => (), @@ -74,26 +74,26 @@ pub fn main() { let X(_t) = *sm; //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION sm if let Either::One(_t) = *rm { } //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION rm while let Either::One(_t) = *rm { } //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION rm match *rm { //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION rm Either::One(_t) | Either::Two(_t) => (), } match *rm { //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION rm Either::One(_t) => (), Either::Two(ref _t) => (), @@ -101,7 +101,7 @@ pub fn main() { } match *rm { //~^ ERROR cannot move - //~| HELP consider removing this dereference operator + //~| HELP consider removing the `*` //~| SUGGESTION rm Either::One(_t) => (), Either::Two(ref mut _t) => (), @@ -176,20 +176,20 @@ pub fn main() { let &X(_t) = s; //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION X(_t) if let &Either::One(_t) = r { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION Either::One(_t) while let &Either::One(_t) = r { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION Either::One(_t) match r { //~^ ERROR cannot move &Either::One(_t) - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) | &Either::Two(_t) => (), // TODO: would really like a suggestion here too @@ -197,87 +197,87 @@ pub fn main() { match r { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) &Either::Two(ref _t) => (), } match r { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) Either::Two(_t) => (), } fn f1(&X(_t): &X) { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION X(_t) let &mut X(_t) = sm; //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION X(_t) if let &mut Either::One(_t) = rm { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) while let &mut Either::One(_t) = rm { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) &mut Either::Two(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::Two(_t) } match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) &mut Either::Two(ref _t) => (), } match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) &mut Either::Two(ref mut _t) => (), } match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) Either::Two(_t) => (), } fn f2(&mut X(_t): &mut X) { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION X(_t) // -------- let &X(_t) = &x; //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION X(_t) if let &Either::One(_t) = &e { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION Either::One(_t) while let &Either::One(_t) = &e { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&` //~| SUGGESTION Either::One(_t) match &e { //~^ ERROR cannot move &Either::One(_t) - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) | &Either::Two(_t) => (), // TODO: would really like a suggestion here too @@ -285,34 +285,34 @@ pub fn main() { match &e { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) &Either::Two(ref _t) => (), } match &e { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) Either::Two(_t) => (), } let &mut X(_t) = &mut xm; //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION X(_t) if let &mut Either::One(_t) = &mut em { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) while let &mut Either::One(_t) = &mut em { } //~^ ERROR cannot move - //~| HELP consider removing this borrow operator + //~| HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) match &mut em { //~^ ERROR cannot move &mut Either::One(_t) - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) | &mut Either::Two(_t) => (), // TODO: would really like a suggestion here too @@ -320,21 +320,21 @@ pub fn main() { match &mut em { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) &mut Either::Two(ref _t) => (), } match &mut em { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) &mut Either::Two(ref mut _t) => (), } match &mut em { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing this borrow operator + //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) Either::Two(_t) => (), } diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 0493a9fa6e8ac..f18b609a1756d 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -5,7 +5,7 @@ LL | let X(_t) = *s; | -- ^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `s` + | | help: consider removing the `*`: `s` | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait @@ -21,7 +21,7 @@ LL | if let Either::One(_t) = *r { } | -- ^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `r` + | | help: consider removing the `*`: `r` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -37,7 +37,7 @@ LL | while let Either::One(_t) = *r { } | -- ^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `r` + | | help: consider removing the `*`: `r` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -53,7 +53,7 @@ LL | match *r { | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` ... LL | Either::One(_t) | -- data moved here @@ -71,7 +71,7 @@ LL | match *r { | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` ... LL | Either::One(_t) => (), | -- data moved here @@ -89,7 +89,7 @@ LL | let X(_t) = *sm; | -- ^^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `sm` + | | help: consider removing the `*`: `sm` | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait @@ -105,7 +105,7 @@ LL | if let Either::One(_t) = *rm { } | -- ^^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `rm` + | | help: consider removing the `*`: `rm` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -121,7 +121,7 @@ LL | while let Either::One(_t) = *rm { } | -- ^^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `rm` + | | help: consider removing the `*`: `rm` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -137,7 +137,7 @@ LL | match *rm { | ^^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `rm` + | help: consider removing the `*`: `rm` ... LL | Either::One(_t) | -- data moved here @@ -155,7 +155,7 @@ LL | match *rm { | ^^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `rm` + | help: consider removing the `*`: `rm` ... LL | Either::One(_t) => (), | -- data moved here @@ -173,7 +173,7 @@ LL | match *rm { | ^^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `rm` + | help: consider removing the `*`: `rm` ... LL | Either::One(_t) => (), | -- data moved here @@ -377,7 +377,7 @@ LL | let &X(_t) = s; | ------ ^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `X(_t)` + | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:177:12 @@ -392,7 +392,7 @@ LL | if let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:181:25 @@ -407,7 +407,7 @@ LL | while let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:185:28 @@ -425,7 +425,7 @@ LL | &Either::One(_t) | ---------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:191:22 @@ -443,7 +443,7 @@ LL | &Either::One(_t) => (), | ---------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:199:22 @@ -461,7 +461,7 @@ LL | &Either::One(_t) => (), | ---------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:206:22 @@ -476,7 +476,7 @@ LL | let &mut X(_t) = sm; | ---------- ^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `X(_t)` + | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:216:16 @@ -491,7 +491,7 @@ LL | if let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:220:29 @@ -506,7 +506,7 @@ LL | while let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:224:32 @@ -536,11 +536,11 @@ note: move occurs because `_t` has type `X`, which does not implement the `Copy` | LL | &mut Either::Two(_t) => (), | ^^ -help: consider removing this borrow operator +help: consider removing the `&mut` | LL | Either::One(_t) => (), | ^^^^^^^^^^^^^^^ -help: consider removing this borrow operator +help: consider removing the `&mut` | LL | Either::Two(_t) => (), | ^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL | &mut Either::One(_t) => (), | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:239:26 @@ -573,7 +573,7 @@ LL | &mut Either::One(_t) => (), | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:246:26 @@ -591,7 +591,7 @@ LL | &mut Either::One(_t) => (), | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:253:26 @@ -606,7 +606,7 @@ LL | let &X(_t) = &x; | ------ ^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `X(_t)` + | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:265:12 @@ -621,7 +621,7 @@ LL | if let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:269:25 @@ -636,7 +636,7 @@ LL | while let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:273:28 @@ -654,7 +654,7 @@ LL | &Either::One(_t) | ---------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:279:22 @@ -672,7 +672,7 @@ LL | &Either::One(_t) => (), | ---------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:287:22 @@ -690,7 +690,7 @@ LL | &Either::One(_t) => (), | ---------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:294:22 @@ -705,7 +705,7 @@ LL | let &mut X(_t) = &mut xm; | ---------- ^^^^^^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `X(_t)` + | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:300:16 @@ -720,7 +720,7 @@ LL | if let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:304:29 @@ -735,7 +735,7 @@ LL | while let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:308:32 @@ -753,7 +753,7 @@ LL | &mut Either::One(_t) | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:314:26 @@ -771,7 +771,7 @@ LL | &mut Either::One(_t) => (), | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:322:26 @@ -789,7 +789,7 @@ LL | &mut Either::One(_t) => (), | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:329:26 @@ -807,7 +807,7 @@ LL | &mut Either::One(_t) => (), | -------------------- | | | | | data moved here - | help: consider removing this borrow operator: `Either::One(_t)` + | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:336:26 @@ -823,7 +823,7 @@ LL | fn f1(&X(_t): &X) { } | | | | | data moved here | cannot move out of borrowed content - | help: consider removing this borrow operator: `X(_t)` + | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:211:14 @@ -839,7 +839,7 @@ LL | fn f2(&mut X(_t): &mut X) { } | | | | | data moved here | cannot move out of borrowed content - | help: consider removing this borrow operator: `X(_t)` + | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:258:18 From 10aaba8dbef601b2612b3b75ee9c31340af817cf Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Sun, 12 Aug 2018 13:55:34 -0700 Subject: [PATCH 09/27] Make move errors more consistent with typeck errors --- src/librustc_mir/borrow_check/move_errors.rs | 2 +- src/test/ui/suggestions/dont-suggest-ref.rs | 22 +++++++++---------- .../ui/suggestions/dont-suggest-ref.stderr | 22 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index ce7206be4c32c..61b8b8d9220bb 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -360,7 +360,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } else { err.span_suggestion( span, - "consider using a reference instead", + "consider borrowing here", format!("&{}", snippet), ); } diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index b7047b01af045..90e8f951712d4 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -110,26 +110,26 @@ pub fn main() { let X(_t) = vs_[0]; //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vs_[0] if let Either::One(_t) = vr[0] { } //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vr[0] while let Either::One(_t) = vr[0] { } //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vr[0] match vr[0] { //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vr[0] Either::One(_t) | Either::Two(_t) => (), } match vr[0] { //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vr[0] Either::One(_t) => (), Either::Two(ref _t) => (), @@ -138,26 +138,26 @@ pub fn main() { let X(_t) = vsm[0]; //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vsm[0] if let Either::One(_t) = vrm[0] { } //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vrm[0] while let Either::One(_t) = vrm[0] { } //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vrm[0] match vrm[0] { //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vrm[0] Either::One(_t) | Either::Two(_t) => (), } match vrm[0] { //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref _t) => (), @@ -165,7 +165,7 @@ pub fn main() { } match vrm[0] { //~^ ERROR cannot move - //~| HELP consider using a reference instead + //~| HELP consider borrowing here //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref mut _t) => (), diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index f18b609a1756d..7616aa898a02b 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -191,7 +191,7 @@ LL | let X(_t) = vs_[0]; | -- ^^^^^^ | | | | | cannot move out of borrowed content - | | help: consider using a reference instead: `&vs_[0]` + | | help: consider borrowing here: `&vs_[0]` | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait @@ -207,7 +207,7 @@ LL | if let Either::One(_t) = vr[0] { } | -- ^^^^^ | | | | | cannot move out of borrowed content - | | help: consider using a reference instead: `&vr[0]` + | | help: consider borrowing here: `&vr[0]` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -223,7 +223,7 @@ LL | while let Either::One(_t) = vr[0] { } | -- ^^^^^ | | | | | cannot move out of borrowed content - | | help: consider using a reference instead: `&vr[0]` + | | help: consider borrowing here: `&vr[0]` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -239,7 +239,7 @@ LL | match vr[0] { | ^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&vr[0]` + | help: consider borrowing here: `&vr[0]` ... LL | Either::One(_t) | -- data moved here @@ -257,7 +257,7 @@ LL | match vr[0] { | ^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&vr[0]` + | help: consider borrowing here: `&vr[0]` ... LL | Either::One(_t) => (), | -- data moved here @@ -275,7 +275,7 @@ LL | let X(_t) = vsm[0]; | -- ^^^^^^ | | | | | cannot move out of borrowed content - | | help: consider using a reference instead: `&vsm[0]` + | | help: consider borrowing here: `&vsm[0]` | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait @@ -291,7 +291,7 @@ LL | if let Either::One(_t) = vrm[0] { } | -- ^^^^^^ | | | | | cannot move out of borrowed content - | | help: consider using a reference instead: `&vrm[0]` + | | help: consider borrowing here: `&vrm[0]` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -307,7 +307,7 @@ LL | while let Either::One(_t) = vrm[0] { } | -- ^^^^^^ | | | | | cannot move out of borrowed content - | | help: consider using a reference instead: `&vrm[0]` + | | help: consider borrowing here: `&vrm[0]` | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait @@ -323,7 +323,7 @@ LL | match vrm[0] { | ^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&vrm[0]` + | help: consider borrowing here: `&vrm[0]` ... LL | Either::One(_t) | -- data moved here @@ -341,7 +341,7 @@ LL | match vrm[0] { | ^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&vrm[0]` + | help: consider borrowing here: `&vrm[0]` ... LL | Either::One(_t) => (), | -- data moved here @@ -359,7 +359,7 @@ LL | match vrm[0] { | ^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&vrm[0]` + | help: consider borrowing here: `&vrm[0]` ... LL | Either::One(_t) => (), | -- data moved here From 8135372ed105cf8bce043b09e1ef108219230a80 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Sun, 12 Aug 2018 14:42:33 -0700 Subject: [PATCH 10/27] Change TODOs to FIXMEs --- src/test/ui/suggestions/dont-suggest-ref.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index 90e8f951712d4..70c53bf963af3 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -69,7 +69,7 @@ pub fn main() { //~| SUGGESTION r Either::One(_t) => (), Either::Two(ref _t) => (), - // TODO: should suggest removing `ref` too + // FIXME: should suggest removing `ref` too } let X(_t) = *sm; @@ -97,7 +97,7 @@ pub fn main() { //~| SUGGESTION rm Either::One(_t) => (), Either::Two(ref _t) => (), - // TODO: should suggest removing `ref` too + // FIXME: should suggest removing `ref` too } match *rm { //~^ ERROR cannot move @@ -105,7 +105,7 @@ pub fn main() { //~| SUGGESTION rm Either::One(_t) => (), Either::Two(ref mut _t) => (), - // TODO: should suggest removing `ref mut` too + // FIXME: should suggest removing `ref mut` too } let X(_t) = vs_[0]; @@ -133,7 +133,7 @@ pub fn main() { //~| SUGGESTION &vr[0] Either::One(_t) => (), Either::Two(ref _t) => (), - // TODO: should suggest removing `ref` too + // FIXME: should suggest removing `ref` too } let X(_t) = vsm[0]; @@ -161,7 +161,7 @@ pub fn main() { //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref _t) => (), - // TODO: should suggest removing `ref` too + // FIXME: should suggest removing `ref` too } match vrm[0] { //~^ ERROR cannot move @@ -169,7 +169,7 @@ pub fn main() { //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref mut _t) => (), - // TODO: should suggest removing `ref mut` too + // FIXME: should suggest removing `ref mut` too } // -------- @@ -192,7 +192,7 @@ pub fn main() { //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) | &Either::Two(_t) => (), - // TODO: would really like a suggestion here too + // FIXME: would really like a suggestion here too } match r { //~^ ERROR cannot move @@ -280,7 +280,7 @@ pub fn main() { //~^ HELP consider removing the `&` //~| SUGGESTION Either::One(_t) | &Either::Two(_t) => (), - // TODO: would really like a suggestion here too + // FIXME: would really like a suggestion here too } match &e { //~^ ERROR cannot move @@ -315,7 +315,7 @@ pub fn main() { //~^ HELP consider removing the `&mut` //~| SUGGESTION Either::One(_t) | &mut Either::Two(_t) => (), - // TODO: would really like a suggestion here too + // FIXME: would really like a suggestion here too } match &mut em { //~^ ERROR cannot move From 40b5118c8ab4e85c72803c371bc6d18dc01b478c Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Sun, 12 Aug 2018 16:07:19 -0700 Subject: [PATCH 11/27] Remove unnecessary underscore --- src/test/ui/suggestions/dont-suggest-ref.rs | 6 +++--- src/test/ui/suggestions/dont-suggest-ref.stderr | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index 70c53bf963af3..b7543ac1b3335 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -39,7 +39,7 @@ pub fn main() { let vx = vec![X(Y)]; - let vs_ = &vx; + let vs = &vx; let vsm = &mut vec![X(Y)]; // -------- @@ -108,10 +108,10 @@ pub fn main() { // FIXME: should suggest removing `ref mut` too } - let X(_t) = vs_[0]; + let X(_t) = vs[0]; //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vs_[0] + //~| SUGGESTION &vs[0] if let Either::One(_t) = vr[0] { } //~^ ERROR cannot move //~| HELP consider borrowing here diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 7616aa898a02b..05aff35c636e9 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -187,17 +187,17 @@ LL | Either::One(_t) => (), error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:111:17 | -LL | let X(_t) = vs_[0]; - | -- ^^^^^^ +LL | let X(_t) = vs[0]; + | -- ^^^^^ | | | | | cannot move out of borrowed content - | | help: consider borrowing here: `&vs_[0]` + | | help: consider borrowing here: `&vs[0]` | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:111:11 | -LL | let X(_t) = vs_[0]; +LL | let X(_t) = vs[0]; | ^^ error[E0507]: cannot move out of borrowed content From 20ae08bda6462780b80cd30e9ab3ade836338685 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 03:17:53 -0700 Subject: [PATCH 12/27] Dedup suggestions --- src/librustc_mir/borrow_check/move_errors.rs | 14 +- src/test/ui/suggestions/dont-suggest-ref.rs | 117 ++++ .../ui/suggestions/dont-suggest-ref.stderr | 628 +++++++++++++++--- 3 files changed, 654 insertions(+), 105 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 61b8b8d9220bb..1615ff04badb1 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -380,11 +380,14 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } + // FIXME: Move the loop outside this method and add_move_error_labels() + // so they can share it. fn add_move_error_suggestions( &self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], ) { + let mut suggestions: Vec<(Span, String, String)> = Vec::new(); for local in binds_to { let bind_to = &self.mir.local_decls[*local]; if let Some( @@ -410,14 +413,19 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { suggestion = pat_snippet; to_remove = "&"; } - err.span_suggestion( + suggestions.push(( pat_span, - &format!("consider removing the `{}`", to_remove), + format!("consider removing the `{}`", to_remove), suggestion.to_owned(), - ); + )); } } } + suggestions.sort_unstable_by_key(|&(span, _, _)| span); + suggestions.dedup_by_key(|&mut (span, _, _)| span); + for (span, msg, suggestion) in suggestions { + err.span_suggestion(span, &msg, suggestion); + } } fn add_move_error_labels( diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index b7543ac1b3335..8fa19e84e4c99 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -10,13 +10,16 @@ #![feature(nll)] +#[derive(Clone)] enum Either { One(X), Two(X), } +#[derive(Clone)] struct X(Y); +#[derive(Clone)] struct Y; pub fn main() { @@ -338,4 +341,118 @@ pub fn main() { //~| SUGGESTION Either::One(_t) Either::Two(_t) => (), } + + // -------- + + let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (X(_t), X(_u)) + if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &(Either::Two(_t), Either::One(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::Two(_t), Either::One(_u)) + _ => (), + } + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + | &(Either::Two(_t), Either::One(_u)) => (), + // FIXME: would really like a suggestion here too + _ => (), + } + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &(Either::Two(ref _t), Either::One(ref _u)) => (), + _ => (), + } + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + (Either::Two(_t), Either::One(_u)) => (), + _ => (), + } + fn f3(&(X(_t), X(_u)): &(X, X)) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (X(_t), X(_u)) + + let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (X(_t), X(_u)) + if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &mut (Either::Two(_t), Either::One(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::Two(_t), Either::One(_u)) + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + | &mut (Either::Two(_t), Either::One(_u)) => (), + // FIXME: would really like a suggestion here too + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &mut (Either::Two(ref _t), Either::One(ref _u)) => (), + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &mut (Either::Two(ref mut _t), Either::One(ref mut _u)) => (), + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + (Either::Two(_t), Either::One(_u)) => (), + _ => (), + } + fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (X(_t), X(_u)) } diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 05aff35c636e9..81e3c21084802 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:47:17 + --> $DIR/dont-suggest-ref.rs:50:17 | LL | let X(_t) = *s; | -- ^^ @@ -9,13 +9,13 @@ LL | let X(_t) = *s; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:47:11 + --> $DIR/dont-suggest-ref.rs:50:11 | LL | let X(_t) = *s; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:51:30 + --> $DIR/dont-suggest-ref.rs:54:30 | LL | if let Either::One(_t) = *r { } | -- ^^ @@ -25,13 +25,13 @@ LL | if let Either::One(_t) = *r { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:51:24 + --> $DIR/dont-suggest-ref.rs:54:24 | LL | if let Either::One(_t) = *r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:55:33 + --> $DIR/dont-suggest-ref.rs:58:33 | LL | while let Either::One(_t) = *r { } | -- ^^ @@ -41,13 +41,13 @@ LL | while let Either::One(_t) = *r { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:55:27 + --> $DIR/dont-suggest-ref.rs:58:27 | LL | while let Either::One(_t) = *r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:59:11 + --> $DIR/dont-suggest-ref.rs:62:11 | LL | match *r { | ^^ @@ -59,13 +59,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:63:21 + --> $DIR/dont-suggest-ref.rs:66:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:66:11 + --> $DIR/dont-suggest-ref.rs:69:11 | LL | match *r { | ^^ @@ -77,13 +77,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:70:21 + --> $DIR/dont-suggest-ref.rs:73:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:75:17 + --> $DIR/dont-suggest-ref.rs:78:17 | LL | let X(_t) = *sm; | -- ^^^ @@ -93,13 +93,13 @@ LL | let X(_t) = *sm; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:75:11 + --> $DIR/dont-suggest-ref.rs:78:11 | LL | let X(_t) = *sm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:79:30 + --> $DIR/dont-suggest-ref.rs:82:30 | LL | if let Either::One(_t) = *rm { } | -- ^^^ @@ -109,13 +109,13 @@ LL | if let Either::One(_t) = *rm { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:79:24 + --> $DIR/dont-suggest-ref.rs:82:24 | LL | if let Either::One(_t) = *rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:83:33 + --> $DIR/dont-suggest-ref.rs:86:33 | LL | while let Either::One(_t) = *rm { } | -- ^^^ @@ -125,13 +125,13 @@ LL | while let Either::One(_t) = *rm { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:83:27 + --> $DIR/dont-suggest-ref.rs:86:27 | LL | while let Either::One(_t) = *rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:87:11 + --> $DIR/dont-suggest-ref.rs:90:11 | LL | match *rm { | ^^^ @@ -143,13 +143,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:91:21 + --> $DIR/dont-suggest-ref.rs:94:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:94:11 + --> $DIR/dont-suggest-ref.rs:97:11 | LL | match *rm { | ^^^ @@ -161,13 +161,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:98:21 + --> $DIR/dont-suggest-ref.rs:101:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:102:11 + --> $DIR/dont-suggest-ref.rs:105:11 | LL | match *rm { | ^^^ @@ -179,13 +179,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:106:21 + --> $DIR/dont-suggest-ref.rs:109:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:111:17 + --> $DIR/dont-suggest-ref.rs:114:17 | LL | let X(_t) = vs[0]; | -- ^^^^^ @@ -195,13 +195,13 @@ LL | let X(_t) = vs[0]; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:111:11 + --> $DIR/dont-suggest-ref.rs:114:11 | LL | let X(_t) = vs[0]; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:115:30 + --> $DIR/dont-suggest-ref.rs:118:30 | LL | if let Either::One(_t) = vr[0] { } | -- ^^^^^ @@ -211,13 +211,13 @@ LL | if let Either::One(_t) = vr[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:115:24 + --> $DIR/dont-suggest-ref.rs:118:24 | LL | if let Either::One(_t) = vr[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:119:33 + --> $DIR/dont-suggest-ref.rs:122:33 | LL | while let Either::One(_t) = vr[0] { } | -- ^^^^^ @@ -227,13 +227,13 @@ LL | while let Either::One(_t) = vr[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:119:27 + --> $DIR/dont-suggest-ref.rs:122:27 | LL | while let Either::One(_t) = vr[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:123:11 + --> $DIR/dont-suggest-ref.rs:126:11 | LL | match vr[0] { | ^^^^^ @@ -245,13 +245,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:127:21 + --> $DIR/dont-suggest-ref.rs:130:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:130:11 + --> $DIR/dont-suggest-ref.rs:133:11 | LL | match vr[0] { | ^^^^^ @@ -263,13 +263,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:134:21 + --> $DIR/dont-suggest-ref.rs:137:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:139:17 + --> $DIR/dont-suggest-ref.rs:142:17 | LL | let X(_t) = vsm[0]; | -- ^^^^^^ @@ -279,13 +279,13 @@ LL | let X(_t) = vsm[0]; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:139:11 + --> $DIR/dont-suggest-ref.rs:142:11 | LL | let X(_t) = vsm[0]; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:143:30 + --> $DIR/dont-suggest-ref.rs:146:30 | LL | if let Either::One(_t) = vrm[0] { } | -- ^^^^^^ @@ -295,13 +295,13 @@ LL | if let Either::One(_t) = vrm[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:143:24 + --> $DIR/dont-suggest-ref.rs:146:24 | LL | if let Either::One(_t) = vrm[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:147:33 + --> $DIR/dont-suggest-ref.rs:150:33 | LL | while let Either::One(_t) = vrm[0] { } | -- ^^^^^^ @@ -311,13 +311,13 @@ LL | while let Either::One(_t) = vrm[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:147:27 + --> $DIR/dont-suggest-ref.rs:150:27 | LL | while let Either::One(_t) = vrm[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:151:11 + --> $DIR/dont-suggest-ref.rs:154:11 | LL | match vrm[0] { | ^^^^^^ @@ -329,13 +329,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:155:21 + --> $DIR/dont-suggest-ref.rs:158:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:158:11 + --> $DIR/dont-suggest-ref.rs:161:11 | LL | match vrm[0] { | ^^^^^^ @@ -347,13 +347,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:162:21 + --> $DIR/dont-suggest-ref.rs:165:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:166:11 + --> $DIR/dont-suggest-ref.rs:169:11 | LL | match vrm[0] { | ^^^^^^ @@ -365,13 +365,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:170:21 + --> $DIR/dont-suggest-ref.rs:173:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:177:18 + --> $DIR/dont-suggest-ref.rs:180:18 | LL | let &X(_t) = s; | ------ ^ cannot move out of borrowed content @@ -380,13 +380,13 @@ LL | let &X(_t) = s; | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:177:12 + --> $DIR/dont-suggest-ref.rs:180:12 | LL | let &X(_t) = s; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:181:31 + --> $DIR/dont-suggest-ref.rs:184:31 | LL | if let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content @@ -395,13 +395,13 @@ LL | if let &Either::One(_t) = r { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:181:25 + --> $DIR/dont-suggest-ref.rs:184:25 | LL | if let &Either::One(_t) = r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:185:34 + --> $DIR/dont-suggest-ref.rs:188:34 | LL | while let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content @@ -410,13 +410,13 @@ LL | while let &Either::One(_t) = r { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:185:28 + --> $DIR/dont-suggest-ref.rs:188:28 | LL | while let &Either::One(_t) = r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:189:11 + --> $DIR/dont-suggest-ref.rs:192:11 | LL | match r { | ^ cannot move out of borrowed content @@ -428,13 +428,13 @@ LL | &Either::One(_t) | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:191:22 + --> $DIR/dont-suggest-ref.rs:194:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:197:11 + --> $DIR/dont-suggest-ref.rs:200:11 | LL | match r { | ^ cannot move out of borrowed content @@ -446,13 +446,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:199:22 + --> $DIR/dont-suggest-ref.rs:202:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:204:11 + --> $DIR/dont-suggest-ref.rs:207:11 | LL | match r { | ^ cannot move out of borrowed content @@ -464,13 +464,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:206:22 + --> $DIR/dont-suggest-ref.rs:209:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:216:22 + --> $DIR/dont-suggest-ref.rs:219:22 | LL | let &mut X(_t) = sm; | ---------- ^^ cannot move out of borrowed content @@ -479,13 +479,13 @@ LL | let &mut X(_t) = sm; | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:216:16 + --> $DIR/dont-suggest-ref.rs:219:16 | LL | let &mut X(_t) = sm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:220:35 + --> $DIR/dont-suggest-ref.rs:223:35 | LL | if let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content @@ -494,13 +494,13 @@ LL | if let &mut Either::One(_t) = rm { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:220:29 + --> $DIR/dont-suggest-ref.rs:223:29 | LL | if let &mut Either::One(_t) = rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:224:38 + --> $DIR/dont-suggest-ref.rs:227:38 | LL | while let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content @@ -509,13 +509,13 @@ LL | while let &mut Either::One(_t) = rm { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:224:32 + --> $DIR/dont-suggest-ref.rs:227:32 | LL | while let &mut Either::One(_t) = rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:228:11 + --> $DIR/dont-suggest-ref.rs:231:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -527,12 +527,12 @@ LL | &mut Either::Two(_t) => (), | -- ... and here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:230:26 + --> $DIR/dont-suggest-ref.rs:233:26 | LL | &mut Either::One(_t) => (), | ^^ note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:233:26 + --> $DIR/dont-suggest-ref.rs:236:26 | LL | &mut Either::Two(_t) => (), | ^^ @@ -546,7 +546,7 @@ LL | Either::Two(_t) => (), | ^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:237:11 + --> $DIR/dont-suggest-ref.rs:240:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -558,13 +558,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:239:26 + --> $DIR/dont-suggest-ref.rs:242:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:244:11 + --> $DIR/dont-suggest-ref.rs:247:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -576,13 +576,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:246:26 + --> $DIR/dont-suggest-ref.rs:249:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:251:11 + --> $DIR/dont-suggest-ref.rs:254:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -594,13 +594,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:253:26 + --> $DIR/dont-suggest-ref.rs:256:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:265:18 + --> $DIR/dont-suggest-ref.rs:268:18 | LL | let &X(_t) = &x; | ------ ^^ cannot move out of borrowed content @@ -609,13 +609,13 @@ LL | let &X(_t) = &x; | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:265:12 + --> $DIR/dont-suggest-ref.rs:268:12 | LL | let &X(_t) = &x; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:269:31 + --> $DIR/dont-suggest-ref.rs:272:31 | LL | if let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -624,13 +624,13 @@ LL | if let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:269:25 + --> $DIR/dont-suggest-ref.rs:272:25 | LL | if let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:273:34 + --> $DIR/dont-suggest-ref.rs:276:34 | LL | while let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -639,13 +639,13 @@ LL | while let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:273:28 + --> $DIR/dont-suggest-ref.rs:276:28 | LL | while let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:277:11 + --> $DIR/dont-suggest-ref.rs:280:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -657,13 +657,13 @@ LL | &Either::One(_t) | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:279:22 + --> $DIR/dont-suggest-ref.rs:282:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:285:11 + --> $DIR/dont-suggest-ref.rs:288:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -675,13 +675,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:287:22 + --> $DIR/dont-suggest-ref.rs:290:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:292:11 + --> $DIR/dont-suggest-ref.rs:295:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -693,13 +693,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:294:22 + --> $DIR/dont-suggest-ref.rs:297:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:300:22 + --> $DIR/dont-suggest-ref.rs:303:22 | LL | let &mut X(_t) = &mut xm; | ---------- ^^^^^^^ cannot move out of borrowed content @@ -708,13 +708,13 @@ LL | let &mut X(_t) = &mut xm; | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:300:16 + --> $DIR/dont-suggest-ref.rs:303:16 | LL | let &mut X(_t) = &mut xm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:304:35 + --> $DIR/dont-suggest-ref.rs:307:35 | LL | if let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -723,13 +723,13 @@ LL | if let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:304:29 + --> $DIR/dont-suggest-ref.rs:307:29 | LL | if let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:308:38 + --> $DIR/dont-suggest-ref.rs:311:38 | LL | while let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -738,13 +738,13 @@ LL | while let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:308:32 + --> $DIR/dont-suggest-ref.rs:311:32 | LL | while let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:312:11 + --> $DIR/dont-suggest-ref.rs:315:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -756,13 +756,13 @@ LL | &mut Either::One(_t) | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:314:26 + --> $DIR/dont-suggest-ref.rs:317:26 | LL | &mut Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:320:11 + --> $DIR/dont-suggest-ref.rs:323:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -774,13 +774,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:322:26 + --> $DIR/dont-suggest-ref.rs:325:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:327:11 + --> $DIR/dont-suggest-ref.rs:330:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -792,13 +792,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:329:26 + --> $DIR/dont-suggest-ref.rs:332:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:334:11 + --> $DIR/dont-suggest-ref.rs:337:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -810,13 +810,393 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:336:26 + --> $DIR/dont-suggest-ref.rs:339:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:211:11 + --> $DIR/dont-suggest-ref.rs:347:27 + | +LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&`: `(X(_t), X(_u))` + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:347:13 + | +LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + | ^^ +note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:347:20 + | +LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:351:50 + | +LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:351:26 + | +LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:351:43 + | +LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:355:53 + | +LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:355:29 + | +LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:355:46 + | +LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:359:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) => (), + | -- -- ... and here + | | + | data moved here +... +LL | &(Either::Two(_t), Either::One(_u)) => (), + | -- ... and here -- ... and here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:361:23 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:361:40 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:364:23 + | +LL | &(Either::Two(_t), Either::One(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:364:40 + | +LL | &(Either::Two(_t), Either::One(_u)) => (), + | ^^ +help: consider removing the `&` + | +LL | (Either::One(_t), Either::Two(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider removing the `&` + | +LL | (Either::Two(_t), Either::One(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:369:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) + | ----------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:371:23 + | +LL | &(Either::One(_t), Either::Two(_u)) + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:371:40 + | +LL | &(Either::One(_t), Either::Two(_u)) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:378:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ----------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:380:23 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:380:40 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:386:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ----------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:388:23 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:388:40 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:399:31 + | +LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(X(_t), X(_u))` + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:399:17 + | +LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + | ^^ +note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:399:24 + | +LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:403:54 + | +LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:403:30 + | +LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:403:47 + | +LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:407:57 + | +LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:407:33 + | +LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:407:50 + | +LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:411:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | -- -- ... and here + | | + | data moved here +... +LL | &mut (Either::Two(_t), Either::One(_u)) => (), + | -- ... and here -- ... and here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:413:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:413:44 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:416:27 + | +LL | &mut (Either::Two(_t), Either::One(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:416:44 + | +LL | &mut (Either::Two(_t), Either::One(_u)) => (), + | ^^ +help: consider removing the `&mut` + | +LL | (Either::One(_t), Either::Two(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider removing the `&mut` + | +LL | (Either::Two(_t), Either::One(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:421:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) + | --------------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:423:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:423:44 + | +LL | &mut (Either::One(_t), Either::Two(_u)) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:430:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | --------------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:432:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:432:44 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:438:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | --------------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:440:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:440:44 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:446:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | --------------------------------------- + | | | | + | | | ... and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:448:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ +note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:448:44 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:214:11 | LL | fn f1(&X(_t): &X) { } | ^^^--^ @@ -826,13 +1206,13 @@ LL | fn f1(&X(_t): &X) { } | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:211:14 + --> $DIR/dont-suggest-ref.rs:214:14 | LL | fn f1(&X(_t): &X) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:258:11 + --> $DIR/dont-suggest-ref.rs:261:11 | LL | fn f2(&mut X(_t): &mut X) { } | ^^^^^^^--^ @@ -842,11 +1222,55 @@ LL | fn f2(&mut X(_t): &mut X) { } | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:258:18 + --> $DIR/dont-suggest-ref.rs:261:18 | LL | fn f2(&mut X(_t): &mut X) { } | ^^ -error: aborting due to 50 previous errors +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:394:11 + | +LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } + | ^^^^--^^^^^--^^ + | | | | + | | | ... and here + | | data moved here + | cannot move out of borrowed content + | help: consider removing the `&`: `(X(_t), X(_u))` + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:394:15 + | +LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } + | ^^ +note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:394:22 + | +LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:454:11 + | +LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } + | ^^^^^^^^--^^^^^--^^ + | | | | + | | | ... and here + | | data moved here + | cannot move out of borrowed content + | help: consider removing the `&mut`: `(X(_t), X(_u))` + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:454:19 + | +LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } + | ^^ +note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:454:26 + | +LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } + | ^^ + +error: aborting due to 67 previous errors For more information about this error, try `rustc --explain E0507`. From 6cf4e14ac021647165071b883e0bbcc863909191 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 14:51:27 -0700 Subject: [PATCH 13/27] Coalesce var-is-not-Copy notes per move --- src/librustc_mir/borrow_check/move_errors.rs | 29 ++- .../ui/suggestions/dont-suggest-ref.stderr | 181 ++++-------------- 2 files changed, 60 insertions(+), 150 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 1615ff04badb1..44459b977242e 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -380,8 +380,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } - // FIXME: Move the loop outside this method and add_move_error_labels() - // so they can share it. fn add_move_error_suggestions( &self, err: &mut DiagnosticBuilder<'a>, @@ -433,6 +431,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], ) { + let mut noncopy_var_spans = Vec::new(); for (j, local) in binds_to.into_iter().enumerate() { let bind_to = &self.mir.local_decls[*local]; let binding_span = bind_to.source_info.span; @@ -443,14 +442,26 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { err.span_label(binding_span, format!("... and here")); } + if binds_to.len() == 1 { + err.span_note( + binding_span, + &format!( + "move occurs because `{}` has type `{}`, \ + which does not implement the `Copy` trait", + bind_to.name.unwrap(), + bind_to.ty + ), + ); + } else { + noncopy_var_spans.push(binding_span); + } + } + + if binds_to.len() > 1 { err.span_note( - binding_span, - &format!( - "move occurs because `{}` has type `{}`, \ - which does not implement the `Copy` trait", - bind_to.name.unwrap(), - bind_to.ty - ), + noncopy_var_spans, + "move occurs because these variables have types that \ + don't implement the `Copy` trait", ); } } diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 81e3c21084802..8bc9209c2ed86 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -526,14 +526,12 @@ LL | &mut Either::One(_t) => (), LL | &mut Either::Two(_t) => (), | -- ... and here | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:233:26 | LL | &mut Either::One(_t) => (), | ^^ -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:236:26 - | +... LL | &mut Either::Two(_t) => (), | ^^ help: consider removing the `&mut` @@ -825,16 +823,11 @@ LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | | data moved here | help: consider removing the `&`: `(X(_t), X(_u))` | -note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:347:13 | LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - | ^^ -note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:347:20 - | -LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:351:50 @@ -846,16 +839,11 @@ LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:351:26 | LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:351:43 - | -LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:355:53 @@ -867,16 +855,11 @@ LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:355:29 | LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:355:46 - | -LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:359:11 @@ -892,26 +875,14 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), LL | &(Either::Two(_t), Either::One(_u)) => (), | -- ... and here -- ... and here | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:361:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:361:40 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:364:23 - | -LL | &(Either::Two(_t), Either::One(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:364:40 - | + | ^^ ^^ +... LL | &(Either::Two(_t), Either::One(_u)) => (), - | ^^ + | ^^ ^^ help: consider removing the `&` | LL | (Either::One(_t), Either::Two(_u)) => (), @@ -934,16 +905,11 @@ LL | &(Either::One(_t), Either::Two(_u)) | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:371:23 | LL | &(Either::One(_t), Either::Two(_u)) - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:371:40 - | -LL | &(Either::One(_t), Either::Two(_u)) - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:378:11 @@ -958,16 +924,11 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:380:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:380:40 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:386:11 @@ -982,16 +943,11 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:388:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:388:40 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:399:31 @@ -1003,16 +959,11 @@ LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | | data moved here | help: consider removing the `&mut`: `(X(_t), X(_u))` | -note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:399:17 | LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - | ^^ -note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:399:24 - | -LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:403:54 @@ -1024,16 +975,11 @@ LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.c | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:403:30 | LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:403:47 - | -LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:407:57 @@ -1045,16 +991,11 @@ LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), e | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:407:33 | LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:407:50 - | -LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:411:11 @@ -1070,26 +1011,14 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), LL | &mut (Either::Two(_t), Either::One(_u)) => (), | -- ... and here -- ... and here | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:413:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:413:44 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:416:27 - | -LL | &mut (Either::Two(_t), Either::One(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:416:44 - | + | ^^ ^^ +... LL | &mut (Either::Two(_t), Either::One(_u)) => (), - | ^^ + | ^^ ^^ help: consider removing the `&mut` | LL | (Either::One(_t), Either::Two(_u)) => (), @@ -1112,16 +1041,11 @@ LL | &mut (Either::One(_t), Either::Two(_u)) | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:423:27 | LL | &mut (Either::One(_t), Either::Two(_u)) - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:423:44 - | -LL | &mut (Either::One(_t), Either::Two(_u)) - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:430:11 @@ -1136,16 +1060,11 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:432:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:432:44 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:438:11 @@ -1160,16 +1079,11 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:440:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:440:44 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:446:11 @@ -1184,16 +1098,11 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:448:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ -note: move occurs because `_u` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:448:44 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:214:11 @@ -1238,16 +1147,11 @@ LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } | cannot move out of borrowed content | help: consider removing the `&`: `(X(_t), X(_u))` | -note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:394:15 | LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } - | ^^ -note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:394:22 - | -LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } - | ^^ + | ^^ ^^ error[E0507]: cannot move out of borrowed content --> $DIR/dont-suggest-ref.rs:454:11 @@ -1260,16 +1164,11 @@ LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } | cannot move out of borrowed content | help: consider removing the `&mut`: `(X(_t), X(_u))` | -note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait +note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:454:19 | LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } - | ^^ -note: move occurs because `_u` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:454:26 - | -LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } - | ^^ + | ^^ ^^ error: aborting due to 67 previous errors From 0a82abc47b729244d699a11e7f30c1337f2e5cc9 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 15:52:23 -0700 Subject: [PATCH 14/27] Test patterns in tuples --- src/test/ui/suggestions/dont-suggest-ref.rs | 42 ++- .../ui/suggestions/dont-suggest-ref.stderr | 278 ++++++++++++++---- 2 files changed, 249 insertions(+), 71 deletions(-) diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index 8fa19e84e4c99..67e8b4a0e952b 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -45,7 +45,7 @@ pub fn main() { let vs = &vx; let vsm = &mut vec![X(Y)]; - // -------- + // -------- move from Either/X place -------- let X(_t) = *s; //~^ ERROR cannot move @@ -175,7 +175,7 @@ pub fn main() { // FIXME: should suggest removing `ref mut` too } - // -------- + // -------- move from &Either/&X place -------- let &X(_t) = s; //~^ ERROR cannot move @@ -263,7 +263,37 @@ pub fn main() { //~| HELP consider removing the `&mut` //~| SUGGESTION X(_t) - // -------- + // -------- move from tuple of &Either/&X (no suggestions) -------- + + let (&X(_t),) = (&x.clone(),); + //~^ ERROR cannot move + if let (&Either::One(_t),) = (&e.clone(),) { } + //~^ ERROR cannot move + while let (&Either::One(_t),) = (&e.clone(),) { } + //~^ ERROR cannot move + match (&e.clone(),) { + //~^ ERROR cannot move + (&Either::One(_t),) + | (&Either::Two(_t),) => (), + } + fn f3((&X(_t),): (&X,)) { } + //~^ ERROR cannot move + + let (&mut X(_t),) = (&mut xm.clone(),); + //~^ ERROR cannot move + if let (&mut Either::One(_t),) = (&mut em.clone(),) { } + //~^ ERROR cannot move + while let (&mut Either::One(_t),) = (&mut em.clone(),) { } + //~^ ERROR cannot move + match (&mut em.clone(),) { + //~^ ERROR cannot move + (&mut Either::One(_t),) => (), + (&mut Either::Two(_t),) => (), + } + fn f4((&mut X(_t),): (&mut X,)) { } + //~^ ERROR cannot move + + // -------- move from &Either/&X value -------- let &X(_t) = &x; //~^ ERROR cannot move @@ -342,7 +372,7 @@ pub fn main() { Either::Two(_t) => (), } - // -------- + // -------- test for duplicate suggestions -------- let &(X(_t), X(_u)) = &(x.clone(), x.clone()); //~^ ERROR cannot move @@ -391,7 +421,7 @@ pub fn main() { (Either::Two(_t), Either::One(_u)) => (), _ => (), } - fn f3(&(X(_t), X(_u)): &(X, X)) { } + fn f5(&(X(_t), X(_u)): &(X, X)) { } //~^ ERROR cannot move //~| HELP consider removing the `&` //~| SUGGESTION (X(_t), X(_u)) @@ -451,7 +481,7 @@ pub fn main() { (Either::Two(_t), Either::One(_u)) => (), _ => (), } - fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } + fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } //~^ ERROR cannot move //~| HELP consider removing the `&mut` //~| SUGGESTION (X(_t), X(_u)) diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 8bc9209c2ed86..00fe78d916474 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -598,7 +598,125 @@ LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:268:18 + --> $DIR/dont-suggest-ref.rs:268:21 + | +LL | let (&X(_t),) = (&x.clone(),); + | -- ^^^^^^^^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:268:13 + | +LL | let (&X(_t),) = (&x.clone(),); + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:270:34 + | +LL | if let (&Either::One(_t),) = (&e.clone(),) { } + | -- ^^^^^^^^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:270:26 + | +LL | if let (&Either::One(_t),) = (&e.clone(),) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:272:37 + | +LL | while let (&Either::One(_t),) = (&e.clone(),) { } + | -- ^^^^^^^^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:272:29 + | +LL | while let (&Either::One(_t),) = (&e.clone(),) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:274:11 + | +LL | match (&e.clone(),) { + | ^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | (&Either::One(_t),) + | -- data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:276:23 + | +LL | (&Either::One(_t),) + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:282:25 + | +LL | let (&mut X(_t),) = (&mut xm.clone(),); + | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:282:17 + | +LL | let (&mut X(_t),) = (&mut xm.clone(),); + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:284:38 + | +LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } + | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:284:30 + | +LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:286:41 + | +LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } + | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:286:33 + | +LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:288:11 + | +LL | match (&mut em.clone(),) { + | ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | (&mut Either::One(_t),) => (), + | -- data moved here +LL | (&mut Either::Two(_t),) => (), + | -- ... and here + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:290:27 + | +LL | (&mut Either::One(_t),) => (), + | ^^ +LL | (&mut Either::Two(_t),) => (), + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:298:18 | LL | let &X(_t) = &x; | ------ ^^ cannot move out of borrowed content @@ -607,13 +725,13 @@ LL | let &X(_t) = &x; | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:268:12 + --> $DIR/dont-suggest-ref.rs:298:12 | LL | let &X(_t) = &x; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:272:31 + --> $DIR/dont-suggest-ref.rs:302:31 | LL | if let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -622,13 +740,13 @@ LL | if let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:272:25 + --> $DIR/dont-suggest-ref.rs:302:25 | LL | if let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:276:34 + --> $DIR/dont-suggest-ref.rs:306:34 | LL | while let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -637,13 +755,13 @@ LL | while let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:276:28 + --> $DIR/dont-suggest-ref.rs:306:28 | LL | while let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:280:11 + --> $DIR/dont-suggest-ref.rs:310:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -655,13 +773,13 @@ LL | &Either::One(_t) | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:282:22 + --> $DIR/dont-suggest-ref.rs:312:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:288:11 + --> $DIR/dont-suggest-ref.rs:318:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -673,13 +791,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:290:22 + --> $DIR/dont-suggest-ref.rs:320:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:295:11 + --> $DIR/dont-suggest-ref.rs:325:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -691,13 +809,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:297:22 + --> $DIR/dont-suggest-ref.rs:327:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:303:22 + --> $DIR/dont-suggest-ref.rs:333:22 | LL | let &mut X(_t) = &mut xm; | ---------- ^^^^^^^ cannot move out of borrowed content @@ -706,13 +824,13 @@ LL | let &mut X(_t) = &mut xm; | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:303:16 + --> $DIR/dont-suggest-ref.rs:333:16 | LL | let &mut X(_t) = &mut xm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:307:35 + --> $DIR/dont-suggest-ref.rs:337:35 | LL | if let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -721,13 +839,13 @@ LL | if let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:307:29 + --> $DIR/dont-suggest-ref.rs:337:29 | LL | if let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:311:38 + --> $DIR/dont-suggest-ref.rs:341:38 | LL | while let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -736,13 +854,13 @@ LL | while let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:311:32 + --> $DIR/dont-suggest-ref.rs:341:32 | LL | while let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:315:11 + --> $DIR/dont-suggest-ref.rs:345:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -754,13 +872,13 @@ LL | &mut Either::One(_t) | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:317:26 + --> $DIR/dont-suggest-ref.rs:347:26 | LL | &mut Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:323:11 + --> $DIR/dont-suggest-ref.rs:353:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -772,13 +890,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:325:26 + --> $DIR/dont-suggest-ref.rs:355:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:330:11 + --> $DIR/dont-suggest-ref.rs:360:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -790,13 +908,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:332:26 + --> $DIR/dont-suggest-ref.rs:362:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:337:11 + --> $DIR/dont-suggest-ref.rs:367:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -808,13 +926,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:339:26 + --> $DIR/dont-suggest-ref.rs:369:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:347:27 + --> $DIR/dont-suggest-ref.rs:377:27 | LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -824,13 +942,13 @@ LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | help: consider removing the `&`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:347:13 + --> $DIR/dont-suggest-ref.rs:377:13 | LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:351:50 + --> $DIR/dont-suggest-ref.rs:381:50 | LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -840,13 +958,13 @@ LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:351:26 + --> $DIR/dont-suggest-ref.rs:381:26 | LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:355:53 + --> $DIR/dont-suggest-ref.rs:385:53 | LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -856,13 +974,13 @@ LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:355:29 + --> $DIR/dont-suggest-ref.rs:385:29 | LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:359:11 + --> $DIR/dont-suggest-ref.rs:389:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -876,7 +994,7 @@ LL | &(Either::Two(_t), Either::One(_u)) => (), | -- ... and here -- ... and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:361:23 + --> $DIR/dont-suggest-ref.rs:391:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ @@ -893,7 +1011,7 @@ LL | (Either::Two(_t), Either::One(_u)) => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:369:11 + --> $DIR/dont-suggest-ref.rs:399:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -906,13 +1024,13 @@ LL | &(Either::One(_t), Either::Two(_u)) | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:371:23 + --> $DIR/dont-suggest-ref.rs:401:23 | LL | &(Either::One(_t), Either::Two(_u)) | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:378:11 + --> $DIR/dont-suggest-ref.rs:408:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -925,13 +1043,13 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:380:23 + --> $DIR/dont-suggest-ref.rs:410:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:386:11 + --> $DIR/dont-suggest-ref.rs:416:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -944,13 +1062,13 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:388:23 + --> $DIR/dont-suggest-ref.rs:418:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:399:31 + --> $DIR/dont-suggest-ref.rs:429:31 | LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -960,13 +1078,13 @@ LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | help: consider removing the `&mut`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:399:17 + --> $DIR/dont-suggest-ref.rs:429:17 | LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:403:54 + --> $DIR/dont-suggest-ref.rs:433:54 | LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -976,13 +1094,13 @@ LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.c | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:403:30 + --> $DIR/dont-suggest-ref.rs:433:30 | LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:407:57 + --> $DIR/dont-suggest-ref.rs:437:57 | LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -992,13 +1110,13 @@ LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), e | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:407:33 + --> $DIR/dont-suggest-ref.rs:437:33 | LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:411:11 + --> $DIR/dont-suggest-ref.rs:441:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1012,7 +1130,7 @@ LL | &mut (Either::Two(_t), Either::One(_u)) => (), | -- ... and here -- ... and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:413:27 + --> $DIR/dont-suggest-ref.rs:443:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ @@ -1029,7 +1147,7 @@ LL | (Either::Two(_t), Either::One(_u)) => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:421:11 + --> $DIR/dont-suggest-ref.rs:451:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1042,13 +1160,13 @@ LL | &mut (Either::One(_t), Either::Two(_u)) | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:423:27 + --> $DIR/dont-suggest-ref.rs:453:27 | LL | &mut (Either::One(_t), Either::Two(_u)) | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:430:11 + --> $DIR/dont-suggest-ref.rs:460:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1061,13 +1179,13 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:432:27 + --> $DIR/dont-suggest-ref.rs:462:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:438:11 + --> $DIR/dont-suggest-ref.rs:468:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1080,13 +1198,13 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:440:27 + --> $DIR/dont-suggest-ref.rs:470:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:446:11 + --> $DIR/dont-suggest-ref.rs:476:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1099,7 +1217,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:448:27 + --> $DIR/dont-suggest-ref.rs:478:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ @@ -1137,9 +1255,39 @@ LL | fn f2(&mut X(_t): &mut X) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:394:11 + --> $DIR/dont-suggest-ref.rs:279:11 + | +LL | fn f3((&X(_t),): (&X,)) { } + | ^^^^--^^^ + | | | + | | data moved here + | cannot move out of borrowed content + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:279:15 + | +LL | fn f3((&X(_t),): (&X,)) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:293:11 + | +LL | fn f4((&mut X(_t),): (&mut X,)) { } + | ^^^^^^^^--^^^ + | | | + | | data moved here + | cannot move out of borrowed content + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref.rs:293:19 + | +LL | fn f4((&mut X(_t),): (&mut X,)) { } + | ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/dont-suggest-ref.rs:424:11 | -LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } +LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | ^^^^--^^^^^--^^ | | | | | | | ... and here @@ -1148,15 +1296,15 @@ LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } | help: consider removing the `&`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:394:15 + --> $DIR/dont-suggest-ref.rs:424:15 | -LL | fn f3(&(X(_t), X(_u)): &(X, X)) { } +LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:454:11 + --> $DIR/dont-suggest-ref.rs:484:11 | -LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } +LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | ^^^^^^^^--^^^^^--^^ | | | | | | | ... and here @@ -1165,11 +1313,11 @@ LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } | help: consider removing the `&mut`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:454:19 + --> $DIR/dont-suggest-ref.rs:484:19 | -LL | fn f4(&mut (X(_t), X(_u)): &mut (X, X)) { } +LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | ^^ ^^ -error: aborting due to 67 previous errors +error: aborting due to 77 previous errors For more information about this error, try `rustc --explain E0507`. From a583aa642e68ffc2735a86418ac4e0758c381791 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 16:06:08 -0700 Subject: [PATCH 15/27] Remove unnecessary comment Turns out I didn't read the original comment correctly and had some confusion about how MIR uses temporaries. --- src/librustc_mir/borrow_check/move_errors.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 44459b977242e..2dcdf1d9e456d 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -55,8 +55,6 @@ enum GroupedMoveError<'tcx> { binds_to: Vec, }, // Everything that isn't from pattern matching. - // FIXME(ashtneoi): I think this is only for moves into temporaries, as - // when returning a value. Clarification needed. OtherIllegalMove { original_path: Place<'tcx>, span: Span, From d6dbdee7398480e13bf38b1eb259c78202f7d07e Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 16:12:35 -0700 Subject: [PATCH 16/27] Remove incorrect space --- src/librustc_mir/borrow_check/move_errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 2dcdf1d9e456d..5112ae9e8d2f7 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -437,7 +437,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { if j == 0 { err.span_label(binding_span, format!("data moved here")); } else { - err.span_label(binding_span, format!("... and here")); + err.span_label(binding_span, format!("...and here")); } if binds_to.len() == 1 { From 9a0020a8794d8bcb7551e3c22bb345ee3c2b4343 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 16:45:40 -0700 Subject: [PATCH 17/27] Bless UI tests --- .../borrowck-move-error-with-note.nll.stderr | 39 ++++++-- .../borrowck-move-out-of-vec-tail.nll.stderr | 17 +++- .../borrowck-vec-pattern-nesting.nll.stderr | 62 ++++++++---- src/test/ui/borrowck/issue-51415.nll.stderr | 7 +- .../overlapping_spans.nll.stderr | 11 ++- src/test/ui/issues/issue-12567.nll.stderr | 30 +++--- src/test/ui/issues/issue-20801.nll.stderr | 8 +- .../issue-40402-1.nll.stderr | 2 +- .../issue-40402-2.nll.stderr | 12 ++- .../moves-based-on-type-block-bad.nll.stderr | 10 +- .../ui/nll/cannot-move-block-spans.nll.stderr | 18 ++-- src/test/ui/nll/move-errors.stderr | 94 +++++++++++++------ .../ui/suggestions/dont-suggest-ref.stderr | 42 ++++----- 13 files changed, 231 insertions(+), 121 deletions(-) diff --git a/src/test/ui/borrowck/borrowck-move-error-with-note.nll.stderr b/src/test/ui/borrowck/borrowck-move-error-with-note.nll.stderr index 1b913471924b7..2df520a936c9d 100644 --- a/src/test/ui/borrowck/borrowck-move-error-with-note.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-error-with-note.nll.stderr @@ -5,14 +5,24 @@ LL | match *f { //~ ERROR cannot move out of | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `f` + | help: consider removing the `*`: `f` LL | //~| cannot move out LL | Foo::Foo1(num1, - | ---- move occurs because num1 has type `std::boxed::Box`, which does not implement the `Copy` trait + | ---- data moved here LL | num2) => (), - | ---- move occurs because num2 has type `std::boxed::Box`, which does not implement the `Copy` trait + | ---- ...and here LL | Foo::Foo2(num) => (), - | --- move occurs because num has type `std::boxed::Box`, which does not implement the `Copy` trait + | --- ...and here + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/borrowck-move-error-with-note.rs:23:19 + | +LL | Foo::Foo1(num1, + | ^^^^ +LL | num2) => (), + | ^^^^ +LL | Foo::Foo2(num) => (), + | ^^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-error-with-note.rs:39:11 @@ -23,12 +33,15 @@ LL | match (S {f: "foo".to_string(), g: "bar".to_string()}) { LL | f: _s, | -- data moved here LL | g: _t - | -- ... and here -help: to prevent move, use ref or ref mut + | -- ...and here | -LL | f: ref _s, -LL | g: ref _t +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/borrowck-move-error-with-note.rs:42:16 | +LL | f: _s, + | ^^ +LL | g: _t + | ^^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-move-error-with-note.rs:57:11 @@ -37,10 +50,16 @@ LL | match a.a { //~ ERROR cannot move out of | ^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&a.a` + | help: consider borrowing here: `&a.a` LL | //~| cannot move out LL | n => { - | - move occurs because n has type `std::boxed::Box`, which does not implement the `Copy` trait + | - data moved here + | +note: move occurs because `n` has type `std::boxed::Box`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-error-with-note.rs:59:9 + | +LL | n => { + | ^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.nll.stderr b/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.nll.stderr index 95a7894d53254..f3430ba4e06c9 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.nll.stderr @@ -7,14 +7,23 @@ LL | &[Foo { string: a }, | - data moved here ... LL | Foo { string: b }] => { - | - ... and here -help: to prevent move, use ref or ref mut + | - ...and here | -LL | &[Foo { string: ref a }, +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/borrowck-move-out-of-vec-tail.rs:30:33 + | +LL | &[Foo { string: a }, + | ^ +... +LL | Foo { string: b }] => { + | ^ +help: consider removing the `&` + | +LL | [Foo { string: a }, LL | //~^ ERROR cannot move out of type `[Foo]` LL | //~| cannot move out LL | //~| to prevent move -LL | Foo { string: ref b }] => { +LL | Foo { string: b }] => { | error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.nll.stderr b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.nll.stderr index 2779132590e2c..d5b17119d85f5 100644 --- a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.nll.stderr +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.nll.stderr @@ -28,10 +28,21 @@ error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy sli LL | match vec { | ^^^ cannot move out of here LL | &mut [_a, //~ ERROR cannot move out - | -- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _a` + | -- data moved here + | +note: move occurs because `_a` has type `std::boxed::Box`, which does not implement the `Copy` trait + --> $DIR/borrowck-vec-pattern-nesting.rs:44:15 + | +LL | &mut [_a, //~ ERROR cannot move out + | ^^ +help: consider removing the `&mut` + | +LL | [_a, //~ ERROR cannot move out +LL | //~| cannot move out +LL | //~| to prevent move +LL | .. +LL | ] => { + | error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:57:13 @@ -40,7 +51,7 @@ LL | let a = vec[0]; //~ ERROR cannot move out | ^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&vec[0]` + | help: consider borrowing here: `&vec[0]` error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:64:11 @@ -49,10 +60,19 @@ LL | match vec { | ^^^ cannot move out of here ... LL | _b] => {} - | -- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _b` + | -- data moved here + | +note: move occurs because `_b` has type `std::boxed::Box`, which does not implement the `Copy` trait + --> $DIR/borrowck-vec-pattern-nesting.rs:67:10 + | +LL | _b] => {} + | ^^ +help: consider removing the `&mut` + | +LL | [ //~ ERROR cannot move out +LL | //~^ cannot move out +LL | _b] => {} + | error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:70:13 @@ -61,7 +81,7 @@ LL | let a = vec[0]; //~ ERROR cannot move out | ^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&vec[0]` + | help: consider borrowing here: `&vec[0]` error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:77:11 @@ -69,14 +89,18 @@ error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy sli LL | match vec { | ^^^ cannot move out of here LL | &mut [_a, _b, _c] => {} //~ ERROR cannot move out - | -- -- -- ... and here - | | | - | | ... and here - | data moved here -help: to prevent move, use ref or ref mut - | -LL | &mut [ref _a, ref _b, ref _c] => {} //~ ERROR cannot move out - | ^^^^^^ ^^^^^^ ^^^^^^ + | ----------------- + | | | | | + | | | | ...and here + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `[_a, _b, _c]` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/borrowck-vec-pattern-nesting.rs:78:15 + | +LL | &mut [_a, _b, _c] => {} //~ ERROR cannot move out + | ^^ ^^ ^^ error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:82:13 @@ -85,7 +109,7 @@ LL | let a = vec[0]; //~ ERROR cannot move out | ^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&vec[0]` + | help: consider borrowing here: `&vec[0]` error: aborting due to 8 previous errors diff --git a/src/test/ui/borrowck/issue-51415.nll.stderr b/src/test/ui/borrowck/issue-51415.nll.stderr index 20713c3392e8e..d4340938eebc1 100644 --- a/src/test/ui/borrowck/issue-51415.nll.stderr +++ b/src/test/ui/borrowck/issue-51415.nll.stderr @@ -5,8 +5,13 @@ LL | let opt = a.iter().enumerate().find(|(_, &s)| { | ^^^^^-^ | | | | | data moved here - | | help: to prevent move, use ref or ref mut: `ref s` | cannot move out of borrowed content + | +note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/issue-51415.rs:16:47 + | +LL | let opt = a.iter().enumerate().find(|(_, &s)| { + | ^ error: aborting due to previous error diff --git a/src/test/ui/codemap_tests/overlapping_spans.nll.stderr b/src/test/ui/codemap_tests/overlapping_spans.nll.stderr index a1fbcf1430db9..e334472f9d6e1 100644 --- a/src/test/ui/codemap_tests/overlapping_spans.nll.stderr +++ b/src/test/ui/codemap_tests/overlapping_spans.nll.stderr @@ -4,10 +4,13 @@ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait LL | match (S {f:"foo".to_string()}) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here LL | S {f:_s} => {} //~ ERROR cannot move out - | -- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | -- data moved here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/overlapping_spans.rs:21:14 + | +LL | S {f:_s} => {} //~ ERROR cannot move out + | ^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-12567.nll.stderr b/src/test/ui/issues/issue-12567.nll.stderr index 29bda252b9115..72d21d47d86fa 100644 --- a/src/test/ui/issues/issue-12567.nll.stderr +++ b/src/test/ui/issues/issue-12567.nll.stderr @@ -8,15 +8,16 @@ LL | (&[], &[hd, ..]) | (&[hd, ..], &[]) | -- data moved here ... LL | (&[hd1, ..], &[hd2, ..]) - | --- ... and here -help: to prevent move, use ref or ref mut + | --- ...and here | -LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[]) -LL | => println!("one empty"), -LL | //~^^ ERROR: cannot move out of type `[T]`, a non-copy slice -LL | //~^^^ ERROR: cannot move out of type `[T]`, a non-copy slice -LL | (&[hd1, ..], &[ref hd2, ..]) +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/issue-12567.rs:16:17 | +LL | (&[], &[hd, ..]) | (&[hd, ..], &[]) + | ^^ +... +LL | (&[hd1, ..], &[hd2, ..]) + | ^^^ error[E0508]: cannot move out of type `[T]`, a non-copy slice --> $DIR/issue-12567.rs:14:11 @@ -28,15 +29,16 @@ LL | (&[], &[hd, ..]) | (&[hd, ..], &[]) | -- data moved here ... LL | (&[hd1, ..], &[hd2, ..]) - | --- ... and here -help: to prevent move, use ref or ref mut + | --- ...and here | -LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[]) -LL | => println!("one empty"), -LL | //~^^ ERROR: cannot move out of type `[T]`, a non-copy slice -LL | //~^^^ ERROR: cannot move out of type `[T]`, a non-copy slice -LL | (&[ref hd1, ..], &[hd2, ..]) +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/issue-12567.rs:16:17 | +LL | (&[], &[hd, ..]) | (&[hd, ..], &[]) + | ^^ +... +LL | (&[hd1, ..], &[hd2, ..]) + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-20801.nll.stderr b/src/test/ui/issues/issue-20801.nll.stderr index fc94cc423c531..3a6784eed67dd 100644 --- a/src/test/ui/issues/issue-20801.nll.stderr +++ b/src/test/ui/issues/issue-20801.nll.stderr @@ -5,7 +5,7 @@ LL | let a = unsafe { *mut_ref() }; | ^^^^^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&*mut_ref()` + | help: consider removing the `*`: `mut_ref()` error[E0507]: cannot move out of borrowed content --> $DIR/issue-20801.rs:39:22 @@ -14,7 +14,7 @@ LL | let b = unsafe { *imm_ref() }; | ^^^^^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&*imm_ref()` + | help: consider removing the `*`: `imm_ref()` error[E0507]: cannot move out of borrowed content --> $DIR/issue-20801.rs:42:22 @@ -23,7 +23,7 @@ LL | let c = unsafe { *mut_ptr() }; | ^^^^^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&*mut_ptr()` + | help: consider removing the `*`: `mut_ptr()` error[E0507]: cannot move out of borrowed content --> $DIR/issue-20801.rs:45:22 @@ -32,7 +32,7 @@ LL | let d = unsafe { *const_ptr() }; | ^^^^^^^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&*const_ptr()` + | help: consider removing the `*`: `const_ptr()` error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.nll.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.nll.stderr index 162e43abc0ac4..9020d3778c373 100644 --- a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.nll.stderr +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.nll.stderr @@ -5,7 +5,7 @@ LL | let e = f.v[0]; //~ ERROR cannot move out of indexed content | ^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&f.v[0]` + | help: consider borrowing here: `&f.v[0]` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.nll.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.nll.stderr index cd75be24589df..a80e9a5fe091f 100644 --- a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.nll.stderr +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.nll.stderr @@ -5,9 +5,15 @@ LL | let (a, b) = x[0]; //~ ERROR cannot move out of indexed content | - - ^^^^ | | | | | | | cannot move out of borrowed content - | | | help: consider using a reference instead: `&x[0]` - | | move occurs because b has type `std::string::String`, which does not implement the `Copy` trait - | move occurs because a has type `std::string::String`, which does not implement the `Copy` trait + | | | help: consider borrowing here: `&x[0]` + | | ...and here + | data moved here + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/issue-40402-2.rs:15:10 + | +LL | let (a, b) = x[0]; //~ ERROR cannot move out of indexed content + | ^ ^ error: aborting due to previous error diff --git a/src/test/ui/moves/moves-based-on-type-block-bad.nll.stderr b/src/test/ui/moves/moves-based-on-type-block-bad.nll.stderr index 94f2074b45d4c..1f22ab1481852 100644 --- a/src/test/ui/moves/moves-based-on-type-block-bad.nll.stderr +++ b/src/test/ui/moves/moves-based-on-type-block-bad.nll.stderr @@ -5,10 +5,16 @@ LL | match hellothere.x { //~ ERROR cannot move out | ^^^^^^^^^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&hellothere.x` + | help: consider borrowing here: `&hellothere.x` ... LL | box E::Bar(x) => println!("{}", x.to_string()), - | - move occurs because x has type `std::boxed::Box`, which does not implement the `Copy` trait + | - data moved here + | +note: move occurs because `x` has type `std::boxed::Box`, which does not implement the `Copy` trait + --> $DIR/moves-based-on-type-block-bad.rs:37:28 + | +LL | box E::Bar(x) => println!("{}", x.to_string()), + | ^ error: aborting due to previous error diff --git a/src/test/ui/nll/cannot-move-block-spans.nll.stderr b/src/test/ui/nll/cannot-move-block-spans.nll.stderr index 814e11b6f0682..6a4c8f2e8d815 100644 --- a/src/test/ui/nll/cannot-move-block-spans.nll.stderr +++ b/src/test/ui/nll/cannot-move-block-spans.nll.stderr @@ -5,7 +5,7 @@ LL | let x = { *r }; //~ ERROR | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` error[E0507]: cannot move out of borrowed content --> $DIR/cannot-move-block-spans.rs:16:22 @@ -14,7 +14,7 @@ LL | let y = unsafe { *r }; //~ ERROR | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` error[E0507]: cannot move out of borrowed content --> $DIR/cannot-move-block-spans.rs:17:26 @@ -23,7 +23,7 @@ LL | let z = loop { break *r; }; //~ ERROR | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array --> $DIR/cannot-move-block-spans.rs:21:15 @@ -32,7 +32,7 @@ LL | let x = { arr[0] }; //~ ERROR | ^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&arr[0]` + | help: consider borrowing here: `&arr[0]` error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array --> $DIR/cannot-move-block-spans.rs:22:22 @@ -41,7 +41,7 @@ LL | let y = unsafe { arr[0] }; //~ ERROR | ^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&arr[0]` + | help: consider borrowing here: `&arr[0]` error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array --> $DIR/cannot-move-block-spans.rs:23:26 @@ -50,7 +50,7 @@ LL | let z = loop { break arr[0]; }; //~ ERROR | ^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&arr[0]` + | help: consider borrowing here: `&arr[0]` error[E0507]: cannot move out of borrowed content --> $DIR/cannot-move-block-spans.rs:27:38 @@ -59,7 +59,7 @@ LL | let x = { let mut u = 0; u += 1; *r }; //~ ERROR | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` error[E0507]: cannot move out of borrowed content --> $DIR/cannot-move-block-spans.rs:28:45 @@ -68,7 +68,7 @@ LL | let y = unsafe { let mut u = 0; u += 1; *r }; //~ ERROR | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` error[E0507]: cannot move out of borrowed content --> $DIR/cannot-move-block-spans.rs:29:49 @@ -77,7 +77,7 @@ LL | let z = loop { let mut u = 0; u += 1; break *r; u += 2; }; //~ ERROR | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `r` + | help: consider removing the `*`: `r` error: aborting due to 9 previous errors diff --git a/src/test/ui/nll/move-errors.stderr b/src/test/ui/nll/move-errors.stderr index 53d60d3f6d649..592768363096c 100644 --- a/src/test/ui/nll/move-errors.stderr +++ b/src/test/ui/nll/move-errors.stderr @@ -5,7 +5,7 @@ LL | let b = *a; | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `a` + | help: consider removing the `*`: `a` error[E0508]: cannot move out of type `[A; 1]`, a non-copy array --> $DIR/move-errors.rs:25:13 @@ -14,7 +14,7 @@ LL | let b = a[0]; | ^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&a[0]` + | help: consider borrowing here: `&a[0]` error[E0507]: cannot move out of borrowed content --> $DIR/move-errors.rs:32:13 @@ -23,7 +23,7 @@ LL | let s = **r; | ^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&**r` + | help: consider removing the `*`: `*r` error[E0507]: cannot move out of borrowed content --> $DIR/move-errors.rs:40:13 @@ -32,7 +32,7 @@ LL | let s = *r; | ^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&*r` + | help: consider removing the `*`: `r` error[E0508]: cannot move out of type `[A; 1]`, a non-copy array --> $DIR/move-errors.rs:45:13 @@ -41,7 +41,7 @@ LL | let a = [A("".to_string())][0]; | ^^^^^^^^^^^^^^^^^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&[A("".to_string())][0]` + | help: consider borrowing here: `&[A("".to_string())][0]` error[E0507]: cannot move out of borrowed content --> $DIR/move-errors.rs:51:16 @@ -50,8 +50,14 @@ LL | let A(s) = *a; | - ^^ | | | | | cannot move out of borrowed content - | | help: consider removing this dereference operator: `a` - | move occurs because s has type `std::string::String`, which does not implement the `Copy` trait + | | help: consider removing the `*`: `a` + | data moved here + | +note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/move-errors.rs:51:11 + | +LL | let A(s) = *a; + | ^ error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:57:19 @@ -60,7 +66,12 @@ LL | let C(D(s)) = c; | - ^ cannot move out of here | | | data moved here - | help: to prevent move, use ref or ref mut: `ref s` + | +note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/move-errors.rs:57:13 + | +LL | let C(D(s)) = c; + | ^ error[E0507]: cannot move out of borrowed content --> $DIR/move-errors.rs:64:9 @@ -75,12 +86,20 @@ LL | match x[0] { | ^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&x[0]` + | help: consider borrowing here: `&x[0]` LL | //~^ ERROR LL | B::U(d) => (), - | - move occurs because d has type `D`, which does not implement the `Copy` trait + | - data moved here LL | B::V(s) => (), - | - move occurs because s has type `std::string::String`, which does not implement the `Copy` trait + | - ...and here + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/move-errors.rs:89:14 + | +LL | B::U(d) => (), + | ^ +LL | B::V(s) => (), + | ^ error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:96:11 @@ -89,10 +108,13 @@ LL | match x { | ^ cannot move out of here ... LL | B::U(D(s)) => (), - | - - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref s` + | - data moved here + | +note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/move-errors.rs:99:16 + | +LL | B::U(D(s)) => (), + | ^ error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:105:11 @@ -101,10 +123,13 @@ LL | match x { | ^ cannot move out of here ... LL | (D(s), &t) => (), - | - - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref s` + | - data moved here + | +note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/move-errors.rs:108:12 + | +LL | (D(s), &t) => (), + | ^ error[E0507]: cannot move out of borrowed content --> $DIR/move-errors.rs:105:11 @@ -113,10 +138,13 @@ LL | match x { | ^ cannot move out of borrowed content ... LL | (D(s), &t) => (), - | - - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref t` + | - data moved here + | +note: move occurs because `t` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/move-errors.rs:108:17 + | +LL | (D(s), &t) => (), + | ^ error[E0509]: cannot move out of type `F`, which implements the `Drop` trait --> $DIR/move-errors.rs:115:11 @@ -125,13 +153,15 @@ LL | match x { | ^ cannot move out of here LL | //~^ ERROR LL | F(s, mut t) => (), - | - ----- ... and here + | - ----- ...and here | | | data moved here -help: to prevent move, use ref or ref mut | -LL | F(ref s, ref mut t) => (), - | ^^^^^ ^^^^^^^^^ +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/move-errors.rs:117:11 + | +LL | F(s, mut t) => (), + | ^ ^^^^^ error[E0507]: cannot move out of borrowed content --> $DIR/move-errors.rs:123:11 @@ -140,10 +170,16 @@ LL | match *x { | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `x` + | help: consider removing the `*`: `x` LL | //~^ ERROR LL | Ok(s) | Err(s) => (), - | - move occurs because s has type `std::string::String`, which does not implement the `Copy` trait + | - data moved here + | +note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/move-errors.rs:125:12 + | +LL | Ok(s) | Err(s) => (), + | ^ error: aborting due to 14 previous errors diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 00fe78d916474..7d365e8788f00 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -524,7 +524,7 @@ LL | &mut Either::One(_t) => (), | -- data moved here ... LL | &mut Either::Two(_t) => (), - | -- ... and here + | -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:233:26 @@ -705,7 +705,7 @@ LL | //~^ ERROR cannot move LL | (&mut Either::One(_t),) => (), | -- data moved here LL | (&mut Either::Two(_t),) => (), - | -- ... and here + | -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:290:27 @@ -937,7 +937,7 @@ error[E0507]: cannot move out of borrowed content LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&`: `(X(_t), X(_u))` | @@ -953,7 +953,7 @@ error[E0507]: cannot move out of borrowed content LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | @@ -969,7 +969,7 @@ error[E0507]: cannot move out of borrowed content LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | @@ -986,12 +986,12 @@ LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content LL | //~^ ERROR cannot move LL | &(Either::One(_t), Either::Two(_u)) => (), - | -- -- ... and here + | -- -- ...and here | | | data moved here ... LL | &(Either::Two(_t), Either::One(_u)) => (), - | -- ... and here -- ... and here + | -- ...and here -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:391:23 @@ -1019,7 +1019,7 @@ LL | //~^ ERROR cannot move LL | &(Either::One(_t), Either::Two(_u)) | ----------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | @@ -1038,7 +1038,7 @@ LL | //~^ ERROR cannot move LL | &(Either::One(_t), Either::Two(_u)) => (), | ----------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | @@ -1057,7 +1057,7 @@ LL | //~^ ERROR cannot move LL | &(Either::One(_t), Either::Two(_u)) => (), | ----------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | @@ -1073,7 +1073,7 @@ error[E0507]: cannot move out of borrowed content LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(X(_t), X(_u))` | @@ -1089,7 +1089,7 @@ error[E0507]: cannot move out of borrowed content LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | @@ -1105,7 +1105,7 @@ error[E0507]: cannot move out of borrowed content LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | @@ -1122,12 +1122,12 @@ LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content LL | //~^ ERROR cannot move LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | -- -- ... and here + | -- -- ...and here | | | data moved here ... LL | &mut (Either::Two(_t), Either::One(_u)) => (), - | -- ... and here -- ... and here + | -- ...and here -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait --> $DIR/dont-suggest-ref.rs:443:27 @@ -1155,7 +1155,7 @@ LL | //~^ ERROR cannot move LL | &mut (Either::One(_t), Either::Two(_u)) | --------------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | @@ -1174,7 +1174,7 @@ LL | //~^ ERROR cannot move LL | &mut (Either::One(_t), Either::Two(_u)) => (), | --------------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | @@ -1193,7 +1193,7 @@ LL | //~^ ERROR cannot move LL | &mut (Either::One(_t), Either::Two(_u)) => (), | --------------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | @@ -1212,7 +1212,7 @@ LL | //~^ ERROR cannot move LL | &mut (Either::One(_t), Either::Two(_u)) => (), | --------------------------------------- | | | | - | | | ... and here + | | | ...and here | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | @@ -1290,7 +1290,7 @@ error[E0507]: cannot move out of borrowed content LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | ^^^^--^^^^^--^^ | | | | - | | | ... and here + | | | ...and here | | data moved here | cannot move out of borrowed content | help: consider removing the `&`: `(X(_t), X(_u))` @@ -1307,7 +1307,7 @@ error[E0507]: cannot move out of borrowed content LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | ^^^^^^^^--^^^^^--^^ | | | | - | | | ... and here + | | | ...and here | | data moved here | cannot move out of borrowed content | help: consider removing the `&mut`: `(X(_t), X(_u))` From 81c27c6af74670045c1e6f8550475087861d3c76 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 21:49:39 -0700 Subject: [PATCH 18/27] Add another FIXME about suggestions --- src/test/ui/suggestions/dont-suggest-ref.rs | 4 +- .../ui/suggestions/dont-suggest-ref.stderr | 160 +++++++++--------- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index 67e8b4a0e952b..3f5b87e5ea6d1 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -263,7 +263,9 @@ pub fn main() { //~| HELP consider removing the `&mut` //~| SUGGESTION X(_t) - // -------- move from tuple of &Either/&X (no suggestions) -------- + // -------- move from tuple of &Either/&X -------- + + // FIXME: These should have suggestions. let (&X(_t),) = (&x.clone(),); //~^ ERROR cannot move diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref.stderr index 7d365e8788f00..8994152d1a5ce 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref.stderr @@ -598,7 +598,7 @@ LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:268:21 + --> $DIR/dont-suggest-ref.rs:270:21 | LL | let (&X(_t),) = (&x.clone(),); | -- ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -606,13 +606,13 @@ LL | let (&X(_t),) = (&x.clone(),); | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:268:13 + --> $DIR/dont-suggest-ref.rs:270:13 | LL | let (&X(_t),) = (&x.clone(),); | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:270:34 + --> $DIR/dont-suggest-ref.rs:272:34 | LL | if let (&Either::One(_t),) = (&e.clone(),) { } | -- ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -620,13 +620,13 @@ LL | if let (&Either::One(_t),) = (&e.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:270:26 + --> $DIR/dont-suggest-ref.rs:272:26 | LL | if let (&Either::One(_t),) = (&e.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:272:37 + --> $DIR/dont-suggest-ref.rs:274:37 | LL | while let (&Either::One(_t),) = (&e.clone(),) { } | -- ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -634,13 +634,13 @@ LL | while let (&Either::One(_t),) = (&e.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:272:29 + --> $DIR/dont-suggest-ref.rs:274:29 | LL | while let (&Either::One(_t),) = (&e.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:274:11 + --> $DIR/dont-suggest-ref.rs:276:11 | LL | match (&e.clone(),) { | ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -649,13 +649,13 @@ LL | (&Either::One(_t),) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:276:23 + --> $DIR/dont-suggest-ref.rs:278:23 | LL | (&Either::One(_t),) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:282:25 + --> $DIR/dont-suggest-ref.rs:284:25 | LL | let (&mut X(_t),) = (&mut xm.clone(),); | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -663,13 +663,13 @@ LL | let (&mut X(_t),) = (&mut xm.clone(),); | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:282:17 + --> $DIR/dont-suggest-ref.rs:284:17 | LL | let (&mut X(_t),) = (&mut xm.clone(),); | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:284:38 + --> $DIR/dont-suggest-ref.rs:286:38 | LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -677,13 +677,13 @@ LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:284:30 + --> $DIR/dont-suggest-ref.rs:286:30 | LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:286:41 + --> $DIR/dont-suggest-ref.rs:288:41 | LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -691,13 +691,13 @@ LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:286:33 + --> $DIR/dont-suggest-ref.rs:288:33 | LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:288:11 + --> $DIR/dont-suggest-ref.rs:290:11 | LL | match (&mut em.clone(),) { | ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -708,7 +708,7 @@ LL | (&mut Either::Two(_t),) => (), | -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:290:27 + --> $DIR/dont-suggest-ref.rs:292:27 | LL | (&mut Either::One(_t),) => (), | ^^ @@ -716,7 +716,7 @@ LL | (&mut Either::Two(_t),) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:298:18 + --> $DIR/dont-suggest-ref.rs:300:18 | LL | let &X(_t) = &x; | ------ ^^ cannot move out of borrowed content @@ -725,13 +725,13 @@ LL | let &X(_t) = &x; | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:298:12 + --> $DIR/dont-suggest-ref.rs:300:12 | LL | let &X(_t) = &x; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:302:31 + --> $DIR/dont-suggest-ref.rs:304:31 | LL | if let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -740,13 +740,13 @@ LL | if let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:302:25 + --> $DIR/dont-suggest-ref.rs:304:25 | LL | if let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:306:34 + --> $DIR/dont-suggest-ref.rs:308:34 | LL | while let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -755,13 +755,13 @@ LL | while let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:306:28 + --> $DIR/dont-suggest-ref.rs:308:28 | LL | while let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:310:11 + --> $DIR/dont-suggest-ref.rs:312:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -773,13 +773,13 @@ LL | &Either::One(_t) | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:312:22 + --> $DIR/dont-suggest-ref.rs:314:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:318:11 + --> $DIR/dont-suggest-ref.rs:320:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -791,13 +791,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:320:22 + --> $DIR/dont-suggest-ref.rs:322:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:325:11 + --> $DIR/dont-suggest-ref.rs:327:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -809,13 +809,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:327:22 + --> $DIR/dont-suggest-ref.rs:329:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:333:22 + --> $DIR/dont-suggest-ref.rs:335:22 | LL | let &mut X(_t) = &mut xm; | ---------- ^^^^^^^ cannot move out of borrowed content @@ -824,13 +824,13 @@ LL | let &mut X(_t) = &mut xm; | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:333:16 + --> $DIR/dont-suggest-ref.rs:335:16 | LL | let &mut X(_t) = &mut xm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:337:35 + --> $DIR/dont-suggest-ref.rs:339:35 | LL | if let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -839,13 +839,13 @@ LL | if let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:337:29 + --> $DIR/dont-suggest-ref.rs:339:29 | LL | if let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:341:38 + --> $DIR/dont-suggest-ref.rs:343:38 | LL | while let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -854,13 +854,13 @@ LL | while let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:341:32 + --> $DIR/dont-suggest-ref.rs:343:32 | LL | while let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:345:11 + --> $DIR/dont-suggest-ref.rs:347:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -872,13 +872,13 @@ LL | &mut Either::One(_t) | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:347:26 + --> $DIR/dont-suggest-ref.rs:349:26 | LL | &mut Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:353:11 + --> $DIR/dont-suggest-ref.rs:355:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -890,13 +890,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:355:26 + --> $DIR/dont-suggest-ref.rs:357:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:360:11 + --> $DIR/dont-suggest-ref.rs:362:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -908,13 +908,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:362:26 + --> $DIR/dont-suggest-ref.rs:364:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:367:11 + --> $DIR/dont-suggest-ref.rs:369:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -926,13 +926,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:369:26 + --> $DIR/dont-suggest-ref.rs:371:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:377:27 + --> $DIR/dont-suggest-ref.rs:379:27 | LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -942,13 +942,13 @@ LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | help: consider removing the `&`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:377:13 + --> $DIR/dont-suggest-ref.rs:379:13 | LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:381:50 + --> $DIR/dont-suggest-ref.rs:383:50 | LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -958,13 +958,13 @@ LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:381:26 + --> $DIR/dont-suggest-ref.rs:383:26 | LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:385:53 + --> $DIR/dont-suggest-ref.rs:387:53 | LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -974,13 +974,13 @@ LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:385:29 + --> $DIR/dont-suggest-ref.rs:387:29 | LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:389:11 + --> $DIR/dont-suggest-ref.rs:391:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -994,7 +994,7 @@ LL | &(Either::Two(_t), Either::One(_u)) => (), | -- ...and here -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:391:23 + --> $DIR/dont-suggest-ref.rs:393:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ @@ -1011,7 +1011,7 @@ LL | (Either::Two(_t), Either::One(_u)) => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:399:11 + --> $DIR/dont-suggest-ref.rs:401:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1024,13 +1024,13 @@ LL | &(Either::One(_t), Either::Two(_u)) | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:401:23 + --> $DIR/dont-suggest-ref.rs:403:23 | LL | &(Either::One(_t), Either::Two(_u)) | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:408:11 + --> $DIR/dont-suggest-ref.rs:410:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1043,13 +1043,13 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:410:23 + --> $DIR/dont-suggest-ref.rs:412:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:416:11 + --> $DIR/dont-suggest-ref.rs:418:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1062,13 +1062,13 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:418:23 + --> $DIR/dont-suggest-ref.rs:420:23 | LL | &(Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:429:31 + --> $DIR/dont-suggest-ref.rs:431:31 | LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1078,13 +1078,13 @@ LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | help: consider removing the `&mut`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:429:17 + --> $DIR/dont-suggest-ref.rs:431:17 | LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:433:54 + --> $DIR/dont-suggest-ref.rs:435:54 | LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1094,13 +1094,13 @@ LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.c | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:433:30 + --> $DIR/dont-suggest-ref.rs:435:30 | LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:437:57 + --> $DIR/dont-suggest-ref.rs:439:57 | LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1110,13 +1110,13 @@ LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), e | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:437:33 + --> $DIR/dont-suggest-ref.rs:439:33 | LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:441:11 + --> $DIR/dont-suggest-ref.rs:443:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1130,7 +1130,7 @@ LL | &mut (Either::Two(_t), Either::One(_u)) => (), | -- ...and here -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:443:27 + --> $DIR/dont-suggest-ref.rs:445:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ @@ -1147,7 +1147,7 @@ LL | (Either::Two(_t), Either::One(_u)) => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:451:11 + --> $DIR/dont-suggest-ref.rs:453:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1160,13 +1160,13 @@ LL | &mut (Either::One(_t), Either::Two(_u)) | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:453:27 + --> $DIR/dont-suggest-ref.rs:455:27 | LL | &mut (Either::One(_t), Either::Two(_u)) | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:460:11 + --> $DIR/dont-suggest-ref.rs:462:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1179,13 +1179,13 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:462:27 + --> $DIR/dont-suggest-ref.rs:464:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:468:11 + --> $DIR/dont-suggest-ref.rs:470:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1198,13 +1198,13 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:470:27 + --> $DIR/dont-suggest-ref.rs:472:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:476:11 + --> $DIR/dont-suggest-ref.rs:478:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -1217,7 +1217,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:478:27 + --> $DIR/dont-suggest-ref.rs:480:27 | LL | &mut (Either::One(_t), Either::Two(_u)) => (), | ^^ ^^ @@ -1255,7 +1255,7 @@ LL | fn f2(&mut X(_t): &mut X) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:279:11 + --> $DIR/dont-suggest-ref.rs:281:11 | LL | fn f3((&X(_t),): (&X,)) { } | ^^^^--^^^ @@ -1264,13 +1264,13 @@ LL | fn f3((&X(_t),): (&X,)) { } | cannot move out of borrowed content | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:279:15 + --> $DIR/dont-suggest-ref.rs:281:15 | LL | fn f3((&X(_t),): (&X,)) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:293:11 + --> $DIR/dont-suggest-ref.rs:295:11 | LL | fn f4((&mut X(_t),): (&mut X,)) { } | ^^^^^^^^--^^^ @@ -1279,13 +1279,13 @@ LL | fn f4((&mut X(_t),): (&mut X,)) { } | cannot move out of borrowed content | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:293:19 + --> $DIR/dont-suggest-ref.rs:295:19 | LL | fn f4((&mut X(_t),): (&mut X,)) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:424:11 + --> $DIR/dont-suggest-ref.rs:426:11 | LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | ^^^^--^^^^^--^^ @@ -1296,13 +1296,13 @@ LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | help: consider removing the `&`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:424:15 + --> $DIR/dont-suggest-ref.rs:426:15 | LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | ^^ ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:484:11 + --> $DIR/dont-suggest-ref.rs:486:11 | LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | ^^^^^^^^--^^^^^--^^ @@ -1313,7 +1313,7 @@ LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | help: consider removing the `&mut`: `(X(_t), X(_u))` | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:484:19 + --> $DIR/dont-suggest-ref.rs:486:19 | LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | ^^ ^^ From 3c3a7bad499c8606566a0c39f38983a582b8c4c8 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 22:01:54 -0700 Subject: [PATCH 19/27] Allocate fewer Strings at a time --- src/librustc_mir/borrow_check/move_errors.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 5112ae9e8d2f7..d6c875bab44f9 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -383,7 +383,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], ) { - let mut suggestions: Vec<(Span, String, String)> = Vec::new(); + let mut suggestions: Vec<(Span, &str, String)> = Vec::new(); for local in binds_to { let bind_to = &self.mir.local_decls[*local]; if let Some( @@ -411,7 +411,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } suggestions.push(( pat_span, - format!("consider removing the `{}`", to_remove), + to_remove, suggestion.to_owned(), )); } @@ -419,8 +419,12 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } suggestions.sort_unstable_by_key(|&(span, _, _)| span); suggestions.dedup_by_key(|&mut (span, _, _)| span); - for (span, msg, suggestion) in suggestions { - err.span_suggestion(span, &msg, suggestion); + for (span, to_remove, suggestion) in suggestions { + err.span_suggestion( + span, + &format!("consider removing the `{}`", to_remove), + suggestion + ); } } From 6a24abbbc552ac94e8b18cbc1ef38414d192c60f Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 13 Aug 2018 23:49:21 -0700 Subject: [PATCH 20/27] Fix compiletest JSON error message --- src/tools/compiletest/src/json.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 201a661726e91..58220ba992c7a 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -82,7 +82,7 @@ pub fn extract_rendered(output: &str, proc_res: &ProcRes) -> String { Err(error) => { proc_res.fatal(Some(&format!( "failed to decode compiler output as json: \ - `{}`\noutput: {}\nline: {}", + `{}`\nline: {}\noutput: {}", error, line, output ))); } @@ -114,7 +114,7 @@ fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) -> Err(error) => { proc_res.fatal(Some(&format!( "failed to decode compiler output as json: \ - `{}`\noutput: {}\nline: {}", + `{}`\nline: {}\noutput: {}", error, line, output ))); } From a5b008c45065989e58a1afa5809df0daac481a75 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 14 Aug 2018 11:56:20 -0700 Subject: [PATCH 21/27] Test move-into-Fn/FnMut errors too --- .../dont-suggest-ref-in-closure.rs | 171 +++++++++ .../dont-suggest-ref-in-closure.stderr | 357 ++++++++++++++++++ src/test/ui/suggestions/dont-suggest-ref.rs | 4 +- 3 files changed, 530 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/suggestions/dont-suggest-ref-in-closure.rs create mode 100644 src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr diff --git a/src/test/ui/suggestions/dont-suggest-ref-in-closure.rs b/src/test/ui/suggestions/dont-suggest-ref-in-closure.rs new file mode 100644 index 0000000000000..8cc847e693fa7 --- /dev/null +++ b/src/test/ui/suggestions/dont-suggest-ref-in-closure.rs @@ -0,0 +1,171 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(nll)] + +#[derive(Clone)] +enum Either { + One(X), + Two(X), +} + +#[derive(Clone)] +struct X(Y); + +#[derive(Clone)] +struct Y; + +fn consume_fn(_f: F) { } + +fn consume_fnmut(_f: F) { } + +pub fn main() { } + +fn move_into_fn() { + let e = Either::One(X(Y)); + let mut em = Either::One(X(Y)); + + let x = X(Y); + + // -------- move into Fn -------- + + consume_fn(|| { + let X(_t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &x + if let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + while let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + Either::One(_t) + | Either::Two(_t) => (), + } + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + Either::One(_t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + + let X(mut _t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &x + if let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + while let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + Either::One(mut _t) + | Either::Two(mut _t) => (), + } + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + Either::One(mut _t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + }); +} + +fn move_into_fnmut() { + let e = Either::One(X(Y)); + let mut em = Either::One(X(Y)); + + let x = X(Y); + + // -------- move into FnMut -------- + + consume_fnmut(|| { + let X(_t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &x + if let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + while let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + Either::One(_t) + | Either::Two(_t) => (), + } + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &e + Either::One(_t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + + let X(mut _t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &x + if let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + while let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + Either::One(mut _t) + | Either::Two(mut _t) => (), + } + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + Either::One(mut _t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + //~| SUGGESTION &em + Either::One(mut _t) => (), + Either::Two(ref mut _t) => (), + // FIXME: should suggest removing `ref` too + } + }); +} diff --git a/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr b/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr new file mode 100644 index 0000000000000..d90773786e58d --- /dev/null +++ b/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr @@ -0,0 +1,357 @@ +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:40:21 + | +LL | let X(_t) = x; + | -- ^ + | | | + | | cannot move out of captured variable in an `Fn` closure + | | help: consider borrowing here: `&x` + | data moved here + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:40:15 + | +LL | let X(_t) = x; + | ^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:44:34 + | +LL | if let Either::One(_t) = e { } + | -- ^ + | | | + | | cannot move out of captured variable in an `Fn` closure + | | help: consider borrowing here: `&e` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:44:28 + | +LL | if let Either::One(_t) = e { } + | ^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:48:37 + | +LL | while let Either::One(_t) = e { } + | -- ^ + | | | + | | cannot move out of captured variable in an `Fn` closure + | | help: consider borrowing here: `&e` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:48:31 + | +LL | while let Either::One(_t) = e { } + | ^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:52:15 + | +LL | match e { + | ^ + | | + | cannot move out of captured variable in an `Fn` closure + | help: consider borrowing here: `&e` +... +LL | Either::One(_t) + | -- data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:56:25 + | +LL | Either::One(_t) + | ^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:59:15 + | +LL | match e { + | ^ + | | + | cannot move out of captured variable in an `Fn` closure + | help: consider borrowing here: `&e` +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:63:25 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:68:25 + | +LL | let X(mut _t) = x; + | ------ ^ + | | | + | | cannot move out of captured variable in an `Fn` closure + | | help: consider borrowing here: `&x` + | data moved here + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:68:15 + | +LL | let X(mut _t) = x; + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:72:38 + | +LL | if let Either::One(mut _t) = em { } + | ------ ^^ + | | | + | | cannot move out of captured variable in an `Fn` closure + | | help: consider borrowing here: `&em` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:72:28 + | +LL | if let Either::One(mut _t) = em { } + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:76:41 + | +LL | while let Either::One(mut _t) = em { } + | ------ ^^ + | | | + | | cannot move out of captured variable in an `Fn` closure + | | help: consider borrowing here: `&em` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:76:31 + | +LL | while let Either::One(mut _t) = em { } + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:80:15 + | +LL | match em { + | ^^ + | | + | cannot move out of captured variable in an `Fn` closure + | help: consider borrowing here: `&em` +... +LL | Either::One(mut _t) + | ------ data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:84:25 + | +LL | Either::One(mut _t) + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `Fn` closure + --> $DIR/dont-suggest-ref-in-closure.rs:87:15 + | +LL | match em { + | ^^ + | | + | cannot move out of captured variable in an `Fn` closure + | help: consider borrowing here: `&em` +... +LL | Either::One(mut _t) => (), + | ------ data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:91:25 + | +LL | Either::One(mut _t) => (), + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:107:21 + | +LL | let X(_t) = x; + | -- ^ + | | | + | | cannot move out of captured variable in an `FnMut` closure + | | help: consider borrowing here: `&x` + | data moved here + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:107:15 + | +LL | let X(_t) = x; + | ^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:111:34 + | +LL | if let Either::One(_t) = e { } + | -- ^ + | | | + | | cannot move out of captured variable in an `FnMut` closure + | | help: consider borrowing here: `&e` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:111:28 + | +LL | if let Either::One(_t) = e { } + | ^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:115:37 + | +LL | while let Either::One(_t) = e { } + | -- ^ + | | | + | | cannot move out of captured variable in an `FnMut` closure + | | help: consider borrowing here: `&e` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:115:31 + | +LL | while let Either::One(_t) = e { } + | ^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:119:15 + | +LL | match e { + | ^ + | | + | cannot move out of captured variable in an `FnMut` closure + | help: consider borrowing here: `&e` +... +LL | Either::One(_t) + | -- data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:123:25 + | +LL | Either::One(_t) + | ^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:126:15 + | +LL | match e { + | ^ + | | + | cannot move out of captured variable in an `FnMut` closure + | help: consider borrowing here: `&e` +... +LL | Either::One(_t) => (), + | -- data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:130:25 + | +LL | Either::One(_t) => (), + | ^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:135:25 + | +LL | let X(mut _t) = x; + | ------ ^ + | | | + | | cannot move out of captured variable in an `FnMut` closure + | | help: consider borrowing here: `&x` + | data moved here + | +note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:135:15 + | +LL | let X(mut _t) = x; + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:139:38 + | +LL | if let Either::One(mut _t) = em { } + | ------ ^^ + | | | + | | cannot move out of captured variable in an `FnMut` closure + | | help: consider borrowing here: `&em` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:139:28 + | +LL | if let Either::One(mut _t) = em { } + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:143:41 + | +LL | while let Either::One(mut _t) = em { } + | ------ ^^ + | | | + | | cannot move out of captured variable in an `FnMut` closure + | | help: consider borrowing here: `&em` + | data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:143:31 + | +LL | while let Either::One(mut _t) = em { } + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:147:15 + | +LL | match em { + | ^^ + | | + | cannot move out of captured variable in an `FnMut` closure + | help: consider borrowing here: `&em` +... +LL | Either::One(mut _t) + | ------ data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:151:25 + | +LL | Either::One(mut _t) + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:154:15 + | +LL | match em { + | ^^ + | | + | cannot move out of captured variable in an `FnMut` closure + | help: consider borrowing here: `&em` +... +LL | Either::One(mut _t) => (), + | ------ data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:158:25 + | +LL | Either::One(mut _t) => (), + | ^^^^^^ + +error[E0507]: cannot move out of captured variable in an `FnMut` closure + --> $DIR/dont-suggest-ref-in-closure.rs:162:15 + | +LL | match em { + | ^^ + | | + | cannot move out of captured variable in an `FnMut` closure + | help: consider borrowing here: `&em` +... +LL | Either::One(mut _t) => (), + | ------ data moved here + | +note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait + --> $DIR/dont-suggest-ref-in-closure.rs:166:25 + | +LL | Either::One(mut _t) => (), + | ^^^^^^ + +error: aborting due to 21 previous errors + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref.rs index 3f5b87e5ea6d1..3bd6102c5d648 100644 --- a/src/test/ui/suggestions/dont-suggest-ref.rs +++ b/src/test/ui/suggestions/dont-suggest-ref.rs @@ -108,7 +108,7 @@ pub fn main() { //~| SUGGESTION rm Either::One(_t) => (), Either::Two(ref mut _t) => (), - // FIXME: should suggest removing `ref mut` too + // FIXME: should suggest removing `ref` too } let X(_t) = vs[0]; @@ -172,7 +172,7 @@ pub fn main() { //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref mut _t) => (), - // FIXME: should suggest removing `ref mut` too + // FIXME: should suggest removing `ref` too } // -------- move from &Either/&X place -------- From bd2b54c23c9eb11175edf99233186c77f476d7af Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 14 Aug 2018 12:38:37 -0700 Subject: [PATCH 22/27] Bless tests --- src/test/ui/E0508-fail.mir.stderr | 2 +- .../ui/access-mode-in-closures.nll.stderr | 10 ++++- ...or-loop-correct-cmt-for-pattern.nll.stderr | 42 +++++++++++++------ .../borrowck/borrowck-issue-2657-2.nll.stderr | 2 +- .../borrowck-move-from-unsafe-ptr.nll.stderr | 2 +- ...orrowck-move-in-irrefut-pat.ast.nll.stderr | 30 ++++++++++--- .../borrowck-move-in-irrefut-pat.mir.stderr | 30 ++++++++++--- ...ove-out-of-struct-with-dtor.ast.nll.stderr | 25 ++++++++--- ...ck-move-out-of-struct-with-dtor.mir.stderr | 25 ++++++++--- ...e-out-of-tuple-struct-with-dtor.nll.stderr | 25 ++++++++--- ...-overloaded-index-move-from-vec.nll.stderr | 2 +- .../ui/by-move-pattern-binding.nll.stderr | 14 +++++-- ...check-static-values-constraints.nll.stderr | 2 +- ...tructing-destructing-struct-let.nll.stderr | 7 +++- ...ucting-destructing-struct-match.nll.stderr | 11 +++-- .../ui/moves/move-out-of-slice-1.nll.stderr | 11 +++-- 16 files changed, 178 insertions(+), 62 deletions(-) diff --git a/src/test/ui/E0508-fail.mir.stderr b/src/test/ui/E0508-fail.mir.stderr index faf7411af317b..fda6c24dc8710 100644 --- a/src/test/ui/E0508-fail.mir.stderr +++ b/src/test/ui/E0508-fail.mir.stderr @@ -5,7 +5,7 @@ LL | let _value = array[0]; //[ast]~ ERROR [E0508] | ^^^^^^^^ | | | cannot move out of here - | help: consider using a reference instead: `&array[0]` + | help: consider borrowing here: `&array[0]` error: aborting due to previous error diff --git a/src/test/ui/access-mode-in-closures.nll.stderr b/src/test/ui/access-mode-in-closures.nll.stderr index 2aa8f1c381309..b9de60f43f703 100644 --- a/src/test/ui/access-mode-in-closures.nll.stderr +++ b/src/test/ui/access-mode-in-closures.nll.stderr @@ -2,10 +2,16 @@ error[E0507]: cannot move out of borrowed content --> $DIR/access-mode-in-closures.rs:19:15 | LL | match *s { sty(v) => v } //~ ERROR cannot move out - | ^^ - move occurs because v has type `std::vec::Vec`, which does not implement the `Copy` trait + | ^^ - data moved here | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `s` + | help: consider removing the `*`: `s` + | +note: move occurs because `v` has type `std::vec::Vec`, which does not implement the `Copy` trait + --> $DIR/access-mode-in-closures.rs:19:24 + | +LL | match *s { sty(v) => v } //~ ERROR cannot move out + | ^ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.nll.stderr b/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.nll.stderr index f9e517def1406..25eb69ad9377d 100644 --- a/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.nll.stderr +++ b/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.nll.stderr @@ -2,28 +2,46 @@ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:15 | LL | for &a in x.iter() { //~ ERROR cannot move out - | - ^^^^^^^^ cannot move out of borrowed content - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref a` + | -- ^^^^^^^^ cannot move out of borrowed content + | || + | |data moved here + | help: consider removing the `&`: `a` + | +note: move occurs because `a` has type `&mut i32`, which does not implement the `Copy` trait + --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:10 + | +LL | for &a in x.iter() { //~ ERROR cannot move out + | ^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:28:15 | LL | for &a in &f.a { //~ ERROR cannot move out - | - ^^^^ cannot move out of borrowed content - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref a` + | -- ^^^^ cannot move out of borrowed content + | || + | |data moved here + | help: consider removing the `&`: `a` + | +note: move occurs because `a` has type `std::boxed::Box`, which does not implement the `Copy` trait + --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:28:10 + | +LL | for &a in &f.a { //~ ERROR cannot move out + | ^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:32:15 | LL | for &a in x.iter() { //~ ERROR cannot move out - | - ^^^^^^^^ cannot move out of borrowed content - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref a` + | -- ^^^^^^^^ cannot move out of borrowed content + | || + | |data moved here + | help: consider removing the `&`: `a` + | +note: move occurs because `a` has type `std::boxed::Box`, which does not implement the `Copy` trait + --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:32:10 + | +LL | for &a in x.iter() { //~ ERROR cannot move out + | ^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-issue-2657-2.nll.stderr b/src/test/ui/borrowck/borrowck-issue-2657-2.nll.stderr index 55c6a40d281bc..cdbfab8bd054a 100644 --- a/src/test/ui/borrowck/borrowck-issue-2657-2.nll.stderr +++ b/src/test/ui/borrowck/borrowck-issue-2657-2.nll.stderr @@ -5,7 +5,7 @@ LL | let _b = *y; //~ ERROR cannot move out | ^^ | | | cannot move out of borrowed content - | help: consider removing this dereference operator: `y` + | help: consider removing the `*`: `y` error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr b/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr index 4f692bfc55e42..f823a6f08d789 100644 --- a/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr @@ -5,7 +5,7 @@ LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer | ^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&*x` + | help: consider removing the `*`: `x` error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.ast.nll.stderr b/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.ast.nll.stderr index f670936dbac17..49c2ec0dcf4e7 100644 --- a/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.ast.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.ast.nll.stderr @@ -5,8 +5,14 @@ LL | fn arg_item(&_x: &String) {} | ^-- | || | |data moved here - | |help: to prevent move, use ref or ref mut: `ref _x` | cannot move out of borrowed content + | help: consider removing the `&`: `_x` + | +note: move occurs because `_x` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-in-irrefut-pat.rs:16:14 + | +LL | fn arg_item(&_x: &String) {} + | ^^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-move-in-irrefut-pat.rs:21:11 @@ -15,17 +21,29 @@ LL | with(|&_x| ()) | ^-- | || | |data moved here - | |help: to prevent move, use ref or ref mut: `ref _x` | cannot move out of borrowed content + | help: consider removing the `&`: `_x` + | +note: move occurs because `_x` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-in-irrefut-pat.rs:21:12 + | +LL | with(|&_x| ()) + | ^^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-move-in-irrefut-pat.rs:27:15 | LL | let &_x = &"hi".to_string(); - | -- ^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _x` + | --- ^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | || + | |data moved here + | help: consider removing the `&`: `_x` + | +note: move occurs because `_x` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-in-irrefut-pat.rs:27:10 + | +LL | let &_x = &"hi".to_string(); + | ^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.mir.stderr b/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.mir.stderr index f670936dbac17..49c2ec0dcf4e7 100644 --- a/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.mir.stderr +++ b/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.mir.stderr @@ -5,8 +5,14 @@ LL | fn arg_item(&_x: &String) {} | ^-- | || | |data moved here - | |help: to prevent move, use ref or ref mut: `ref _x` | cannot move out of borrowed content + | help: consider removing the `&`: `_x` + | +note: move occurs because `_x` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-in-irrefut-pat.rs:16:14 + | +LL | fn arg_item(&_x: &String) {} + | ^^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-move-in-irrefut-pat.rs:21:11 @@ -15,17 +21,29 @@ LL | with(|&_x| ()) | ^-- | || | |data moved here - | |help: to prevent move, use ref or ref mut: `ref _x` | cannot move out of borrowed content + | help: consider removing the `&`: `_x` + | +note: move occurs because `_x` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-in-irrefut-pat.rs:21:12 + | +LL | with(|&_x| ()) + | ^^ error[E0507]: cannot move out of borrowed content --> $DIR/borrowck-move-in-irrefut-pat.rs:27:15 | LL | let &_x = &"hi".to_string(); - | -- ^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _x` + | --- ^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | || + | |data moved here + | help: consider removing the `&`: `_x` + | +note: move occurs because `_x` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-in-irrefut-pat.rs:27:10 + | +LL | let &_x = &"hi".to_string(); + | ^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.ast.nll.stderr b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.ast.nll.stderr index 15c7011d71671..34f9f035188b8 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.ast.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.ast.nll.stderr @@ -5,10 +5,13 @@ LL | match (S {f:"foo".to_string()}) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here LL | //[mir]~^ ERROR [E0509] LL | S {f:_s} => {} - | -- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | -- data moved here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:22:14 + | +LL | S {f:_s} => {} + | ^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:28:20 @@ -17,7 +20,12 @@ LL | let S {f:_s} = S {f:"foo".to_string()}; | -- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here | | | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:28:14 + | +LL | let S {f:_s} = S {f:"foo".to_string()}; + | ^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:33:19 @@ -26,8 +34,13 @@ LL | fn move_in_fn_arg(S {f:_s}: S) { | ^^^^^--^ | | | | | data moved here - | | help: to prevent move, use ref or ref mut: `ref _s` | cannot move out of here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:33:24 + | +LL | fn move_in_fn_arg(S {f:_s}: S) { + | ^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.mir.stderr b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.mir.stderr index 15c7011d71671..34f9f035188b8 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.mir.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.mir.stderr @@ -5,10 +5,13 @@ LL | match (S {f:"foo".to_string()}) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here LL | //[mir]~^ ERROR [E0509] LL | S {f:_s} => {} - | -- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | -- data moved here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:22:14 + | +LL | S {f:_s} => {} + | ^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:28:20 @@ -17,7 +20,12 @@ LL | let S {f:_s} = S {f:"foo".to_string()}; | -- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here | | | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:28:14 + | +LL | let S {f:_s} = S {f:"foo".to_string()}; + | ^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:33:19 @@ -26,8 +34,13 @@ LL | fn move_in_fn_arg(S {f:_s}: S) { | ^^^^^--^ | | | | | data moved here - | | help: to prevent move, use ref or ref mut: `ref _s` | cannot move out of here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:33:24 + | +LL | fn move_in_fn_arg(S {f:_s}: S) { + | ^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.nll.stderr b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.nll.stderr index c69ae8755a957..278c33c71e245 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.nll.stderr @@ -4,10 +4,13 @@ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait LL | match S("foo".to_string()) { | ^^^^^^^^^^^^^^^^^^^^ cannot move out of here LL | S(_s) => {} - | -- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | -- data moved here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:18:11 + | +LL | S(_s) => {} + | ^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:24:17 @@ -16,7 +19,12 @@ LL | let S(_s) = S("foo".to_string()); | -- ^^^^^^^^^^^^^^^^^^^^ cannot move out of here | | | data moved here - | help: to prevent move, use ref or ref mut: `ref _s` + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:24:11 + | +LL | let S(_s) = S("foo".to_string()); + | ^^ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:28:19 @@ -25,8 +33,13 @@ LL | fn move_in_fn_arg(S(_s): S) { | ^^--^ | | | | | data moved here - | | help: to prevent move, use ref or ref mut: `ref _s` | cannot move out of here + | +note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:28:21 + | +LL | fn move_in_fn_arg(S(_s): S) { + | ^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.nll.stderr b/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.nll.stderr index 4a72d7f330266..92e10c258c269 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.nll.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.nll.stderr @@ -5,7 +5,7 @@ LL | let bad = v[0]; | ^^^^ | | | cannot move out of borrowed content - | help: consider using a reference instead: `&v[0]` + | help: consider borrowing here: `&v[0]` error: aborting due to previous error diff --git a/src/test/ui/by-move-pattern-binding.nll.stderr b/src/test/ui/by-move-pattern-binding.nll.stderr index 4ba9b3aeb5d5d..491b5b5bd74ab 100644 --- a/src/test/ui/by-move-pattern-binding.nll.stderr +++ b/src/test/ui/by-move-pattern-binding.nll.stderr @@ -5,10 +5,16 @@ LL | match &s.x { | ^^^^ cannot move out of borrowed content LL | &E::Foo => {} LL | &E::Bar(identifier) => f(identifier.clone()) //~ ERROR cannot move - | ---------- - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref identifier` + | ------------------- + | | | + | | data moved here + | help: consider removing the `&`: `E::Bar(identifier)` + | +note: move occurs because `identifier` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/by-move-pattern-binding.rs:26:17 + | +LL | &E::Bar(identifier) => f(identifier.clone()) //~ ERROR cannot move + | ^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/check-static-values-constraints.nll.stderr b/src/test/ui/check-static-values-constraints.nll.stderr index b265ec8bddac6..5522e22fb1fa2 100644 --- a/src/test/ui/check-static-values-constraints.nll.stderr +++ b/src/test/ui/check-static-values-constraints.nll.stderr @@ -56,7 +56,7 @@ LL | let y = { static x: Box = box 3; x }; | ^ | | | cannot move out of static item - | help: consider using a reference instead: `&x` + | help: consider borrowing here: `&x` error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:120:38 diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.nll.stderr b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.nll.stderr index a8be048d7df6c..8e0599370287f 100644 --- a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.nll.stderr +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.nll.stderr @@ -5,7 +5,12 @@ LL | let X { x: y } = x; //~ ERROR cannot move out of type | - ^ cannot move out of here | | | data moved here - | help: to prevent move, use ref or ref mut: `ref y` + | +note: move occurs because `y` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/disallowed-deconstructing-destructing-struct-let.rs:22:16 + | +LL | let X { x: y } = x; //~ ERROR cannot move out of type + | ^ error: aborting due to previous error diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.nll.stderr b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.nll.stderr index 9f0d2d5f0e189..dd1a3ef2a2b98 100644 --- a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.nll.stderr +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.nll.stderr @@ -4,10 +4,13 @@ error[E0509]: cannot move out of type `X`, which implements the `Drop` trait LL | match x { | ^ cannot move out of here LL | X { x: y } => println!("contents: {}", y) - | - - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref y` + | - data moved here + | +note: move occurs because `y` has type `std::string::String`, which does not implement the `Copy` trait + --> $DIR/disallowed-deconstructing-destructing-struct-match.rs:25:16 + | +LL | X { x: y } => println!("contents: {}", y) + | ^ error: aborting due to previous error diff --git a/src/test/ui/moves/move-out-of-slice-1.nll.stderr b/src/test/ui/moves/move-out-of-slice-1.nll.stderr index b061b6a796385..aa62b457ecdf3 100644 --- a/src/test/ui/moves/move-out-of-slice-1.nll.stderr +++ b/src/test/ui/moves/move-out-of-slice-1.nll.stderr @@ -4,10 +4,13 @@ error[E0508]: cannot move out of type `[A]`, a non-copy slice LL | match a { | ^ cannot move out of here LL | box [a] => {}, //~ ERROR cannot move out of type `[A]`, a non-copy slice - | - - | | - | data moved here - | help: to prevent move, use ref or ref mut: `ref a` + | - data moved here + | +note: move occurs because `a` has type `A`, which does not implement the `Copy` trait + --> $DIR/move-out-of-slice-1.rs:18:14 + | +LL | box [a] => {}, //~ ERROR cannot move out of type `[A]`, a non-copy slice + | ^ error: aborting due to previous error From 671d7e064f69bdd6287ffd6b1b727be11f5e0165 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 14 Aug 2018 12:54:31 -0700 Subject: [PATCH 23/27] Change a method name and clarify a comment --- src/librustc_mir/borrow_check/move_errors.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index d6c875bab44f9..56ca4db098f87 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -347,8 +347,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { _ => false, }; if try_remove_deref && snippet.starts_with('*') { - // This is false for (e.g.) index expressions `a[b]`, - // which roughly desugar to `*Index::index(&a, b)` or + // The snippet doesn't start with `*` in (e.g.) index + // expressions `a[b]`, which roughly desugar to + // `*Index::index(&a, b)` or // `*IndexMut::index_mut(&mut a, b)`. err.span_suggestion( span, @@ -365,13 +366,13 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { binds_to.sort(); binds_to.dedup(); - self.add_move_error_labels(err, &binds_to); + self.add_move_error_details(err, &binds_to); } GroupedMoveError::MovesFromValue { mut binds_to, .. } => { binds_to.sort(); binds_to.dedup(); self.add_move_error_suggestions(err, &binds_to); - self.add_move_error_labels(err, &binds_to); + self.add_move_error_details(err, &binds_to); } // No binding. Nothing to suggest. GroupedMoveError::OtherIllegalMove { .. } => (), @@ -428,7 +429,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } - fn add_move_error_labels( + fn add_move_error_details( &self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], From 4c4e1ef2c585ce38751351b15d687ab2f74a8ded Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Tue, 14 Aug 2018 19:03:43 -0700 Subject: [PATCH 24/27] Add files I forgot to commit earlier --- src/test/ui/E0508-fail.ast.nll.stderr | 12 ++++++ src/test/ui/E0508.nll.stderr | 12 ++++++ ...ck-move-out-of-overloaded-deref.nll.stderr | 12 ++++++ src/test/ui/error-codes/E0509.nll.stderr | 12 ++++++ .../issues/issue-17718-static-move.nll.stderr | 12 ++++++ src/test/ui/std-uncopyable-atomics.nll.stderr | 39 +++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 src/test/ui/E0508-fail.ast.nll.stderr create mode 100644 src/test/ui/E0508.nll.stderr create mode 100644 src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.nll.stderr create mode 100644 src/test/ui/error-codes/E0509.nll.stderr create mode 100644 src/test/ui/issues/issue-17718-static-move.nll.stderr create mode 100644 src/test/ui/std-uncopyable-atomics.nll.stderr diff --git a/src/test/ui/E0508-fail.ast.nll.stderr b/src/test/ui/E0508-fail.ast.nll.stderr new file mode 100644 index 0000000000000..fda6c24dc8710 --- /dev/null +++ b/src/test/ui/E0508-fail.ast.nll.stderr @@ -0,0 +1,12 @@ +error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array + --> $DIR/E0508-fail.rs:18:18 + | +LL | let _value = array[0]; //[ast]~ ERROR [E0508] + | ^^^^^^^^ + | | + | cannot move out of here + | help: consider borrowing here: `&array[0]` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0508`. diff --git a/src/test/ui/E0508.nll.stderr b/src/test/ui/E0508.nll.stderr new file mode 100644 index 0000000000000..025ff874bced4 --- /dev/null +++ b/src/test/ui/E0508.nll.stderr @@ -0,0 +1,12 @@ +error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array + --> $DIR/E0508.rs:15:18 + | +LL | let _value = array[0]; //~ ERROR [E0508] + | ^^^^^^^^ + | | + | cannot move out of here + | help: consider borrowing here: `&array[0]` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0508`. diff --git a/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.nll.stderr b/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.nll.stderr new file mode 100644 index 0000000000000..b9c47e6e8cfe9 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.nll.stderr @@ -0,0 +1,12 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/borrowck-move-out-of-overloaded-deref.rs:14:14 + | +LL | let _x = *Rc::new("hi".to_string()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | cannot move out of borrowed content + | help: consider removing the `*`: `Rc::new("hi".to_string())` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/error-codes/E0509.nll.stderr b/src/test/ui/error-codes/E0509.nll.stderr new file mode 100644 index 0000000000000..723b083b90442 --- /dev/null +++ b/src/test/ui/error-codes/E0509.nll.stderr @@ -0,0 +1,12 @@ +error[E0509]: cannot move out of type `DropStruct`, which implements the `Drop` trait + --> $DIR/E0509.rs:26:23 + | +LL | let fancy_field = drop_struct.fancy; //~ ERROR E0509 + | ^^^^^^^^^^^^^^^^^ + | | + | cannot move out of here + | help: consider borrowing here: `&drop_struct.fancy` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0509`. diff --git a/src/test/ui/issues/issue-17718-static-move.nll.stderr b/src/test/ui/issues/issue-17718-static-move.nll.stderr new file mode 100644 index 0000000000000..f8da3c3d5989e --- /dev/null +++ b/src/test/ui/issues/issue-17718-static-move.nll.stderr @@ -0,0 +1,12 @@ +error[E0507]: cannot move out of static item + --> $DIR/issue-17718-static-move.rs:16:14 + | +LL | let _a = FOO; //~ ERROR: cannot move out of static item + | ^^^ + | | + | cannot move out of static item + | help: consider borrowing here: `&FOO` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/std-uncopyable-atomics.nll.stderr b/src/test/ui/std-uncopyable-atomics.nll.stderr new file mode 100644 index 0000000000000..e6b612fed8588 --- /dev/null +++ b/src/test/ui/std-uncopyable-atomics.nll.stderr @@ -0,0 +1,39 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/std-uncopyable-atomics.rs:19:13 + | +LL | let x = *&x; //~ ERROR: cannot move out of borrowed content + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing the `*`: `&x` + +error[E0507]: cannot move out of borrowed content + --> $DIR/std-uncopyable-atomics.rs:21:13 + | +LL | let x = *&x; //~ ERROR: cannot move out of borrowed content + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing the `*`: `&x` + +error[E0507]: cannot move out of borrowed content + --> $DIR/std-uncopyable-atomics.rs:23:13 + | +LL | let x = *&x; //~ ERROR: cannot move out of borrowed content + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing the `*`: `&x` + +error[E0507]: cannot move out of borrowed content + --> $DIR/std-uncopyable-atomics.rs:25:13 + | +LL | let x = *&x; //~ ERROR: cannot move out of borrowed content + | ^^^ + | | + | cannot move out of borrowed content + | help: consider removing the `*`: `&x` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0507`. From f4229b81b5b8f66299615976f0381592d20427af Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Wed, 15 Aug 2018 15:25:53 -0700 Subject: [PATCH 25/27] Re-bless test --- .../dont-suggest-ref-in-closure.stderr | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr b/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr index d90773786e58d..825676b5fdf9a 100644 --- a/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr @@ -1,6 +1,9 @@ error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:40:21 | +LL | let x = X(Y); + | - captured outer variable +... LL | let X(_t) = x; | -- ^ | | | @@ -17,6 +20,9 @@ LL | let X(_t) = x; error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:44:34 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | if let Either::One(_t) = e { } | -- ^ | | | @@ -33,6 +39,9 @@ LL | if let Either::One(_t) = e { } error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:48:37 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | while let Either::One(_t) = e { } | -- ^ | | | @@ -49,6 +58,9 @@ LL | while let Either::One(_t) = e { } error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:52:15 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | match e { | ^ | | @@ -67,6 +79,9 @@ LL | Either::One(_t) error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:59:15 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | match e { | ^ | | @@ -85,6 +100,9 @@ LL | Either::One(_t) => (), error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:68:25 | +LL | let x = X(Y); + | - captured outer variable +... LL | let X(mut _t) = x; | ------ ^ | | | @@ -101,6 +119,9 @@ LL | let X(mut _t) = x; error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:72:38 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | if let Either::One(mut _t) = em { } | ------ ^^ | | | @@ -117,6 +138,9 @@ LL | if let Either::One(mut _t) = em { } error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:76:41 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | while let Either::One(mut _t) = em { } | ------ ^^ | | | @@ -133,6 +157,9 @@ LL | while let Either::One(mut _t) = em { } error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:80:15 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | match em { | ^^ | | @@ -151,6 +178,9 @@ LL | Either::One(mut _t) error[E0507]: cannot move out of captured variable in an `Fn` closure --> $DIR/dont-suggest-ref-in-closure.rs:87:15 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | match em { | ^^ | | @@ -169,6 +199,9 @@ LL | Either::One(mut _t) => (), error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:107:21 | +LL | let x = X(Y); + | - captured outer variable +... LL | let X(_t) = x; | -- ^ | | | @@ -185,6 +218,9 @@ LL | let X(_t) = x; error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:111:34 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | if let Either::One(_t) = e { } | -- ^ | | | @@ -201,6 +237,9 @@ LL | if let Either::One(_t) = e { } error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:115:37 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | while let Either::One(_t) = e { } | -- ^ | | | @@ -217,6 +256,9 @@ LL | while let Either::One(_t) = e { } error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:119:15 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | match e { | ^ | | @@ -235,6 +277,9 @@ LL | Either::One(_t) error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:126:15 | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... LL | match e { | ^ | | @@ -253,6 +298,9 @@ LL | Either::One(_t) => (), error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:135:25 | +LL | let x = X(Y); + | - captured outer variable +... LL | let X(mut _t) = x; | ------ ^ | | | @@ -269,6 +317,9 @@ LL | let X(mut _t) = x; error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:139:38 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | if let Either::One(mut _t) = em { } | ------ ^^ | | | @@ -285,6 +336,9 @@ LL | if let Either::One(mut _t) = em { } error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:143:41 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | while let Either::One(mut _t) = em { } | ------ ^^ | | | @@ -301,6 +355,9 @@ LL | while let Either::One(mut _t) = em { } error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:147:15 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | match em { | ^^ | | @@ -319,6 +376,9 @@ LL | Either::One(mut _t) error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:154:15 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | match em { | ^^ | | @@ -337,6 +397,9 @@ LL | Either::One(mut _t) => (), error[E0507]: cannot move out of captured variable in an `FnMut` closure --> $DIR/dont-suggest-ref-in-closure.rs:162:15 | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... LL | match em { | ^^ | | From f335fb08c2b98df6afd242eb2fc428679a15bbf3 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Wed, 15 Aug 2018 22:35:56 -0700 Subject: [PATCH 26/27] Move tests into their own directory --- .../move-into-closure.rs} | 0 .../move-into-closure.stderr} | 0 .../{dont-suggest-ref.rs => dont-suggest-ref/simple.rs} | 0 .../{dont-suggest-ref.stderr => dont-suggest-ref/simple.stderr} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/suggestions/{dont-suggest-ref-in-closure.rs => dont-suggest-ref/move-into-closure.rs} (100%) rename src/test/ui/suggestions/{dont-suggest-ref-in-closure.stderr => dont-suggest-ref/move-into-closure.stderr} (100%) rename src/test/ui/suggestions/{dont-suggest-ref.rs => dont-suggest-ref/simple.rs} (100%) rename src/test/ui/suggestions/{dont-suggest-ref.stderr => dont-suggest-ref/simple.stderr} (100%) diff --git a/src/test/ui/suggestions/dont-suggest-ref-in-closure.rs b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs similarity index 100% rename from src/test/ui/suggestions/dont-suggest-ref-in-closure.rs rename to src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs diff --git a/src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr similarity index 100% rename from src/test/ui/suggestions/dont-suggest-ref-in-closure.stderr rename to src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr diff --git a/src/test/ui/suggestions/dont-suggest-ref.rs b/src/test/ui/suggestions/dont-suggest-ref/simple.rs similarity index 100% rename from src/test/ui/suggestions/dont-suggest-ref.rs rename to src/test/ui/suggestions/dont-suggest-ref/simple.rs diff --git a/src/test/ui/suggestions/dont-suggest-ref.stderr b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr similarity index 100% rename from src/test/ui/suggestions/dont-suggest-ref.stderr rename to src/test/ui/suggestions/dont-suggest-ref/simple.stderr From 0023dd9ba1f242c81042460e5ec6876bd93afdbf Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Wed, 15 Aug 2018 22:36:19 -0700 Subject: [PATCH 27/27] Split tests more and bless them again --- .../dont-suggest-ref/duplicate-suggestions.rs | 162 +++++ .../duplicate-suggestions.stderr | 328 ++++++++++ .../dont-suggest-ref/move-into-closure.stderr | 84 +-- .../ui/suggestions/dont-suggest-ref/simple.rs | 114 ---- .../dont-suggest-ref/simple.stderr | 567 ++++-------------- 5 files changed, 653 insertions(+), 602 deletions(-) create mode 100644 src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs create mode 100644 src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr diff --git a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs new file mode 100644 index 0000000000000..dc0186e3f26bf --- /dev/null +++ b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs @@ -0,0 +1,162 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(nll)] + +#[derive(Clone)] +enum Either { + One(X), + Two(X), +} + +#[derive(Clone)] +struct X(Y); + +#[derive(Clone)] +struct Y; + + +pub fn main() { + let e = Either::One(X(Y)); + let mut em = Either::One(X(Y)); + + let r = &e; + let rm = &mut Either::One(X(Y)); + + let x = X(Y); + let mut xm = X(Y); + + let s = &x; + let sm = &mut X(Y); + + let ve = vec![Either::One(X(Y))]; + + let vr = &ve; + let vrm = &mut vec![Either::One(X(Y))]; + + let vx = vec![X(Y)]; + + let vs = &vx; + let vsm = &mut vec![X(Y)]; + + // -------- test for duplicate suggestions -------- + + let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (X(_t), X(_u)) + if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &(Either::Two(_t), Either::One(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::Two(_t), Either::One(_u)) + _ => (), + } + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + | &(Either::Two(_t), Either::One(_u)) => (), + // FIXME: would really like a suggestion here too + _ => (), + } + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &(Either::Two(ref _t), Either::One(ref _u)) => (), + _ => (), + } + match &(e.clone(), e.clone()) { + //~^ ERROR cannot move + &(Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + (Either::Two(_t), Either::One(_u)) => (), + _ => (), + } + fn f5(&(X(_t), X(_u)): &(X, X)) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&` + //~| SUGGESTION (X(_t), X(_u)) + + let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (X(_t), X(_u)) + if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &mut (Either::Two(_t), Either::One(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::Two(_t), Either::One(_u)) + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + | &mut (Either::Two(_t), Either::One(_u)) => (), + // FIXME: would really like a suggestion here too + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &mut (Either::Two(ref _t), Either::One(ref _u)) => (), + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + &mut (Either::Two(ref mut _t), Either::One(ref mut _u)) => (), + _ => (), + } + match &mut (em.clone(), em.clone()) { + //~^ ERROR cannot move + &mut (Either::One(_t), Either::Two(_u)) => (), + //~^ HELP consider removing the `&mut` + //~| SUGGESTION (Either::One(_t), Either::Two(_u)) + (Either::Two(_t), Either::One(_u)) => (), + _ => (), + } + fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } + //~^ ERROR cannot move + //~| HELP consider removing the `&mut` + //~| SUGGESTION (X(_t), X(_u)) +} diff --git a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr new file mode 100644 index 0000000000000..bb3688411f718 --- /dev/null +++ b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr @@ -0,0 +1,328 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:51:27 + | +LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&`: `(X(_t), X(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:51:13 + | +LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:55:50 + | +LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:55:26 + | +LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:59:53 + | +LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:59:29 + | +LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:63:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) => (), + | -- -- ...and here + | | + | data moved here +... +LL | &(Either::Two(_t), Either::One(_u)) => (), + | -- ...and here -- ...and here + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:65:23 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ +... +LL | &(Either::Two(_t), Either::One(_u)) => (), + | ^^ ^^ +help: consider removing the `&` + | +LL | (Either::One(_t), Either::Two(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider removing the `&` + | +LL | (Either::Two(_t), Either::One(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:73:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) + | ----------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:75:23 + | +LL | &(Either::One(_t), Either::Two(_u)) + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:82:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ----------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:84:23 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:90:11 + | +LL | match &(e.clone(), e.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ----------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:92:23 + | +LL | &(Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:103:31 + | +LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(X(_t), X(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:103:17 + | +LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:107:54 + | +LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:107:30 + | +LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:111:57 + | +LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:111:33 + | +LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:115:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | -- -- ...and here + | | + | data moved here +... +LL | &mut (Either::Two(_t), Either::One(_u)) => (), + | -- ...and here -- ...and here + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:117:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ +... +LL | &mut (Either::Two(_t), Either::One(_u)) => (), + | ^^ ^^ +help: consider removing the `&mut` + | +LL | (Either::One(_t), Either::Two(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider removing the `&mut` + | +LL | (Either::Two(_t), Either::One(_u)) => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:125:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) + | --------------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:127:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:134:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | --------------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:136:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:142:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | --------------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:144:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:150:11 + | +LL | match &mut (em.clone(), em.clone()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content +LL | //~^ ERROR cannot move +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | --------------------------------------- + | | | | + | | | ...and here + | | data moved here + | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:152:27 + | +LL | &mut (Either::One(_t), Either::Two(_u)) => (), + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:98:11 + | +LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } + | ^^^^--^^^^^--^^ + | | | | + | | | ...and here + | | data moved here + | cannot move out of borrowed content + | help: consider removing the `&`: `(X(_t), X(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:98:15 + | +LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } + | ^^ ^^ + +error[E0507]: cannot move out of borrowed content + --> $DIR/duplicate-suggestions.rs:158:11 + | +LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } + | ^^^^^^^^--^^^^^--^^ + | | | | + | | | ...and here + | | data moved here + | cannot move out of borrowed content + | help: consider removing the `&mut`: `(X(_t), X(_u))` + | +note: move occurs because these variables have types that don't implement the `Copy` trait + --> $DIR/duplicate-suggestions.rs:158:19 + | +LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } + | ^^ ^^ + +error: aborting due to 17 previous errors + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr index 825676b5fdf9a..228ec5afce635 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:40:21 + --> $DIR/move-into-closure.rs:40:21 | LL | let x = X(Y); | - captured outer variable @@ -12,13 +12,13 @@ LL | let X(_t) = x; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:40:15 + --> $DIR/move-into-closure.rs:40:15 | LL | let X(_t) = x; | ^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:44:34 + --> $DIR/move-into-closure.rs:44:34 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -31,13 +31,13 @@ LL | if let Either::One(_t) = e { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:44:28 + --> $DIR/move-into-closure.rs:44:28 | LL | if let Either::One(_t) = e { } | ^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:48:37 + --> $DIR/move-into-closure.rs:48:37 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -50,13 +50,13 @@ LL | while let Either::One(_t) = e { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:48:31 + --> $DIR/move-into-closure.rs:48:31 | LL | while let Either::One(_t) = e { } | ^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:52:15 + --> $DIR/move-into-closure.rs:52:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -71,13 +71,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:56:25 + --> $DIR/move-into-closure.rs:56:25 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:59:15 + --> $DIR/move-into-closure.rs:59:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -92,13 +92,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:63:25 + --> $DIR/move-into-closure.rs:63:25 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:68:25 + --> $DIR/move-into-closure.rs:68:25 | LL | let x = X(Y); | - captured outer variable @@ -111,13 +111,13 @@ LL | let X(mut _t) = x; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:68:15 + --> $DIR/move-into-closure.rs:68:15 | LL | let X(mut _t) = x; | ^^^^^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:72:38 + --> $DIR/move-into-closure.rs:72:38 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -130,13 +130,13 @@ LL | if let Either::One(mut _t) = em { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:72:28 + --> $DIR/move-into-closure.rs:72:28 | LL | if let Either::One(mut _t) = em { } | ^^^^^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:76:41 + --> $DIR/move-into-closure.rs:76:41 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -149,13 +149,13 @@ LL | while let Either::One(mut _t) = em { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:76:31 + --> $DIR/move-into-closure.rs:76:31 | LL | while let Either::One(mut _t) = em { } | ^^^^^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:80:15 + --> $DIR/move-into-closure.rs:80:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -170,13 +170,13 @@ LL | Either::One(mut _t) | ------ data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:84:25 + --> $DIR/move-into-closure.rs:84:25 | LL | Either::One(mut _t) | ^^^^^^ error[E0507]: cannot move out of captured variable in an `Fn` closure - --> $DIR/dont-suggest-ref-in-closure.rs:87:15 + --> $DIR/move-into-closure.rs:87:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -191,13 +191,13 @@ LL | Either::One(mut _t) => (), | ------ data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:91:25 + --> $DIR/move-into-closure.rs:91:25 | LL | Either::One(mut _t) => (), | ^^^^^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:107:21 + --> $DIR/move-into-closure.rs:107:21 | LL | let x = X(Y); | - captured outer variable @@ -210,13 +210,13 @@ LL | let X(_t) = x; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:107:15 + --> $DIR/move-into-closure.rs:107:15 | LL | let X(_t) = x; | ^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:111:34 + --> $DIR/move-into-closure.rs:111:34 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -229,13 +229,13 @@ LL | if let Either::One(_t) = e { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:111:28 + --> $DIR/move-into-closure.rs:111:28 | LL | if let Either::One(_t) = e { } | ^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:115:37 + --> $DIR/move-into-closure.rs:115:37 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -248,13 +248,13 @@ LL | while let Either::One(_t) = e { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:115:31 + --> $DIR/move-into-closure.rs:115:31 | LL | while let Either::One(_t) = e { } | ^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:119:15 + --> $DIR/move-into-closure.rs:119:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -269,13 +269,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:123:25 + --> $DIR/move-into-closure.rs:123:25 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:126:15 + --> $DIR/move-into-closure.rs:126:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -290,13 +290,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:130:25 + --> $DIR/move-into-closure.rs:130:25 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:135:25 + --> $DIR/move-into-closure.rs:135:25 | LL | let x = X(Y); | - captured outer variable @@ -309,13 +309,13 @@ LL | let X(mut _t) = x; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:135:15 + --> $DIR/move-into-closure.rs:135:15 | LL | let X(mut _t) = x; | ^^^^^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:139:38 + --> $DIR/move-into-closure.rs:139:38 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -328,13 +328,13 @@ LL | if let Either::One(mut _t) = em { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:139:28 + --> $DIR/move-into-closure.rs:139:28 | LL | if let Either::One(mut _t) = em { } | ^^^^^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:143:41 + --> $DIR/move-into-closure.rs:143:41 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -347,13 +347,13 @@ LL | while let Either::One(mut _t) = em { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:143:31 + --> $DIR/move-into-closure.rs:143:31 | LL | while let Either::One(mut _t) = em { } | ^^^^^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:147:15 + --> $DIR/move-into-closure.rs:147:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -368,13 +368,13 @@ LL | Either::One(mut _t) | ------ data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:151:25 + --> $DIR/move-into-closure.rs:151:25 | LL | Either::One(mut _t) | ^^^^^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:154:15 + --> $DIR/move-into-closure.rs:154:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -389,13 +389,13 @@ LL | Either::One(mut _t) => (), | ------ data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:158:25 + --> $DIR/move-into-closure.rs:158:25 | LL | Either::One(mut _t) => (), | ^^^^^^ error[E0507]: cannot move out of captured variable in an `FnMut` closure - --> $DIR/dont-suggest-ref-in-closure.rs:162:15 + --> $DIR/move-into-closure.rs:162:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -410,7 +410,7 @@ LL | Either::One(mut _t) => (), | ------ data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref-in-closure.rs:166:25 + --> $DIR/move-into-closure.rs:166:25 | LL | Either::One(mut _t) => (), | ^^^^^^ diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.rs b/src/test/ui/suggestions/dont-suggest-ref/simple.rs index 3bd6102c5d648..474e88c4d5395 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/simple.rs +++ b/src/test/ui/suggestions/dont-suggest-ref/simple.rs @@ -373,118 +373,4 @@ pub fn main() { //~| SUGGESTION Either::One(_t) Either::Two(_t) => (), } - - // -------- test for duplicate suggestions -------- - - let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION (X(_t), X(_u)) - if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - match &(e.clone(), e.clone()) { - //~^ ERROR cannot move - &(Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - &(Either::Two(_t), Either::One(_u)) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION (Either::Two(_t), Either::One(_u)) - _ => (), - } - match &(e.clone(), e.clone()) { - //~^ ERROR cannot move - &(Either::One(_t), Either::Two(_u)) - //~^ HELP consider removing the `&` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - | &(Either::Two(_t), Either::One(_u)) => (), - // FIXME: would really like a suggestion here too - _ => (), - } - match &(e.clone(), e.clone()) { - //~^ ERROR cannot move - &(Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - &(Either::Two(ref _t), Either::One(ref _u)) => (), - _ => (), - } - match &(e.clone(), e.clone()) { - //~^ ERROR cannot move - &(Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - (Either::Two(_t), Either::One(_u)) => (), - _ => (), - } - fn f5(&(X(_t), X(_u)): &(X, X)) { } - //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION (X(_t), X(_u)) - - let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION (X(_t), X(_u)) - if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - match &mut (em.clone(), em.clone()) { - //~^ ERROR cannot move - &mut (Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - &mut (Either::Two(_t), Either::One(_u)) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::Two(_t), Either::One(_u)) - _ => (), - } - match &mut (em.clone(), em.clone()) { - //~^ ERROR cannot move - &mut (Either::One(_t), Either::Two(_u)) - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - | &mut (Either::Two(_t), Either::One(_u)) => (), - // FIXME: would really like a suggestion here too - _ => (), - } - match &mut (em.clone(), em.clone()) { - //~^ ERROR cannot move - &mut (Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - &mut (Either::Two(ref _t), Either::One(ref _u)) => (), - _ => (), - } - match &mut (em.clone(), em.clone()) { - //~^ ERROR cannot move - &mut (Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - &mut (Either::Two(ref mut _t), Either::One(ref mut _u)) => (), - _ => (), - } - match &mut (em.clone(), em.clone()) { - //~^ ERROR cannot move - &mut (Either::One(_t), Either::Two(_u)) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::One(_t), Either::Two(_u)) - (Either::Two(_t), Either::One(_u)) => (), - _ => (), - } - fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } - //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION (X(_t), X(_u)) } diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr index 8994152d1a5ce..d7a32dbfcc643 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:50:17 + --> $DIR/simple.rs:50:17 | LL | let X(_t) = *s; | -- ^^ @@ -9,13 +9,13 @@ LL | let X(_t) = *s; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:50:11 + --> $DIR/simple.rs:50:11 | LL | let X(_t) = *s; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:54:30 + --> $DIR/simple.rs:54:30 | LL | if let Either::One(_t) = *r { } | -- ^^ @@ -25,13 +25,13 @@ LL | if let Either::One(_t) = *r { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:54:24 + --> $DIR/simple.rs:54:24 | LL | if let Either::One(_t) = *r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:58:33 + --> $DIR/simple.rs:58:33 | LL | while let Either::One(_t) = *r { } | -- ^^ @@ -41,13 +41,13 @@ LL | while let Either::One(_t) = *r { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:58:27 + --> $DIR/simple.rs:58:27 | LL | while let Either::One(_t) = *r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:62:11 + --> $DIR/simple.rs:62:11 | LL | match *r { | ^^ @@ -59,13 +59,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:66:21 + --> $DIR/simple.rs:66:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:69:11 + --> $DIR/simple.rs:69:11 | LL | match *r { | ^^ @@ -77,13 +77,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:73:21 + --> $DIR/simple.rs:73:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:78:17 + --> $DIR/simple.rs:78:17 | LL | let X(_t) = *sm; | -- ^^^ @@ -93,13 +93,13 @@ LL | let X(_t) = *sm; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:78:11 + --> $DIR/simple.rs:78:11 | LL | let X(_t) = *sm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:82:30 + --> $DIR/simple.rs:82:30 | LL | if let Either::One(_t) = *rm { } | -- ^^^ @@ -109,13 +109,13 @@ LL | if let Either::One(_t) = *rm { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:82:24 + --> $DIR/simple.rs:82:24 | LL | if let Either::One(_t) = *rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:86:33 + --> $DIR/simple.rs:86:33 | LL | while let Either::One(_t) = *rm { } | -- ^^^ @@ -125,13 +125,13 @@ LL | while let Either::One(_t) = *rm { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:86:27 + --> $DIR/simple.rs:86:27 | LL | while let Either::One(_t) = *rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:90:11 + --> $DIR/simple.rs:90:11 | LL | match *rm { | ^^^ @@ -143,13 +143,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:94:21 + --> $DIR/simple.rs:94:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:97:11 + --> $DIR/simple.rs:97:11 | LL | match *rm { | ^^^ @@ -161,13 +161,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:101:21 + --> $DIR/simple.rs:101:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:105:11 + --> $DIR/simple.rs:105:11 | LL | match *rm { | ^^^ @@ -179,13 +179,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:109:21 + --> $DIR/simple.rs:109:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:114:17 + --> $DIR/simple.rs:114:17 | LL | let X(_t) = vs[0]; | -- ^^^^^ @@ -195,13 +195,13 @@ LL | let X(_t) = vs[0]; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:114:11 + --> $DIR/simple.rs:114:11 | LL | let X(_t) = vs[0]; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:118:30 + --> $DIR/simple.rs:118:30 | LL | if let Either::One(_t) = vr[0] { } | -- ^^^^^ @@ -211,13 +211,13 @@ LL | if let Either::One(_t) = vr[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:118:24 + --> $DIR/simple.rs:118:24 | LL | if let Either::One(_t) = vr[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:122:33 + --> $DIR/simple.rs:122:33 | LL | while let Either::One(_t) = vr[0] { } | -- ^^^^^ @@ -227,13 +227,13 @@ LL | while let Either::One(_t) = vr[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:122:27 + --> $DIR/simple.rs:122:27 | LL | while let Either::One(_t) = vr[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:126:11 + --> $DIR/simple.rs:126:11 | LL | match vr[0] { | ^^^^^ @@ -245,13 +245,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:130:21 + --> $DIR/simple.rs:130:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:133:11 + --> $DIR/simple.rs:133:11 | LL | match vr[0] { | ^^^^^ @@ -263,13 +263,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:137:21 + --> $DIR/simple.rs:137:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:142:17 + --> $DIR/simple.rs:142:17 | LL | let X(_t) = vsm[0]; | -- ^^^^^^ @@ -279,13 +279,13 @@ LL | let X(_t) = vsm[0]; | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:142:11 + --> $DIR/simple.rs:142:11 | LL | let X(_t) = vsm[0]; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:146:30 + --> $DIR/simple.rs:146:30 | LL | if let Either::One(_t) = vrm[0] { } | -- ^^^^^^ @@ -295,13 +295,13 @@ LL | if let Either::One(_t) = vrm[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:146:24 + --> $DIR/simple.rs:146:24 | LL | if let Either::One(_t) = vrm[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:150:33 + --> $DIR/simple.rs:150:33 | LL | while let Either::One(_t) = vrm[0] { } | -- ^^^^^^ @@ -311,13 +311,13 @@ LL | while let Either::One(_t) = vrm[0] { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:150:27 + --> $DIR/simple.rs:150:27 | LL | while let Either::One(_t) = vrm[0] { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:154:11 + --> $DIR/simple.rs:154:11 | LL | match vrm[0] { | ^^^^^^ @@ -329,13 +329,13 @@ LL | Either::One(_t) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:158:21 + --> $DIR/simple.rs:158:21 | LL | Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:161:11 + --> $DIR/simple.rs:161:11 | LL | match vrm[0] { | ^^^^^^ @@ -347,13 +347,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:165:21 + --> $DIR/simple.rs:165:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:169:11 + --> $DIR/simple.rs:169:11 | LL | match vrm[0] { | ^^^^^^ @@ -365,13 +365,13 @@ LL | Either::One(_t) => (), | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:173:21 + --> $DIR/simple.rs:173:21 | LL | Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:180:18 + --> $DIR/simple.rs:180:18 | LL | let &X(_t) = s; | ------ ^ cannot move out of borrowed content @@ -380,13 +380,13 @@ LL | let &X(_t) = s; | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:180:12 + --> $DIR/simple.rs:180:12 | LL | let &X(_t) = s; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:184:31 + --> $DIR/simple.rs:184:31 | LL | if let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content @@ -395,13 +395,13 @@ LL | if let &Either::One(_t) = r { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:184:25 + --> $DIR/simple.rs:184:25 | LL | if let &Either::One(_t) = r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:188:34 + --> $DIR/simple.rs:188:34 | LL | while let &Either::One(_t) = r { } | ---------------- ^ cannot move out of borrowed content @@ -410,13 +410,13 @@ LL | while let &Either::One(_t) = r { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:188:28 + --> $DIR/simple.rs:188:28 | LL | while let &Either::One(_t) = r { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:192:11 + --> $DIR/simple.rs:192:11 | LL | match r { | ^ cannot move out of borrowed content @@ -428,13 +428,13 @@ LL | &Either::One(_t) | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:194:22 + --> $DIR/simple.rs:194:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:200:11 + --> $DIR/simple.rs:200:11 | LL | match r { | ^ cannot move out of borrowed content @@ -446,13 +446,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:202:22 + --> $DIR/simple.rs:202:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:207:11 + --> $DIR/simple.rs:207:11 | LL | match r { | ^ cannot move out of borrowed content @@ -464,13 +464,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:209:22 + --> $DIR/simple.rs:209:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:219:22 + --> $DIR/simple.rs:219:22 | LL | let &mut X(_t) = sm; | ---------- ^^ cannot move out of borrowed content @@ -479,13 +479,13 @@ LL | let &mut X(_t) = sm; | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:219:16 + --> $DIR/simple.rs:219:16 | LL | let &mut X(_t) = sm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:223:35 + --> $DIR/simple.rs:223:35 | LL | if let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content @@ -494,13 +494,13 @@ LL | if let &mut Either::One(_t) = rm { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:223:29 + --> $DIR/simple.rs:223:29 | LL | if let &mut Either::One(_t) = rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:227:38 + --> $DIR/simple.rs:227:38 | LL | while let &mut Either::One(_t) = rm { } | -------------------- ^^ cannot move out of borrowed content @@ -509,13 +509,13 @@ LL | while let &mut Either::One(_t) = rm { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:227:32 + --> $DIR/simple.rs:227:32 | LL | while let &mut Either::One(_t) = rm { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:231:11 + --> $DIR/simple.rs:231:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -527,7 +527,7 @@ LL | &mut Either::Two(_t) => (), | -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:233:26 + --> $DIR/simple.rs:233:26 | LL | &mut Either::One(_t) => (), | ^^ @@ -544,7 +544,7 @@ LL | Either::Two(_t) => (), | ^^^^^^^^^^^^^^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:240:11 + --> $DIR/simple.rs:240:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -556,13 +556,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:242:26 + --> $DIR/simple.rs:242:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:247:11 + --> $DIR/simple.rs:247:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -574,13 +574,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:249:26 + --> $DIR/simple.rs:249:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:254:11 + --> $DIR/simple.rs:254:11 | LL | match rm { | ^^ cannot move out of borrowed content @@ -592,13 +592,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:256:26 + --> $DIR/simple.rs:256:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:270:21 + --> $DIR/simple.rs:270:21 | LL | let (&X(_t),) = (&x.clone(),); | -- ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -606,13 +606,13 @@ LL | let (&X(_t),) = (&x.clone(),); | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:270:13 + --> $DIR/simple.rs:270:13 | LL | let (&X(_t),) = (&x.clone(),); | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:272:34 + --> $DIR/simple.rs:272:34 | LL | if let (&Either::One(_t),) = (&e.clone(),) { } | -- ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -620,13 +620,13 @@ LL | if let (&Either::One(_t),) = (&e.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:272:26 + --> $DIR/simple.rs:272:26 | LL | if let (&Either::One(_t),) = (&e.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:274:37 + --> $DIR/simple.rs:274:37 | LL | while let (&Either::One(_t),) = (&e.clone(),) { } | -- ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -634,13 +634,13 @@ LL | while let (&Either::One(_t),) = (&e.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:274:29 + --> $DIR/simple.rs:274:29 | LL | while let (&Either::One(_t),) = (&e.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:276:11 + --> $DIR/simple.rs:276:11 | LL | match (&e.clone(),) { | ^^^^^^^^^^^^^ cannot move out of borrowed content @@ -649,13 +649,13 @@ LL | (&Either::One(_t),) | -- data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:278:23 + --> $DIR/simple.rs:278:23 | LL | (&Either::One(_t),) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:284:25 + --> $DIR/simple.rs:284:25 | LL | let (&mut X(_t),) = (&mut xm.clone(),); | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -663,13 +663,13 @@ LL | let (&mut X(_t),) = (&mut xm.clone(),); | data moved here | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:284:17 + --> $DIR/simple.rs:284:17 | LL | let (&mut X(_t),) = (&mut xm.clone(),); | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:286:38 + --> $DIR/simple.rs:286:38 | LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -677,13 +677,13 @@ LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:286:30 + --> $DIR/simple.rs:286:30 | LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:288:41 + --> $DIR/simple.rs:288:41 | LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | -- ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -691,13 +691,13 @@ LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | data moved here | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:288:33 + --> $DIR/simple.rs:288:33 | LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:290:11 + --> $DIR/simple.rs:290:11 | LL | match (&mut em.clone(),) { | ^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content @@ -708,7 +708,7 @@ LL | (&mut Either::Two(_t),) => (), | -- ...and here | note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:292:27 + --> $DIR/simple.rs:292:27 | LL | (&mut Either::One(_t),) => (), | ^^ @@ -716,7 +716,7 @@ LL | (&mut Either::Two(_t),) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:300:18 + --> $DIR/simple.rs:300:18 | LL | let &X(_t) = &x; | ------ ^^ cannot move out of borrowed content @@ -725,13 +725,13 @@ LL | let &X(_t) = &x; | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:300:12 + --> $DIR/simple.rs:300:12 | LL | let &X(_t) = &x; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:304:31 + --> $DIR/simple.rs:304:31 | LL | if let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -740,13 +740,13 @@ LL | if let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:304:25 + --> $DIR/simple.rs:304:25 | LL | if let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:308:34 + --> $DIR/simple.rs:308:34 | LL | while let &Either::One(_t) = &e { } | ---------------- ^^ cannot move out of borrowed content @@ -755,13 +755,13 @@ LL | while let &Either::One(_t) = &e { } | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:308:28 + --> $DIR/simple.rs:308:28 | LL | while let &Either::One(_t) = &e { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:312:11 + --> $DIR/simple.rs:312:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -773,13 +773,13 @@ LL | &Either::One(_t) | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:314:22 + --> $DIR/simple.rs:314:22 | LL | &Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:320:11 + --> $DIR/simple.rs:320:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -791,13 +791,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:322:22 + --> $DIR/simple.rs:322:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:327:11 + --> $DIR/simple.rs:327:11 | LL | match &e { | ^^ cannot move out of borrowed content @@ -809,13 +809,13 @@ LL | &Either::One(_t) => (), | help: consider removing the `&`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:329:22 + --> $DIR/simple.rs:329:22 | LL | &Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:335:22 + --> $DIR/simple.rs:335:22 | LL | let &mut X(_t) = &mut xm; | ---------- ^^^^^^^ cannot move out of borrowed content @@ -824,13 +824,13 @@ LL | let &mut X(_t) = &mut xm; | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:335:16 + --> $DIR/simple.rs:335:16 | LL | let &mut X(_t) = &mut xm; | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:339:35 + --> $DIR/simple.rs:339:35 | LL | if let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -839,13 +839,13 @@ LL | if let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:339:29 + --> $DIR/simple.rs:339:29 | LL | if let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:343:38 + --> $DIR/simple.rs:343:38 | LL | while let &mut Either::One(_t) = &mut em { } | -------------------- ^^^^^^^ cannot move out of borrowed content @@ -854,13 +854,13 @@ LL | while let &mut Either::One(_t) = &mut em { } | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:343:32 + --> $DIR/simple.rs:343:32 | LL | while let &mut Either::One(_t) = &mut em { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:347:11 + --> $DIR/simple.rs:347:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -872,13 +872,13 @@ LL | &mut Either::One(_t) | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:349:26 + --> $DIR/simple.rs:349:26 | LL | &mut Either::One(_t) | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:355:11 + --> $DIR/simple.rs:355:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -890,13 +890,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:357:26 + --> $DIR/simple.rs:357:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:362:11 + --> $DIR/simple.rs:362:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -908,13 +908,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:364:26 + --> $DIR/simple.rs:364:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:369:11 + --> $DIR/simple.rs:369:11 | LL | match &mut em { | ^^^^^^^ cannot move out of borrowed content @@ -926,304 +926,13 @@ LL | &mut Either::One(_t) => (), | help: consider removing the `&mut`: `Either::One(_t)` | note: move occurs because `_t` has type `X`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:371:26 + --> $DIR/simple.rs:371:26 | LL | &mut Either::One(_t) => (), | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:379:27 - | -LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(X(_t), X(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:379:13 - | -LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:383:50 - | -LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:383:26 - | -LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:387:53 - | -LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:387:29 - | -LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:391:11 - | -LL | match &(e.clone(), e.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &(Either::One(_t), Either::Two(_u)) => (), - | -- -- ...and here - | | - | data moved here -... -LL | &(Either::Two(_t), Either::One(_u)) => (), - | -- ...and here -- ...and here - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:393:23 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ -... -LL | &(Either::Two(_t), Either::One(_u)) => (), - | ^^ ^^ -help: consider removing the `&` - | -LL | (Either::One(_t), Either::Two(_u)) => (), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: consider removing the `&` - | -LL | (Either::Two(_t), Either::One(_u)) => (), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:401:11 - | -LL | match &(e.clone(), e.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &(Either::One(_t), Either::Two(_u)) - | ----------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:403:23 - | -LL | &(Either::One(_t), Either::Two(_u)) - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:410:11 - | -LL | match &(e.clone(), e.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ----------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:412:23 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:418:11 - | -LL | match &(e.clone(), e.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ----------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:420:23 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:431:31 - | -LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(X(_t), X(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:431:17 - | -LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:435:54 - | -LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:435:30 - | -LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:439:57 - | -LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:439:33 - | -LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:443:11 - | -LL | match &mut (em.clone(), em.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | -- -- ...and here - | | - | data moved here -... -LL | &mut (Either::Two(_t), Either::One(_u)) => (), - | -- ...and here -- ...and here - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:445:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ -... -LL | &mut (Either::Two(_t), Either::One(_u)) => (), - | ^^ ^^ -help: consider removing the `&mut` - | -LL | (Either::One(_t), Either::Two(_u)) => (), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: consider removing the `&mut` - | -LL | (Either::Two(_t), Either::One(_u)) => (), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:453:11 - | -LL | match &mut (em.clone(), em.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &mut (Either::One(_t), Either::Two(_u)) - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:455:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:462:11 - | -LL | match &mut (em.clone(), em.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:464:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:470:11 - | -LL | match &mut (em.clone(), em.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:472:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:478:11 - | -LL | match &mut (em.clone(), em.clone()) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content -LL | //~^ ERROR cannot move -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:480:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:214:11 + --> $DIR/simple.rs:214:11 | LL | fn f1(&X(_t): &X) { } | ^^^--^ @@ -1233,13 +942,13 @@ LL | fn f1(&X(_t): &X) { } | help: consider removing the `&`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:214:14 + --> $DIR/simple.rs:214:14 | LL | fn f1(&X(_t): &X) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:261:11 + --> $DIR/simple.rs:261:11 | LL | fn f2(&mut X(_t): &mut X) { } | ^^^^^^^--^ @@ -1249,13 +958,13 @@ LL | fn f2(&mut X(_t): &mut X) { } | help: consider removing the `&mut`: `X(_t)` | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:261:18 + --> $DIR/simple.rs:261:18 | LL | fn f2(&mut X(_t): &mut X) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:281:11 + --> $DIR/simple.rs:281:11 | LL | fn f3((&X(_t),): (&X,)) { } | ^^^^--^^^ @@ -1264,13 +973,13 @@ LL | fn f3((&X(_t),): (&X,)) { } | cannot move out of borrowed content | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:281:15 + --> $DIR/simple.rs:281:15 | LL | fn f3((&X(_t),): (&X,)) { } | ^^ error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:295:11 + --> $DIR/simple.rs:295:11 | LL | fn f4((&mut X(_t),): (&mut X,)) { } | ^^^^^^^^--^^^ @@ -1279,45 +988,11 @@ LL | fn f4((&mut X(_t),): (&mut X,)) { } | cannot move out of borrowed content | note: move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:295:19 + --> $DIR/simple.rs:295:19 | LL | fn f4((&mut X(_t),): (&mut X,)) { } | ^^ -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:426:11 - | -LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } - | ^^^^--^^^^^--^^ - | | | | - | | | ...and here - | | data moved here - | cannot move out of borrowed content - | help: consider removing the `&`: `(X(_t), X(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:426:15 - | -LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } - | ^^ ^^ - -error[E0507]: cannot move out of borrowed content - --> $DIR/dont-suggest-ref.rs:486:11 - | -LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } - | ^^^^^^^^--^^^^^--^^ - | | | | - | | | ...and here - | | data moved here - | cannot move out of borrowed content - | help: consider removing the `&mut`: `(X(_t), X(_u))` - | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/dont-suggest-ref.rs:486:19 - | -LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } - | ^^ ^^ - -error: aborting due to 77 previous errors +error: aborting due to 60 previous errors For more information about this error, try `rustc --explain E0507`.