diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 5a47f45677ecb..6db3c858ae714 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -4,7 +4,7 @@ use rustc_middle::ty; use rustc_mir_dataflow::move_paths::{ IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex, }; -use rustc_span::Span; +use rustc_span::{BytePos, Span}; use crate::diagnostics::{DescribePlaceOpt, UseSpans}; use crate::prefixes::PrefixSet; @@ -148,7 +148,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { match_span: Span, statement_span: Span, ) { - debug!("append_binding_error(match_place={:?}, match_span={:?})", match_place, match_span); + debug!(?match_place, ?match_span, "append_binding_error"); let from_simple_let = match_place.is_none(); let match_place = match_place.unwrap_or(move_from); @@ -160,7 +160,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if let GroupedMoveError::MovesFromPlace { span, binds_to, .. } = ge && match_span == *span { - debug!("appending local({:?}) to list", bind_to); + debug!("appending local({bind_to:?}) to list"); if !binds_to.is_empty() { binds_to.push(bind_to); } @@ -198,7 +198,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } = ge { if match_span == *span && mpi == *other_mpi { - debug!("appending local({:?}) to list", bind_to); + debug!("appending local({bind_to:?}) to list"); binds_to.push(bind_to); return; } @@ -410,15 +410,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diagnostic, span: Span) { match error { GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { - if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) { - err.span_suggestion( - span, - "consider borrowing here", - format!("&{snippet}"), - Applicability::Unspecified, - ); - } - + self.add_borrow_suggestions(err, span); if binds_to.is_empty() { let place_ty = move_from.ty(self.body, self.infcx.tcx).ty; let place_desc = match self.describe_place(move_from.as_ref()) { @@ -461,39 +453,75 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } + fn add_borrow_suggestions(&self, err: &mut Diagnostic, span: Span) { + match self.infcx.tcx.sess.source_map().span_to_snippet(span) { + Ok(snippet) if snippet.starts_with('*') => { + err.span_suggestion_verbose( + span.with_hi(span.lo() + BytePos(1)), + "consider removing the dereference here", + String::new(), + Applicability::MaybeIncorrect, + ); + } + _ => { + err.span_suggestion_verbose( + span.shrink_to_lo(), + "consider borrowing here", + "&".to_string(), + Applicability::MaybeIncorrect, + ); + } + } + } + fn add_move_error_suggestions(&self, err: &mut Diagnostic, binds_to: &[Local]) { - let mut suggestions: Vec<(Span, &str, String)> = Vec::new(); + let mut suggestions: Vec<(Span, String, String)> = Vec::new(); for local in binds_to { let bind_to = &self.body.local_decls[*local]; if let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var( VarBindingForm { pat_span, .. }, )))) = bind_to.local_info { - if let Ok(pat_snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(pat_span) + let Ok(pat_snippet) = + self.infcx.tcx.sess.source_map().span_to_snippet(pat_span) else { continue; }; + let Some(stripped) = pat_snippet.strip_prefix('&') else { + suggestions.push(( + bind_to.source_info.span.shrink_to_lo(), + "consider borrowing the pattern binding".to_string(), + "ref ".to_string(), + )); + continue; + }; + let inner_pat_snippet = stripped.trim_start(); + let (pat_span, suggestion, to_remove) = if inner_pat_snippet.starts_with("mut") + && inner_pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace) { - if let Some(stripped) = pat_snippet.strip_prefix('&') { - let pat_snippet = stripped.trim_start(); - let (suggestion, to_remove) = if pat_snippet.starts_with("mut") - && pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace) - { - (pat_snippet["mut".len()..].trim_start(), "&mut") - } else { - (pat_snippet, "&") - }; - suggestions.push((pat_span, to_remove, suggestion.to_owned())); - } - } + let inner_pat_snippet = inner_pat_snippet["mut".len()..].trim_start(); + let pat_span = pat_span.with_hi( + pat_span.lo() + + BytePos((pat_snippet.len() - inner_pat_snippet.len()) as u32), + ); + (pat_span, String::new(), "mutable borrow") + } else { + let pat_span = pat_span.with_hi( + pat_span.lo() + + BytePos( + (pat_snippet.len() - inner_pat_snippet.trim_start().len()) as u32, + ), + ); + (pat_span, String::new(), "borrow") + }; + suggestions.push(( + pat_span, + format!("consider removing the {to_remove}"), + suggestion.to_string(), + )); } } suggestions.sort_unstable_by_key(|&(span, _, _)| span); suggestions.dedup_by_key(|&mut (span, _, _)| span); - for (span, to_remove, suggestion) in suggestions { - err.span_suggestion( - span, - &format!("consider removing the `{to_remove}`"), - suggestion, - Applicability::MachineApplicable, - ); + for (span, msg, suggestion) in suggestions { + err.span_suggestion_verbose(span, &msg, suggestion, Applicability::MachineApplicable); } } @@ -521,8 +549,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if binds_to.len() > 1 { err.note( - "move occurs because these variables have types that \ - don't implement the `Copy` trait", + "move occurs because these variables have types that don't implement the `Copy` \ + trait", ); } } diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs index 49d7136a2f1ff..7b19acf70737f 100644 --- a/compiler/rustc_mir_build/src/build/block.rs +++ b/compiler/rustc_mir_build/src/build/block.rs @@ -231,7 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { remainder_span, pattern, None, - Some((None, initializer_span)), + Some((Some(&destination), initializer_span)), ); this.visit_primary_bindings( pattern, diff --git a/src/test/ui/borrowck/access-mode-in-closures.stderr b/src/test/ui/borrowck/access-mode-in-closures.stderr index 13a6277da14c0..abee72ba8cf97 100644 --- a/src/test/ui/borrowck/access-mode-in-closures.stderr +++ b/src/test/ui/borrowck/access-mode-in-closures.stderr @@ -3,10 +3,15 @@ error[E0507]: cannot move out of `s` which is behind a shared reference | LL | match *s { S(v) => v } | ^^ - - | | | - | | data moved here - | | move occurs because `v` has type `Vec`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*s` + | | + | data moved here + | move occurs because `v` has type `Vec`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *s { S(v) => v } +LL + match s { S(v) => v } + | error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.stderr b/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.stderr index 2eabc1f1d9df5..f9ced03e0f038 100644 --- a/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.stderr +++ b/src/test/ui/borrowck/borrowck-for-loop-correct-cmt-for-pattern.stderr @@ -2,31 +2,46 @@ error[E0507]: cannot move out of a shared reference --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:12:15 | LL | for &a in x.iter() { - | -- ^^^^^^^^ - | || - | |data moved here - | |move occurs because `a` has type `&mut i32`, which does not implement the `Copy` trait - | help: consider removing the `&`: `a` + | - ^^^^^^^^ + | | + | data moved here + | move occurs because `a` has type `&mut i32`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - for &a in x.iter() { +LL + for a in x.iter() { + | error[E0507]: cannot move out of a shared reference --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:18:15 | LL | for &a in &f.a { - | -- ^^^^ - | || - | |data moved here - | |move occurs because `a` has type `Box`, which does not implement the `Copy` trait - | help: consider removing the `&`: `a` + | - ^^^^ + | | + | data moved here + | move occurs because `a` has type `Box`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - for &a in &f.a { +LL + for a in &f.a { + | error[E0507]: cannot move out of a shared reference --> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:15 | LL | for &a in x.iter() { - | -- ^^^^^^^^ - | || - | |data moved here - | |move occurs because `a` has type `Box`, which does not implement the `Copy` trait - | help: consider removing the `&`: `a` + | - ^^^^^^^^ + | | + | data moved here + | move occurs because `a` has type `Box`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - for &a in x.iter() { +LL + for a in x.iter() { + | error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-issue-2657-2.fixed b/src/test/ui/borrowck/borrowck-issue-2657-2.fixed new file mode 100644 index 0000000000000..625e7c3cad590 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-issue-2657-2.fixed @@ -0,0 +1,12 @@ +// run-rustfix +fn main() { + + let x: Option> = Some(Box::new(1)); + + match x { + Some(ref y) => { + let _b = y; //~ ERROR cannot move out + } + _ => {} + } +} diff --git a/src/test/ui/borrowck/borrowck-issue-2657-2.rs b/src/test/ui/borrowck/borrowck-issue-2657-2.rs index 7dbac02154a6e..f79a846e70e7b 100644 --- a/src/test/ui/borrowck/borrowck-issue-2657-2.rs +++ b/src/test/ui/borrowck/borrowck-issue-2657-2.rs @@ -1,3 +1,4 @@ +// run-rustfix fn main() { let x: Option> = Some(Box::new(1)); diff --git a/src/test/ui/borrowck/borrowck-issue-2657-2.stderr b/src/test/ui/borrowck/borrowck-issue-2657-2.stderr index f9ba2ca416bdd..850bb9ae3930c 100644 --- a/src/test/ui/borrowck/borrowck-issue-2657-2.stderr +++ b/src/test/ui/borrowck/borrowck-issue-2657-2.stderr @@ -1,11 +1,14 @@ error[E0507]: cannot move out of `*y` which is behind a shared reference - --> $DIR/borrowck-issue-2657-2.rs:7:18 + --> $DIR/borrowck-issue-2657-2.rs:8:18 | LL | let _b = *y; - | ^^ - | | - | move occurs because `*y` has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*y` + | ^^ move occurs because `*y` has type `Box`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let _b = *y; +LL + let _b = y; + | error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-move-error-with-note.fixed b/src/test/ui/borrowck/borrowck-move-error-with-note.fixed new file mode 100644 index 0000000000000..cf6c382a692b2 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-move-error-with-note.fixed @@ -0,0 +1,56 @@ +// run-rustfix +#![allow(unused)] +enum Foo { + Foo1(Box, Box), + Foo2(Box), + Foo3, +} + + + +fn blah() { + let f = &Foo::Foo1(Box::new(1), Box::new(2)); + match f { //~ ERROR cannot move out of + Foo::Foo1(num1, + num2) => (), + Foo::Foo2(num) => (), + Foo::Foo3 => () + } +} + +struct S { + f: String, + g: String +} +impl Drop for S { + fn drop(&mut self) { println!("{}", self.f); } +} + +fn move_in_match() { + match (S {f: "foo".to_string(), g: "bar".to_string()}) { + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait + S { + f: ref _s, + g: ref _t + } => {} + } +} + +// from issue-8064 +struct A { + a: Box, +} + +fn free(_: T) {} + +fn blah2() { + let a = &A { a: Box::new(1) }; + match &a.a { //~ ERROR cannot move out of + n => { + free(n) + } + } + free(a) +} + +fn main() {} diff --git a/src/test/ui/borrowck/borrowck-move-error-with-note.rs b/src/test/ui/borrowck/borrowck-move-error-with-note.rs index ef38cbb63a5e3..f336ac4f994fa 100644 --- a/src/test/ui/borrowck/borrowck-move-error-with-note.rs +++ b/src/test/ui/borrowck/borrowck-move-error-with-note.rs @@ -1,3 +1,5 @@ +// run-rustfix +#![allow(unused)] enum Foo { Foo1(Box, Box), Foo2(Box), diff --git a/src/test/ui/borrowck/borrowck-move-error-with-note.stderr b/src/test/ui/borrowck/borrowck-move-error-with-note.stderr index 96246d9ae1a89..722c2c1443a7f 100644 --- a/src/test/ui/borrowck/borrowck-move-error-with-note.stderr +++ b/src/test/ui/borrowck/borrowck-move-error-with-note.stderr @@ -1,8 +1,8 @@ error[E0507]: cannot move out of `f` as enum variant `Foo1` which is behind a shared reference - --> $DIR/borrowck-move-error-with-note.rs:11:11 + --> $DIR/borrowck-move-error-with-note.rs:13:11 | LL | match *f { - | ^^ help: consider borrowing here: `&*f` + | ^^ LL | Foo::Foo1(num1, | ---- data moved here LL | num2) => (), @@ -11,9 +11,14 @@ LL | Foo::Foo2(num) => (), | --- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the dereference here + | +LL - match *f { +LL + match f { + | error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/borrowck-move-error-with-note.rs:28:11 + --> $DIR/borrowck-move-error-with-note.rs:30:11 | LL | match (S {f: "foo".to_string(), g: "bar".to_string()}) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here @@ -24,17 +29,30 @@ LL | g: _t | -- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider borrowing the pattern binding + | +LL | f: ref _s, + | +++ +help: consider borrowing the pattern binding + | +LL | g: ref _t + | +++ error[E0507]: cannot move out of `a.a` which is behind a shared reference - --> $DIR/borrowck-move-error-with-note.rs:46:11 + --> $DIR/borrowck-move-error-with-note.rs:48:11 | LL | match a.a { - | ^^^ help: consider borrowing here: `&a.a` + | ^^^ LL | n => { | - | | | data moved here | move occurs because `n` has type `Box`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &a.a { + | + error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.stderr b/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.stderr index 7ac095e808a85..43fc102bd6256 100644 --- a/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.stderr +++ b/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.stderr @@ -2,10 +2,13 @@ error[E0507]: cannot move out of `*x` which is behind a raw pointer --> $DIR/borrowck-move-from-unsafe-ptr.rs:2:13 | LL | let y = *x; - | ^^ - | | - | move occurs because `*x` has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*x` + | ^^ move occurs because `*x` has type `Box`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let y = *x; +LL + let y = x; + | error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.stderr b/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.stderr index 6b19f9d977efa..21bd073321b83 100644 --- a/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.stderr +++ b/src/test/ui/borrowck/borrowck-move-in-irrefut-pat.stderr @@ -3,30 +3,45 @@ error[E0507]: cannot move out of a shared reference | LL | fn arg_item(&_x: &String) {} | ^-- - | || - | |data moved here - | |move occurs because `_x` has type `String`, which does not implement the `Copy` trait - | help: consider removing the `&`: `_x` + | | + | data moved here + | move occurs because `_x` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - fn arg_item(&_x: &String) {} +LL + fn arg_item(_x: &String) {} + | error[E0507]: cannot move out of a shared reference --> $DIR/borrowck-move-in-irrefut-pat.rs:7:11 | LL | with(|&_x| ()) | ^-- - | || - | |data moved here - | |move occurs because `_x` has type `String`, which does not implement the `Copy` trait - | help: consider removing the `&`: `_x` + | | + | data moved here + | move occurs because `_x` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - with(|&_x| ()) +LL + with(|_x| ()) + | error[E0507]: cannot move out of a shared reference --> $DIR/borrowck-move-in-irrefut-pat.rs:12:15 | LL | let &_x = &"hi".to_string(); - | --- ^^^^^^^^^^^^^^^^^ - | || - | |data moved here - | |move occurs because `_x` has type `String`, which does not implement the `Copy` trait - | help: consider removing the `&`: `_x` + | -- ^^^^^^^^^^^^^^^^^ + | | + | data moved here + | move occurs because `_x` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let &_x = &"hi".to_string(); +LL + let _x = &"hi".to_string(); + | error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.stderr b/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.stderr index 68994c2071bef..599fa1e88dfec 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.stderr @@ -2,10 +2,13 @@ error[E0507]: cannot move out of an `Rc` --> $DIR/borrowck-move-out-of-overloaded-deref.rs:4:14 | LL | let _x = *Rc::new("hi".to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | move occurs because value has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*Rc::new("hi".to_string())` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let _x = *Rc::new("hi".to_string()); +LL + let _x = Rc::new("hi".to_string()); + | error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.fixed b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.fixed new file mode 100644 index 0000000000000..c463c6559386c --- /dev/null +++ b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.fixed @@ -0,0 +1,24 @@ +// run-rustfix +#![allow(unused)] +struct S {f:String} +impl Drop for S { + fn drop(&mut self) { println!("{}", self.f); } +} + +fn move_in_match() { + match (S {f:"foo".to_string()}) { + //~^ ERROR [E0509] + S {f:ref _s} => {} + } +} + +fn move_in_let() { + let S {f:ref _s} = S {f:"foo".to_string()}; + //~^ ERROR [E0509] +} + +fn move_in_fn_arg(S {f:ref _s}: S) { + //~^ ERROR [E0509] +} + +fn main() {} diff --git a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.rs b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.rs index a429f4bc33b06..93183062d61b3 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.rs +++ b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.rs @@ -1,3 +1,5 @@ +// run-rustfix +#![allow(unused)] struct S {f:String} impl Drop for S { fn drop(&mut self) { println!("{}", self.f); } diff --git a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.stderr b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.stderr index 7b00ac9f1c3a6..58f706c65ff28 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-struct-with-dtor.stderr @@ -1,5 +1,5 @@ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:7:11 + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:9:11 | LL | match (S {f:"foo".to_string()}) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here @@ -9,18 +9,28 @@ LL | S {f:_s} => {} | | | data moved here | move occurs because `_s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | S {f:ref _s} => {} + | +++ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:14:20 + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:16:20 | LL | let S {f:_s} = S {f:"foo".to_string()}; | -- ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here | | | data moved here | move occurs because `_s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let S {f:ref _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:18:19 + --> $DIR/borrowck-move-out-of-struct-with-dtor.rs:20:19 | LL | fn move_in_fn_arg(S {f:_s}: S) { | ^^^^^--^ @@ -28,6 +38,11 @@ LL | fn move_in_fn_arg(S {f:_s}: S) { | | data moved here | | move occurs because `_s` has type `String`, which does not implement the `Copy` trait | cannot move out of here + | +help: consider borrowing the pattern binding + | +LL | fn move_in_fn_arg(S {f:ref _s}: S) { + | +++ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.fixed b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.fixed new file mode 100644 index 0000000000000..bc2ddf85fb4a8 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.fixed @@ -0,0 +1,24 @@ +// run-rustfix +#![allow(unused)] +struct S(String); +impl Drop for S { + fn drop(&mut self) { } +} + +fn move_in_match() { + match S("foo".to_string()) { + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait + S(ref _s) => {} + } +} + +fn move_in_let() { + let S(ref _s) = S("foo".to_string()); + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait +} + +fn move_in_fn_arg(S(ref _s): S) { + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait +} + +fn main() {} diff --git a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs index 5bd32f82ebc44..f050bce874067 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs +++ b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs @@ -1,3 +1,5 @@ +// run-rustfix +#![allow(unused)] struct S(String); impl Drop for S { fn drop(&mut self) { } diff --git a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.stderr b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.stderr index f00181b74689b..160a1f99f63f6 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.stderr @@ -1,5 +1,5 @@ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:7:11 + --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:9:11 | LL | match S("foo".to_string()) { | ^^^^^^^^^^^^^^^^^^^^ cannot move out of here @@ -9,18 +9,28 @@ LL | S(_s) => {} | | | data moved here | move occurs because `_s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | S(ref _s) => {} + | +++ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:14:17 + --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:16:17 | LL | let S(_s) = S("foo".to_string()); | -- ^^^^^^^^^^^^^^^^^^^^ cannot move out of here | | | data moved here | move occurs because `_s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let S(ref _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:18:19 + --> $DIR/borrowck-move-out-of-tuple-struct-with-dtor.rs:20:19 | LL | fn move_in_fn_arg(S(_s): S) { | ^^--^ @@ -28,6 +38,11 @@ LL | fn move_in_fn_arg(S(_s): S) { | | data moved here | | move occurs because `_s` has type `String`, which does not implement the `Copy` trait | cannot move out of here + | +help: consider borrowing the pattern binding + | +LL | fn move_in_fn_arg(S(ref _s): S) { + | +++ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr b/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr index a865812cb4a7c..9ff20a1f46a12 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr @@ -10,10 +10,10 @@ LL | Foo { string: b }] => { | - ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider removing the `&` +help: consider removing the borrow | -LL ~ [Foo { string: a }, -LL ~ Foo { string: b }] => { +LL - &[Foo { string: a }, +LL + [Foo { string: a }, | error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.stderr b/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.stderr index 2b4293b433e01..f5f4817e9bf32 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.stderr @@ -2,10 +2,12 @@ error[E0507]: cannot move out of index of `MyVec>` --> $DIR/borrowck-overloaded-index-move-from-vec.rs:20:15 | LL | let bad = v[0]; - | ^^^^ - | | - | move occurs because value has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&v[0]` + | ^^^^ move occurs because value has type `Box`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let bad = &v[0]; + | + error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs index 8a9296c597828..0e9284a2cadd2 100644 --- a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs @@ -37,7 +37,7 @@ fn c() { &mut [_a, //~^ NOTE data moved here //~| NOTE move occurs because `_a` has type - //~| HELP consider removing the `&mut` + //~| HELP consider removing the mutable borrow .. ] => { } @@ -56,7 +56,7 @@ fn d() { //~^ ERROR cannot move out //~| NOTE cannot move out &mut [ - //~^ HELP consider removing the `&mut` + //~^ HELP consider removing the mutable borrow _b] => {} //~^ NOTE data moved here //~| NOTE move occurs because `_b` has type @@ -79,7 +79,7 @@ fn e() { //~^ NOTE data moved here //~| NOTE and here //~| NOTE and here - //~| HELP consider removing the `&mut` + //~| HELP consider removing the mutable borrow _ => {} } let a = vec[0]; //~ ERROR cannot move out diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr index c3bcb7de65daa..0dc5e64e4ff30 100644 --- a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr @@ -34,14 +34,10 @@ LL | &mut [_a, | data moved here | move occurs because `_a` has type `Box`, which does not implement the `Copy` trait | -help: consider removing the `&mut` +help: consider removing the mutable borrow | -LL ~ [_a, -LL + -LL + -LL + -LL + .. -LL ~ ] => { +LL - &mut [_a, +LL + [_a, | error[E0508]: cannot move out of type `[Box]`, a non-copy slice @@ -52,7 +48,11 @@ LL | let a = vec[0]; | | | cannot move out of here | move occurs because `vec[_]` has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&vec[0]` + | +help: consider borrowing here + | +LL | let a = &vec[0]; + | + error[E0508]: cannot move out of type `[Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:55:11 @@ -66,11 +66,10 @@ LL | _b] => {} | data moved here | move occurs because `_b` has type `Box`, which does not implement the `Copy` trait | -help: consider removing the `&mut` +help: consider removing the mutable borrow | -LL ~ [ -LL + -LL ~ _b] => {} +LL - &mut [ +LL + [ | error[E0508]: cannot move out of type `[Box]`, a non-copy slice @@ -81,7 +80,11 @@ LL | let a = vec[0]; | | | cannot move out of here | move occurs because `vec[_]` has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&vec[0]` + | +help: consider borrowing here + | +LL | let a = &vec[0]; + | + error[E0508]: cannot move out of type `[Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:74:11 @@ -90,14 +93,17 @@ LL | match vec { | ^^^ cannot move out of here ... LL | &mut [_a, _b, _c] => {} - | ----------------- - | | | | | - | | | | ...and here - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `[_a, _b, _c]` + | -- -- -- ...and here + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - &mut [_a, _b, _c] => {} +LL + [_a, _b, _c] => {} + | error[E0508]: cannot move out of type `[Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:85:13 @@ -107,7 +113,11 @@ LL | let a = vec[0]; | | | cannot move out of here | move occurs because `vec[_]` has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&vec[0]` + | +help: consider borrowing here + | +LL | let a = &vec[0]; + | + error: aborting due to 8 previous errors diff --git a/src/test/ui/borrowck/issue-17718-static-move.stderr b/src/test/ui/borrowck/issue-17718-static-move.stderr index 984534bfb8b86..65aea5b1834b0 100644 --- a/src/test/ui/borrowck/issue-17718-static-move.stderr +++ b/src/test/ui/borrowck/issue-17718-static-move.stderr @@ -2,10 +2,12 @@ error[E0507]: cannot move out of static item `FOO` --> $DIR/issue-17718-static-move.rs:6:14 | LL | let _a = FOO; - | ^^^ - | | - | move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait - | help: consider borrowing here: `&FOO` + | ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let _a = &FOO; + | + error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-20801.stderr b/src/test/ui/borrowck/issue-20801.stderr index d276231dc0c96..215bf01006369 100644 --- a/src/test/ui/borrowck/issue-20801.stderr +++ b/src/test/ui/borrowck/issue-20801.stderr @@ -2,37 +2,49 @@ error[E0507]: cannot move out of a mutable reference --> $DIR/issue-20801.rs:26:22 | LL | let a = unsafe { *mut_ref() }; - | ^^^^^^^^^^ - | | - | move occurs because value has type `T`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*mut_ref()` + | ^^^^^^^^^^ move occurs because value has type `T`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let a = unsafe { *mut_ref() }; +LL + let a = unsafe { mut_ref() }; + | error[E0507]: cannot move out of a shared reference --> $DIR/issue-20801.rs:29:22 | LL | let b = unsafe { *imm_ref() }; - | ^^^^^^^^^^ - | | - | move occurs because value has type `T`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*imm_ref()` + | ^^^^^^^^^^ move occurs because value has type `T`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let b = unsafe { *imm_ref() }; +LL + let b = unsafe { imm_ref() }; + | error[E0507]: cannot move out of a raw pointer --> $DIR/issue-20801.rs:32:22 | LL | let c = unsafe { *mut_ptr() }; - | ^^^^^^^^^^ - | | - | move occurs because value has type `T`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*mut_ptr()` + | ^^^^^^^^^^ move occurs because value has type `T`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let c = unsafe { *mut_ptr() }; +LL + let c = unsafe { mut_ptr() }; + | error[E0507]: cannot move out of a raw pointer --> $DIR/issue-20801.rs:35:22 | LL | let d = unsafe { *const_ptr() }; - | ^^^^^^^^^^^^ - | | - | move occurs because value has type `T`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*const_ptr()` + | ^^^^^^^^^^^^ move occurs because value has type `T`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let d = unsafe { *const_ptr() }; +LL + let d = unsafe { const_ptr() }; + | error: aborting due to 4 previous errors diff --git a/src/test/ui/borrowck/issue-47215-ice-from-drop-elab.stderr b/src/test/ui/borrowck/issue-47215-ice-from-drop-elab.stderr index eb41af1cea80d..8d4918867f75e 100644 --- a/src/test/ui/borrowck/issue-47215-ice-from-drop-elab.stderr +++ b/src/test/ui/borrowck/issue-47215-ice-from-drop-elab.stderr @@ -2,10 +2,12 @@ error[E0507]: cannot move out of static item `X` --> $DIR/issue-47215-ice-from-drop-elab.rs:17:21 | LL | let mut x = X; - | ^ - | | - | move occurs because `X` has type `AtomicUsize`, which does not implement the `Copy` trait - | help: consider borrowing here: `&X` + | ^ move occurs because `X` has type `AtomicUsize`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let mut x = &X; + | + error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-51301.stderr b/src/test/ui/borrowck/issue-51301.stderr index f3decf7a9913c..6ec920cb81f39 100644 --- a/src/test/ui/borrowck/issue-51301.stderr +++ b/src/test/ui/borrowck/issue-51301.stderr @@ -6,6 +6,11 @@ LL | .find(|(&event_type, _)| event == event_type) | | | data moved here | move occurs because `event_type` has type `EventType`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | .find(|(&ref event_type, _)| event == event_type) + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-51415.fixed b/src/test/ui/borrowck/issue-51415.fixed new file mode 100644 index 0000000000000..92943f6c9ecb2 --- /dev/null +++ b/src/test/ui/borrowck/issue-51415.fixed @@ -0,0 +1,12 @@ +// run-rustfix +// Regression test for #51415: match default bindings were failing to +// see the "move out" implied by `&s` below. + +fn main() { + let a = vec![String::from("a")]; + let opt = a.iter().enumerate().find(|(_, &ref s)| { + //~^ ERROR cannot move out + *s == String::from("d") + }).map(|(i, _)| i); + println!("{:?}", opt); +} diff --git a/src/test/ui/borrowck/issue-51415.rs b/src/test/ui/borrowck/issue-51415.rs index f031308fb7871..56ed57a61a0fe 100644 --- a/src/test/ui/borrowck/issue-51415.rs +++ b/src/test/ui/borrowck/issue-51415.rs @@ -1,3 +1,4 @@ +// run-rustfix // Regression test for #51415: match default bindings were failing to // see the "move out" implied by `&s` below. diff --git a/src/test/ui/borrowck/issue-51415.stderr b/src/test/ui/borrowck/issue-51415.stderr index a88819efcf798..0d486b45592b5 100644 --- a/src/test/ui/borrowck/issue-51415.stderr +++ b/src/test/ui/borrowck/issue-51415.stderr @@ -1,11 +1,16 @@ error[E0507]: cannot move out of a shared reference - --> $DIR/issue-51415.rs:6:42 + --> $DIR/issue-51415.rs:7:42 | LL | let opt = a.iter().enumerate().find(|(_, &s)| { | ^^^^^-^ | | | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let opt = a.iter().enumerate().find(|(_, &ref s)| { + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-54597-reject-move-out-of-borrow-via-pat.stderr b/src/test/ui/borrowck/issue-54597-reject-move-out-of-borrow-via-pat.stderr index 1f9cbdb73425d..99c63e4db50d3 100644 --- a/src/test/ui/borrowck/issue-54597-reject-move-out-of-borrow-via-pat.stderr +++ b/src/test/ui/borrowck/issue-54597-reject-move-out-of-borrow-via-pat.stderr @@ -2,10 +2,13 @@ error[E0507]: cannot move out of `*array` which is behind a shared reference --> $DIR/issue-54597-reject-move-out-of-borrow-via-pat.rs:14:13 | LL | *array - | ^^^^^^ - | | - | move occurs because `*array` has type `Vec`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*array` + | ^^^^^^ move occurs because `*array` has type `Vec`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - *array +LL + array + | error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-87456-point-to-closure.stderr b/src/test/ui/borrowck/issue-87456-point-to-closure.stderr index 039575a8d79a5..afd141125ac7c 100644 --- a/src/test/ui/borrowck/issue-87456-point-to-closure.stderr +++ b/src/test/ui/borrowck/issue-87456-point-to-closure.stderr @@ -8,10 +8,12 @@ LL | take_mut(|| { | -- captured by this `FnMut` closure LL | LL | let _foo: String = val; - | ^^^ - | | - | move occurs because `val` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&val` + | ^^^ move occurs because `val` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let _foo: String = &val; + | + error: aborting due to previous error diff --git a/src/test/ui/borrowck/move-error-snippets.stderr b/src/test/ui/borrowck/move-error-snippets.stderr index 984981ce2ea14..8ac711e9e59db 100644 --- a/src/test/ui/borrowck/move-error-snippets.stderr +++ b/src/test/ui/borrowck/move-error-snippets.stderr @@ -2,10 +2,7 @@ error[E0507]: cannot move out of static item `D` --> $DIR/move-error-snippets-ext.rs:5:17 | LL | let a = $c; - | ^^ - | | - | move occurs because `D` has type `A`, which does not implement the `Copy` trait - | help: consider borrowing here: `&$c` + | ^^ move occurs because `D` has type `A`, which does not implement the `Copy` trait | ::: $DIR/move-error-snippets.rs:21:1 | @@ -13,6 +10,10 @@ LL | sss!(); | ------ in this macro invocation | = note: this error originates in the macro `aaa` which comes from the expansion of the macro `sss` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider borrowing here + | +LL | let a = &$c; + | + error: aborting due to previous error diff --git a/src/test/ui/by-move-pattern-binding.rs b/src/test/ui/by-move-pattern-binding.rs index d4c9f23164f8b..f68d181291dd7 100644 --- a/src/test/ui/by-move-pattern-binding.rs +++ b/src/test/ui/by-move-pattern-binding.rs @@ -19,4 +19,11 @@ fn main() { &E::Foo => {} &E::Bar(ref identifier) => println!("{}", *identifier) }; + if let &E::Bar(identifier) = &s.x { //~ ERROR cannot move + f(identifier.clone()); + }; + let &E::Bar(identifier) = &s.x else { //~ ERROR cannot move + return; + }; + f(identifier.clone()); } diff --git a/src/test/ui/by-move-pattern-binding.stderr b/src/test/ui/by-move-pattern-binding.stderr index 0012f67cfa1cd..203e37dc387c1 100644 --- a/src/test/ui/by-move-pattern-binding.stderr +++ b/src/test/ui/by-move-pattern-binding.stderr @@ -5,12 +5,47 @@ LL | match &s.x { | ^^^^ LL | &E::Foo => {} LL | &E::Bar(identifier) => f(identifier.clone()) - | ------------------- - | | | - | | data moved here - | | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait - | help: consider removing the `&`: `E::Bar(identifier)` + | ---------- + | | + | data moved here + | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &E::Bar(identifier) => f(identifier.clone()) +LL + E::Bar(identifier) => f(identifier.clone()) + | + +error[E0507]: cannot move out of a shared reference + --> $DIR/by-move-pattern-binding.rs:22:34 + | +LL | if let &E::Bar(identifier) = &s.x { + | ---------- ^^^^ + | | + | data moved here + | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - if let &E::Bar(identifier) = &s.x { +LL + if let E::Bar(identifier) = &s.x { + | + +error[E0507]: cannot move out of a shared reference + --> $DIR/by-move-pattern-binding.rs:25:31 + | +LL | let &E::Bar(identifier) = &s.x else { + | ---------- ^^^^ + | | + | data moved here + | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let &E::Bar(identifier) = &s.x else { +LL + let E::Bar(identifier) = &s.x else { + | -error: aborting due to previous error +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/check-static-values-constraints.stderr b/src/test/ui/check-static-values-constraints.stderr index 31939f7f6db5d..b13700a4ea5ba 100644 --- a/src/test/ui/check-static-values-constraints.stderr +++ b/src/test/ui/check-static-values-constraints.stderr @@ -58,10 +58,12 @@ error[E0507]: cannot move out of static item `x` --> $DIR/check-static-values-constraints.rs:110:45 | LL | let y = { static x: Box = box 3; x }; - | ^ - | | - | move occurs because `x` has type `Box`, which does not implement the `Copy` trait - | help: consider borrowing here: `&x` + | ^ move occurs because `x` has type `Box`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let y = { static x: Box = box 3; &x }; + | + error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:110:38 diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.fixed b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.fixed new file mode 100644 index 0000000000000..ae0a84eea4d9a --- /dev/null +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.fixed @@ -0,0 +1,21 @@ +// run-rustfix +struct X { + x: String, +} + +impl Drop for X { + fn drop(&mut self) { + println!("value: {}", self.x); + } +} + +fn unwrap(x: X) -> String { + let X { x: ref y } = x; //~ ERROR cannot move out of type + y.to_string() +} + +fn main() { + let x = X { x: "hello".to_string() }; + let y = unwrap(x); + println!("contents: {}", y); +} diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.rs b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.rs index 8e394498a2349..c8db786106813 100644 --- a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.rs +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.rs @@ -1,3 +1,4 @@ +// run-rustfix struct X { x: String, } @@ -10,7 +11,7 @@ impl Drop for X { fn unwrap(x: X) -> String { let X { x: y } = x; //~ ERROR cannot move out of type - y + y.to_string() } fn main() { diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.stderr b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.stderr index cda81d1366995..596ad4bf784bb 100644 --- a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.stderr +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-let.stderr @@ -1,11 +1,16 @@ error[E0509]: cannot move out of type `X`, which implements the `Drop` trait - --> $DIR/disallowed-deconstructing-destructing-struct-let.rs:12:22 + --> $DIR/disallowed-deconstructing-destructing-struct-let.rs:13:22 | LL | let X { x: y } = x; | - ^ cannot move out of here | | | data moved here | move occurs because `y` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let X { x: ref y } = x; + | +++ error: aborting due to previous error diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.fixed b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.fixed new file mode 100644 index 0000000000000..c8a451efeb28e --- /dev/null +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.fixed @@ -0,0 +1,19 @@ +// run-rustfix +struct X { + x: String, +} + +impl Drop for X { + fn drop(&mut self) { + println!("value: {}", self.x); + } +} + +fn main() { + let x = X { x: "hello".to_string() }; + + match x { + //~^ ERROR cannot move out of type `X`, which implements the `Drop` trait + X { x: ref y } => println!("contents: {}", y) + } +} diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.rs b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.rs index 9c996a93b9532..815567ffec358 100644 --- a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.rs +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.rs @@ -1,3 +1,4 @@ +// run-rustfix struct X { x: String, } diff --git a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.stderr b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.stderr index 70cdd6446c8d9..e32a4dd441149 100644 --- a/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.stderr +++ b/src/test/ui/disallowed-deconstructing/disallowed-deconstructing-destructing-struct-match.stderr @@ -1,5 +1,5 @@ error[E0509]: cannot move out of type `X`, which implements the `Drop` trait - --> $DIR/disallowed-deconstructing-destructing-struct-match.rs:14:11 + --> $DIR/disallowed-deconstructing-destructing-struct-match.rs:15:11 | LL | match x { | ^ cannot move out of here @@ -9,6 +9,11 @@ LL | X { x: y } => println!("contents: {}", y) | | | data moved here | move occurs because `y` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | X { x: ref y } => println!("contents: {}", y) + | +++ error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0508-fail.stderr b/src/test/ui/error-codes/E0508-fail.stderr index b69d7743b6c2c..208ba30729f8b 100644 --- a/src/test/ui/error-codes/E0508-fail.stderr +++ b/src/test/ui/error-codes/E0508-fail.stderr @@ -6,7 +6,11 @@ LL | let _value = array[0]; | | | cannot move out of here | move occurs because `array[_]` has type `NonCopy`, which does not implement the `Copy` trait - | help: consider borrowing here: `&array[0]` + | +help: consider borrowing here + | +LL | let _value = &array[0]; + | + error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0508.stderr b/src/test/ui/error-codes/E0508.stderr index 5e7b56dcd372a..df2d3b0d311c9 100644 --- a/src/test/ui/error-codes/E0508.stderr +++ b/src/test/ui/error-codes/E0508.stderr @@ -6,7 +6,11 @@ LL | let _value = array[0]; | | | cannot move out of here | move occurs because `array[_]` has type `NonCopy`, which does not implement the `Copy` trait - | help: consider borrowing here: `&array[0]` + | +help: consider borrowing here + | +LL | let _value = &array[0]; + | + error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0509.stderr b/src/test/ui/error-codes/E0509.stderr index cbfbc3ccf6a87..c00d9142e7505 100644 --- a/src/test/ui/error-codes/E0509.stderr +++ b/src/test/ui/error-codes/E0509.stderr @@ -6,7 +6,11 @@ LL | let fancy_field = drop_struct.fancy; | | | cannot move out of here | move occurs because `drop_struct.fancy` has type `FancyNum`, which does not implement the `Copy` trait - | help: consider borrowing here: `&drop_struct.fancy` + | +help: consider borrowing here + | +LL | let fancy_field = &drop_struct.fancy; + | + error: aborting due to previous error diff --git a/src/test/ui/issues/issue-12567.stderr b/src/test/ui/issues/issue-12567.stderr index 3ce659ccd14da..7fa06825f0f00 100644 --- a/src/test/ui/issues/issue-12567.stderr +++ b/src/test/ui/issues/issue-12567.stderr @@ -11,6 +11,14 @@ LL | (&[hd1, ..], &[hd2, ..]) | --- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider borrowing the pattern binding + | +LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[]) + | +++ +help: consider borrowing the pattern binding + | +LL | (&[ref hd1, ..], &[hd2, ..]) + | +++ error[E0508]: cannot move out of type `[T]`, a non-copy slice --> $DIR/issue-12567.rs:2:11 @@ -25,6 +33,14 @@ LL | (&[hd1, ..], &[hd2, ..]) | --- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider borrowing the pattern binding + | +LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[]) + | +++ +help: consider borrowing the pattern binding + | +LL | (&[hd1, ..], &[ref hd2, ..]) + | +++ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr index 0a5a6b80e9b23..e15eed6561234 100644 --- a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr @@ -2,10 +2,12 @@ error[E0507]: cannot move out of index of `Vec` --> $DIR/issue-40402-1.rs:9:13 | LL | let e = f.v[0]; - | ^^^^^^ - | | - | move occurs because value has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&f.v[0]` + | ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let e = &f.v[0]; + | + error: aborting due to previous error diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr index b6049f967ff40..1bc554efb5c3d 100644 --- a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr @@ -2,12 +2,16 @@ error[E0507]: cannot move out of index of `Vec<(String, String)>` --> $DIR/issue-40402-2.rs:5:18 | LL | let (a, b) = x[0]; - | - - ^^^^ 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 +help: consider borrowing here + | +LL | let (a, b) = &x[0]; + | + error: aborting due to previous error diff --git a/src/test/ui/moves/issue-99470-move-out-of-some.stderr b/src/test/ui/moves/issue-99470-move-out-of-some.stderr index 6e4a4e5ba22c1..c5159471fe3e4 100644 --- a/src/test/ui/moves/issue-99470-move-out-of-some.stderr +++ b/src/test/ui/moves/issue-99470-move-out-of-some.stderr @@ -5,11 +5,16 @@ LL | match x { | ^ LL | LL | &Some(_y) => (), - | --------- - | | | - | | data moved here - | | move occurs because `_y` has type `Box`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Some(_y)` + | -- + | | + | data moved here + | move occurs because `_y` has type `Box`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &Some(_y) => (), +LL + Some(_y) => (), + | error: aborting due to previous error diff --git a/src/test/ui/moves/move-out-of-array-ref.stderr b/src/test/ui/moves/move-out-of-array-ref.stderr index 0caa0b83a4c7c..26d4996d6cb1d 100644 --- a/src/test/ui/moves/move-out-of-array-ref.stderr +++ b/src/test/ui/moves/move-out-of-array-ref.stderr @@ -2,45 +2,61 @@ error[E0508]: cannot move out of type `[D; 4]`, a non-copy array --> $DIR/move-out-of-array-ref.rs:8:24 | LL | let [_, e, _, _] = *a; - | - ^^ - | | | - | | cannot move out of here - | | help: consider borrowing here: `&*a` + | - ^^ cannot move out of here + | | | data moved here | move occurs because `e` has type `D`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let [_, e, _, _] = *a; +LL + let [_, e, _, _] = a; + | error[E0508]: cannot move out of type `[D; 4]`, a non-copy array --> $DIR/move-out-of-array-ref.rs:13:27 | LL | let [_, s @ .. , _] = *a; - | - ^^ - | | | - | | cannot move out of here - | | help: consider borrowing here: `&*a` + | - ^^ cannot move out of here + | | | data moved here | move occurs because `s` has type `[D; 2]`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let [_, s @ .. , _] = *a; +LL + let [_, s @ .. , _] = a; + | error[E0508]: cannot move out of type `[D; 4]`, a non-copy array --> $DIR/move-out-of-array-ref.rs:18:24 | LL | let [_, e, _, _] = *a; - | - ^^ - | | | - | | cannot move out of here - | | help: consider borrowing here: `&*a` + | - ^^ cannot move out of here + | | | data moved here | move occurs because `e` has type `D`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let [_, e, _, _] = *a; +LL + let [_, e, _, _] = a; + | error[E0508]: cannot move out of type `[D; 4]`, a non-copy array --> $DIR/move-out-of-array-ref.rs:23:27 | LL | let [_, s @ .. , _] = *a; - | - ^^ - | | | - | | cannot move out of here - | | help: consider borrowing here: `&*a` + | - ^^ cannot move out of here + | | | data moved here | move occurs because `s` has type `[D; 2]`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let [_, s @ .. , _] = *a; +LL + let [_, s @ .. , _] = a; + | error: aborting due to 4 previous errors diff --git a/src/test/ui/moves/move-out-of-slice-1.stderr b/src/test/ui/moves/move-out-of-slice-1.stderr index ce5ddb3e183b1..5a0357cf567da 100644 --- a/src/test/ui/moves/move-out-of-slice-1.stderr +++ b/src/test/ui/moves/move-out-of-slice-1.stderr @@ -8,6 +8,11 @@ LL | box [a] => {}, | | | data moved here | move occurs because `a` has type `A`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | box [ref a] => {}, + | +++ error: aborting due to previous error diff --git a/src/test/ui/moves/move-out-of-slice-2.rs b/src/test/ui/moves/move-out-of-slice-2.rs index 59c02d42bf17e..2f7394fbfd36c 100644 --- a/src/test/ui/moves/move-out-of-slice-2.rs +++ b/src/test/ui/moves/move-out-of-slice-2.rs @@ -1,5 +1,6 @@ #![feature(unsized_locals)] //~^ WARN the feature `unsized_locals` is incomplete +#![allow(unused)] struct A; #[derive(Clone, Copy)] diff --git a/src/test/ui/moves/move-out-of-slice-2.stderr b/src/test/ui/moves/move-out-of-slice-2.stderr index 46357ce6f2eac..b46854cd6b458 100644 --- a/src/test/ui/moves/move-out-of-slice-2.stderr +++ b/src/test/ui/moves/move-out-of-slice-2.stderr @@ -8,7 +8,7 @@ LL | #![feature(unsized_locals)] = note: `#[warn(incomplete_features)]` on by default error[E0508]: cannot move out of type `[A]`, a non-copy slice - --> $DIR/move-out-of-slice-2.rs:10:11 + --> $DIR/move-out-of-slice-2.rs:11:11 | LL | match *a { | ^^ cannot move out of here @@ -18,9 +18,14 @@ LL | [a @ ..] => {} | | | data moved here | move occurs because `a` has type `[A]`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | [ref a @ ..] => {} + | +++ error[E0508]: cannot move out of type `[A]`, a non-copy slice - --> $DIR/move-out-of-slice-2.rs:16:11 + --> $DIR/move-out-of-slice-2.rs:17:11 | LL | match *b { | ^^ cannot move out of here @@ -30,9 +35,14 @@ LL | [_, _, b @ .., _] => {} | | | data moved here | move occurs because `b` has type `[A]`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | [_, _, ref b @ .., _] => {} + | +++ error[E0508]: cannot move out of type `[C]`, a non-copy slice - --> $DIR/move-out-of-slice-2.rs:24:11 + --> $DIR/move-out-of-slice-2.rs:25:11 | LL | match *c { | ^^ cannot move out of here @@ -42,9 +52,14 @@ LL | [c @ ..] => {} | | | data moved here | move occurs because `c` has type `[C]`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | [ref c @ ..] => {} + | +++ error[E0508]: cannot move out of type `[C]`, a non-copy slice - --> $DIR/move-out-of-slice-2.rs:30:11 + --> $DIR/move-out-of-slice-2.rs:31:11 | LL | match *d { | ^^ cannot move out of here @@ -54,6 +69,11 @@ LL | [_, _, d @ .., _] => {} | | | data moved here | move occurs because `d` has type `[C]`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | [_, _, ref d @ .., _] => {} + | +++ error: aborting due to 4 previous errors; 1 warning emitted diff --git a/src/test/ui/moves/moves-based-on-type-block-bad.stderr b/src/test/ui/moves/moves-based-on-type-block-bad.stderr index 5ed91a0d55963..df09ababa5a01 100644 --- a/src/test/ui/moves/moves-based-on-type-block-bad.stderr +++ b/src/test/ui/moves/moves-based-on-type-block-bad.stderr @@ -2,13 +2,18 @@ error[E0507]: cannot move out of `hellothere.x` as enum variant `Bar` which is b --> $DIR/moves-based-on-type-block-bad.rs:22:19 | LL | match hellothere.x { - | ^^^^^^^^^^^^ help: consider borrowing here: `&hellothere.x` + | ^^^^^^^^^^^^ LL | box E::Foo(_) => {} LL | box E::Bar(x) => println!("{}", x.to_string()), | - | | | data moved here | move occurs because `x` has type `Box`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &hellothere.x { + | + error: aborting due to previous error diff --git a/src/test/ui/nll/cannot-move-block-spans.stderr b/src/test/ui/nll/cannot-move-block-spans.stderr index 56a5cdff073e4..0dc5c08ea5f08 100644 --- a/src/test/ui/nll/cannot-move-block-spans.stderr +++ b/src/test/ui/nll/cannot-move-block-spans.stderr @@ -2,28 +2,37 @@ error[E0507]: cannot move out of `*r` which is behind a shared reference --> $DIR/cannot-move-block-spans.rs:5:15 | LL | let x = { *r }; - | ^^ - | | - | move occurs because `*r` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because `*r` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = { *r }; +LL + let x = { r }; + | error[E0507]: cannot move out of `*r` which is behind a shared reference --> $DIR/cannot-move-block-spans.rs:6:22 | LL | let y = unsafe { *r }; - | ^^ - | | - | move occurs because `*r` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because `*r` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let y = unsafe { *r }; +LL + let y = unsafe { r }; + | error[E0507]: cannot move out of `*r` which is behind a shared reference --> $DIR/cannot-move-block-spans.rs:7:26 | LL | let z = loop { break *r; }; - | ^^ - | | - | move occurs because `*r` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because `*r` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let z = loop { break *r; }; +LL + let z = loop { break r; }; + | error[E0508]: cannot move out of type `[String; 2]`, a non-copy array --> $DIR/cannot-move-block-spans.rs:11:15 @@ -33,7 +42,11 @@ LL | let x = { arr[0] }; | | | cannot move out of here | move occurs because `arr[_]` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&arr[0]` + | +help: consider borrowing here + | +LL | let x = { &arr[0] }; + | + error[E0508]: cannot move out of type `[String; 2]`, a non-copy array --> $DIR/cannot-move-block-spans.rs:12:22 @@ -43,7 +56,11 @@ LL | let y = unsafe { arr[0] }; | | | cannot move out of here | move occurs because `arr[_]` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&arr[0]` + | +help: consider borrowing here + | +LL | let y = unsafe { &arr[0] }; + | + error[E0508]: cannot move out of type `[String; 2]`, a non-copy array --> $DIR/cannot-move-block-spans.rs:13:26 @@ -53,34 +70,47 @@ LL | let z = loop { break arr[0]; }; | | | cannot move out of here | move occurs because `arr[_]` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&arr[0]` + | +help: consider borrowing here + | +LL | let z = loop { break &arr[0]; }; + | + error[E0507]: cannot move out of `*r` which is behind a shared reference --> $DIR/cannot-move-block-spans.rs:17:38 | LL | let x = { let mut u = 0; u += 1; *r }; - | ^^ - | | - | move occurs because `*r` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because `*r` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = { let mut u = 0; u += 1; *r }; +LL + let x = { let mut u = 0; u += 1; r }; + | error[E0507]: cannot move out of `*r` which is behind a shared reference --> $DIR/cannot-move-block-spans.rs:18:45 | LL | let y = unsafe { let mut u = 0; u += 1; *r }; - | ^^ - | | - | move occurs because `*r` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because `*r` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let y = unsafe { let mut u = 0; u += 1; *r }; +LL + let y = unsafe { let mut u = 0; u += 1; r }; + | error[E0507]: cannot move out of `*r` which is behind a shared reference --> $DIR/cannot-move-block-spans.rs:19:49 | LL | let z = loop { let mut u = 0; u += 1; break *r; u += 2; }; - | ^^ - | | - | move occurs because `*r` has type `String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because `*r` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let z = loop { let mut u = 0; u += 1; break *r; u += 2; }; +LL + let z = loop { let mut u = 0; u += 1; break r; u += 2; }; + | error: aborting due to 9 previous errors diff --git a/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr b/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr index c0a17a67ee269..7f9cbc3c30a92 100644 --- a/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr +++ b/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr @@ -36,7 +36,11 @@ LL | let p = s.url; p | | | cannot move out of here | move occurs because `s.url` has type `&mut String`, which does not implement the `Copy` trait - | help: consider borrowing here: `&s.url` + | +help: consider borrowing here + | +LL | let p = &s.url; p + | + error: aborting due to 4 previous errors diff --git a/src/test/ui/nll/move-errors.stderr b/src/test/ui/nll/move-errors.stderr index b03fcf70babe2..58b8aa31d4c2d 100644 --- a/src/test/ui/nll/move-errors.stderr +++ b/src/test/ui/nll/move-errors.stderr @@ -2,10 +2,13 @@ error[E0507]: cannot move out of `*a` which is behind a shared reference --> $DIR/move-errors.rs:6:13 | LL | let b = *a; - | ^^ - | | - | move occurs because `*a` has type `A`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*a` + | ^^ move occurs because `*a` has type `A`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let b = *a; +LL + let b = a; + | error[E0508]: cannot move out of type `[A; 1]`, a non-copy array --> $DIR/move-errors.rs:12:13 @@ -15,25 +18,35 @@ LL | let b = a[0]; | | | cannot move out of here | move occurs because `a[_]` has type `A`, which does not implement the `Copy` trait - | help: consider borrowing here: `&a[0]` + | +help: consider borrowing here + | +LL | let b = &a[0]; + | + error[E0507]: cannot move out of `**r` which is behind a shared reference --> $DIR/move-errors.rs:19:13 | LL | let s = **r; - | ^^^ - | | - | move occurs because `**r` has type `A`, which does not implement the `Copy` trait - | help: consider borrowing here: `&**r` + | ^^^ move occurs because `**r` has type `A`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let s = **r; +LL + let s = *r; + | error[E0507]: cannot move out of an `Rc` --> $DIR/move-errors.rs:27:13 | LL | let s = *r; - | ^^ - | | - | move occurs because value has type `A`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*r` + | ^^ move occurs because value has type `A`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let s = *r; +LL + let s = r; + | error[E0508]: cannot move out of type `[A; 1]`, a non-copy array --> $DIR/move-errors.rs:32:13 @@ -43,16 +56,26 @@ LL | let a = [A("".to_string())][0]; | | | cannot move out of here | move occurs because value has type `A`, which does not implement the `Copy` trait - | help: consider borrowing here: `&[A("".to_string())][0]` + | +help: consider borrowing here + | +LL | let a = &[A("".to_string())][0]; + | + error[E0507]: cannot move out of `a` which is behind a shared reference --> $DIR/move-errors.rs:38:16 | LL | let A(s) = *a; - | - ^^ help: consider borrowing here: `&*a` + | - ^^ | | | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let A(s) = *a; +LL + let A(s) = a; + | error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:44:19 @@ -62,6 +85,11 @@ LL | let C(D(s)) = c; | | | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let C(D(ref s)) = c; + | +++ error[E0507]: cannot move out of `*a` which is behind a shared reference --> $DIR/move-errors.rs:51:9 @@ -73,10 +101,7 @@ error[E0508]: cannot move out of type `[B; 1]`, a non-copy array --> $DIR/move-errors.rs:74:11 | LL | match x[0] { - | ^^^^ - | | - | cannot move out of here - | help: consider borrowing here: `&x[0]` + | ^^^^ cannot move out of here LL | LL | B::U(d) => (), | - data moved here @@ -84,6 +109,10 @@ LL | B::V(s) => (), | - ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider borrowing here + | +LL | match &x[0] { + | + error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:83:11 @@ -96,6 +125,11 @@ LL | B::U(D(s)) => (), | | | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | B::U(D(ref s)) => (), + | +++ error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:92:11 @@ -108,6 +142,11 @@ LL | (D(s), &t) => (), | | | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | (D(ref s), &t) => (), + | +++ error[E0507]: cannot move out of `*x.1` which is behind a shared reference --> $DIR/move-errors.rs:92:11 @@ -120,6 +159,11 @@ LL | (D(s), &t) => (), | | | data moved here | move occurs because `t` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | (D(s), &ref t) => (), + | +++ error[E0509]: cannot move out of type `F`, which implements the `Drop` trait --> $DIR/move-errors.rs:102:11 @@ -133,18 +177,32 @@ LL | F(s, mut t) => (), | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider borrowing the pattern binding + | +LL | F(ref s, mut t) => (), + | +++ +help: consider borrowing the pattern binding + | +LL | F(s, ref mut t) => (), + | +++ error[E0507]: cannot move out of `x` as enum variant `Err` which is behind a shared reference --> $DIR/move-errors.rs:110:11 | LL | match *x { - | ^^ help: consider borrowing here: `&*x` + | ^^ LL | LL | Ok(s) | Err(s) => (), | - | | | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *x { +LL + match x { + | error: aborting due to 14 previous errors diff --git a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.fixed b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.fixed new file mode 100644 index 0000000000000..5f04fc83d37ab --- /dev/null +++ b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.fixed @@ -0,0 +1,12 @@ +// run-rustfix +#![allow(unused_variables)] +fn main() { + struct U; + + // A tuple is a "non-reference pattern". + // A `mut` binding pattern resets the binding mode to by-value. + + let mut p = (U, U); + let (a, ref mut b) = &mut p; + //~^ ERROR cannot move out of a mutable reference +} diff --git a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.rs b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.rs new file mode 100644 index 0000000000000..5dc1ae2feb5f0 --- /dev/null +++ b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.rs @@ -0,0 +1,12 @@ +// run-rustfix +#![allow(unused_variables)] +fn main() { + struct U; + + // A tuple is a "non-reference pattern". + // A `mut` binding pattern resets the binding mode to by-value. + + let mut p = (U, U); + let (a, mut b) = &mut p; + //~^ ERROR cannot move out of a mutable reference +} diff --git a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.stderr b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.stderr new file mode 100644 index 0000000000000..d3ab533e35e4a --- /dev/null +++ b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes-fixable.stderr @@ -0,0 +1,17 @@ +error[E0507]: cannot move out of a mutable reference + --> $DIR/move-ref-patterns-default-binding-modes-fixable.rs:10:22 + | +LL | let (a, mut b) = &mut p; + | ----- ^^^^^^ + | | + | data moved here + | move occurs because `b` has type `U`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let (a, ref mut b) = &mut p; + | +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.rs b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.rs index 1dd66aad57a33..6c913c245130d 100644 --- a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.rs +++ b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.rs @@ -7,8 +7,4 @@ fn main() { let p = (U, U); let (a, mut b) = &p; //~^ ERROR cannot move out of a shared reference - - let mut p = (U, U); - let (a, mut b) = &mut p; - //~^ ERROR cannot move out of a mutable reference } diff --git a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.stderr b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.stderr index 6952c743a3069..65030b6225001 100644 --- a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.stderr +++ b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-default-binding-modes.stderr @@ -6,16 +6,12 @@ LL | let (a, mut b) = &p; | | | data moved here | move occurs because `b` has type `U`, which does not implement the `Copy` trait - -error[E0507]: cannot move out of a mutable reference - --> $DIR/move-ref-patterns-default-binding-modes.rs:12:22 | -LL | let (a, mut b) = &mut p; - | ----- ^^^^^^ - | | - | data moved here - | move occurs because `b` has type `U`, which does not implement the `Copy` trait +help: consider borrowing the pattern binding + | +LL | let (a, ref mut b) = &p; + | +++ -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/rfc-2005-default-binding-mode/for.stderr b/src/test/ui/rfc-2005-default-binding-mode/for.stderr index 9cc20a7bf3144..07991af6ef97c 100644 --- a/src/test/ui/rfc-2005-default-binding-mode/for.stderr +++ b/src/test/ui/rfc-2005-default-binding-mode/for.stderr @@ -6,6 +6,11 @@ LL | for (n, mut m) in &tups { | | | data moved here | move occurs because `m` has type `Foo`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | for (n, ref mut m) in &tups { + | +++ error: aborting due to previous error diff --git a/src/test/ui/std-uncopyable-atomics.stderr b/src/test/ui/std-uncopyable-atomics.stderr index 9db9fcf40f82c..8c5d0b9609627 100644 --- a/src/test/ui/std-uncopyable-atomics.stderr +++ b/src/test/ui/std-uncopyable-atomics.stderr @@ -2,37 +2,49 @@ error[E0507]: cannot move out of a shared reference --> $DIR/std-uncopyable-atomics.rs:9:13 | LL | let x = *&x; - | ^^^ - | | - | move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*&x` + | ^^^ move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = *&x; +LL + let x = &x; + | error[E0507]: cannot move out of a shared reference --> $DIR/std-uncopyable-atomics.rs:11:13 | LL | let x = *&x; - | ^^^ - | | - | move occurs because value has type `std::sync::atomic::AtomicIsize`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*&x` + | ^^^ move occurs because value has type `std::sync::atomic::AtomicIsize`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = *&x; +LL + let x = &x; + | error[E0507]: cannot move out of a shared reference --> $DIR/std-uncopyable-atomics.rs:13:13 | LL | let x = *&x; - | ^^^ - | | - | move occurs because value has type `std::sync::atomic::AtomicUsize`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*&x` + | ^^^ move occurs because value has type `std::sync::atomic::AtomicUsize`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = *&x; +LL + let x = &x; + | error[E0507]: cannot move out of a shared reference --> $DIR/std-uncopyable-atomics.rs:15:13 | LL | let x = *&x; - | ^^^ - | | - | move occurs because value has type `std::sync::atomic::AtomicPtr`, which does not implement the `Copy` trait - | help: consider borrowing here: `&*&x` + | ^^^ move occurs because value has type `std::sync::atomic::AtomicPtr`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let x = *&x; +LL + let x = &x; + | error: aborting due to 4 previous errors diff --git a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs index bf0c1dc27ce43..e19d497f21d29 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs +++ b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.rs @@ -38,31 +38,25 @@ pub fn main() { let &(X(_t), X(_u)) = &(x.clone(), x.clone()); //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION (X(_t), X(_u)) + //~| HELP consider removing the borrow 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)) + //~| HELP consider removing the borrow 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)) + //~| HELP consider removing the borrow 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)) + //~^ HELP consider removing the borrow &(Either::Two(_t), Either::One(_u)) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION (Either::Two(_t), Either::One(_u)) + //~^ HELP consider removing the borrow _ => (), } 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)) + //~^ HELP consider removing the borrow | &(Either::Two(_t), Either::One(_u)) => (), // FIXME: would really like a suggestion here too _ => (), @@ -70,51 +64,42 @@ pub fn main() { 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)) + //~^ HELP consider removing the borrow &(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)) + //~^ HELP consider removing the borrow (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)) + //~| HELP consider removing the borrow let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION (X(_t), X(_u)) + //~| HELP consider removing the mutable borrow 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)) + //~| HELP consider removing the mutable borrow 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)) + //~| HELP consider removing the mutable borrow 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)) + //~^ HELP consider removing the mutable borrow &mut (Either::Two(_t), Either::One(_u)) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION (Either::Two(_t), Either::One(_u)) + //~^ HELP consider removing the mutable borrow _ => (), } 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)) + //~^ HELP consider removing the mutable borrow | &mut (Either::Two(_t), Either::One(_u)) => (), // FIXME: would really like a suggestion here too _ => (), @@ -122,29 +107,25 @@ pub fn main() { 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)) + //~^ HELP consider removing the mutable borrow &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)) + //~^ HELP consider removing the mutable borrow &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)) + //~^ HELP consider removing the mutable borrow (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)) + //~| HELP consider removing the mutable borrow } diff --git a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr index 40ad671f96630..b96b3713f2a7a 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr @@ -2,40 +2,52 @@ error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:39:27 | LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - | --------------- ^^^^^^^^^^^^^^^^^^^^^^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(X(_t), X(_u))` + | -- -- ^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the borrow + | +LL - let &(X(_t), X(_u)) = &(x.clone(), x.clone()); +LL + let (X(_t), X(_u)) = &(x.clone(), x.clone()); + | error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:43:50 + --> $DIR/duplicate-suggestions.rs:42:50 | LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | -- -- ^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the borrow + | +LL - if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } +LL + if let (Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:47:53 + --> $DIR/duplicate-suggestions.rs:45:53 | LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | -- -- ^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the borrow + | +LL - while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } +LL + while let (Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } + | error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:51:11 + --> $DIR/duplicate-suggestions.rs:48:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,22 +56,24 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | -- -- ...and here | | | data moved here -... +LL | 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 -help: consider removing the `&` +help: consider removing the borrow | -LL | (Either::One(_t), Either::Two(_u)) => (), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: consider removing the `&` +LL - &(Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), + | +help: consider removing the borrow + | +LL - &(Either::Two(_t), Either::One(_u)) => (), +LL + (Either::Two(_t), Either::One(_u)) => (), | -LL | (Either::Two(_t), Either::One(_u)) => (), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:61:11 + --> $DIR/duplicate-suggestions.rs:56:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,82 +84,98 @@ LL | &(Either::One(_t), Either::Two(_u)) | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider removing the `&` +help: consider removing the borrow | -LL ~ (Either::One(_t), Either::Two(_u)) -LL + -LL + -LL ~ | &(Either::Two(_t), Either::One(_u)) => (), +LL - &(Either::One(_t), Either::Two(_u)) +LL + (Either::One(_t), Either::Two(_u)) | error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:70:11 + --> $DIR/duplicate-suggestions.rs:64:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | &(Either::One(_t), Either::Two(_u)) => (), - | ----------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | -- -- ...and here + | | + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the borrow + | +LL - &(Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), + | error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:78:11 + --> $DIR/duplicate-suggestions.rs:71:11 | LL | match &(e.clone(), e.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | &(Either::One(_t), Either::Two(_u)) => (), - | ----------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` + | -- -- ...and here + | | + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the borrow + | +LL - &(Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:91:31 + --> $DIR/duplicate-suggestions.rs:82:31 | LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(X(_t), X(_u))` + | -- -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); +LL + let (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:95:54 + --> $DIR/duplicate-suggestions.rs:85:54 | LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | -- -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } +LL + if let (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:99:57 + --> $DIR/duplicate-suggestions.rs:88:57 | LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | --------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | -- -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } +LL + while let (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:103:11 + --> $DIR/duplicate-suggestions.rs:91:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,22 +184,24 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | -- -- ...and here | | | data moved here -... +LL | 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 -help: consider removing the `&mut` +help: consider removing the mutable borrow + | +LL - &mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), | -LL | (Either::One(_t), Either::Two(_u)) => (), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: consider removing the `&mut` +help: consider removing the mutable borrow + | +LL - &mut (Either::Two(_t), Either::One(_u)) => (), +LL + (Either::Two(_t), Either::One(_u)) => (), | -LL | (Either::Two(_t), Either::One(_u)) => (), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:113:11 + --> $DIR/duplicate-suggestions.rs:99:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,82 +212,97 @@ LL | &mut (Either::One(_t), Either::Two(_u)) | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider removing the `&mut` +help: consider removing the mutable borrow | -LL ~ (Either::One(_t), Either::Two(_u)) -LL + -LL + -LL ~ | &mut (Either::Two(_t), Either::One(_u)) => (), +LL - &mut (Either::One(_t), Either::Two(_u)) +LL + (Either::One(_t), Either::Two(_u)) | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:122:11 + --> $DIR/duplicate-suggestions.rs:107:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | -- -- ...and here + | | + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - &mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:130:11 + --> $DIR/duplicate-suggestions.rs:114:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | -- -- ...and here + | | + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - &mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:138:11 + --> $DIR/duplicate-suggestions.rs:121:11 | LL | match &mut (em.clone(), em.clone()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | --------------------------------------- - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` + | -- -- ...and here + | | + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - &mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), + | error[E0507]: cannot move out of a shared reference - --> $DIR/duplicate-suggestions.rs:86:11 + --> $DIR/duplicate-suggestions.rs:78:11 | LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | ^^^^--^^^^^--^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&`: `(X(_t), X(_u))` + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the borrow + | +LL - fn f5(&(X(_t), X(_u)): &(X, X)) { } +LL + fn f5((X(_t), X(_u)): &(X, X)) { } + | error[E0507]: cannot move out of a mutable reference - --> $DIR/duplicate-suggestions.rs:146:11 + --> $DIR/duplicate-suggestions.rs:128:11 | LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | ^^^^^^^^--^^^^^--^^ - | | | | - | | | ...and here - | | data moved here - | help: consider removing the `&mut`: `(X(_t), X(_u))` + | | | + | | ...and here + | data moved here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider removing the mutable borrow + | +LL - fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } +LL + fn f6((X(_t), X(_u)): &mut (X, X)) { } + | error: aborting due to 17 previous errors diff --git a/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs index f1e043c30f213..44eac3691a3be 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs +++ b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.rs @@ -28,26 +28,21 @@ fn move_into_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 @@ -56,26 +51,21 @@ fn move_into_fn() { 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 @@ -95,26 +85,21 @@ fn move_into_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 @@ -123,26 +108,21 @@ fn move_into_fnmut() { 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 @@ -150,7 +130,6 @@ fn move_into_fnmut() { 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/move-into-closure.stderr b/src/test/ui/suggestions/dont-suggest-ref/move-into-closure.stderr index e06ee4290abd8..edda2cbc735a2 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 @@ -7,13 +7,18 @@ LL | let x = X(Y); LL | consume_fn(|| { | -- captured by this `Fn` closure LL | let X(_t) = x; - | -- ^ help: consider borrowing here: `&x` + | -- ^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let X(_t) = &x; + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:32:34 + --> $DIR/move-into-closure.rs:31:34 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -22,13 +27,18 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | if let Either::One(_t) = e { } - | -- ^ help: consider borrowing here: `&e` + | -- ^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | if let Either::One(_t) = &e { } + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:36:37 + --> $DIR/move-into-closure.rs:34:37 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -37,13 +47,18 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | while let Either::One(_t) = e { } - | -- ^ help: consider borrowing here: `&e` + | -- ^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | while let Either::One(_t) = &e { } + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:40:15 + --> $DIR/move-into-closure.rs:37:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -52,16 +67,21 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | match e { - | ^ help: consider borrowing here: `&e` + | ^ ... LL | Either::One(_t) | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &e { + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:47:15 + --> $DIR/move-into-closure.rs:43:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -70,16 +90,21 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | match e { - | ^ help: consider borrowing here: `&e` + | ^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &e { + | + error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:56:25 + --> $DIR/move-into-closure.rs:51:25 | LL | let x = X(Y); | - captured outer variable @@ -88,13 +113,18 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | let X(mut _t) = x; - | ------ ^ help: consider borrowing here: `&x` + | ------ ^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let X(mut _t) = &x; + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:60:38 + --> $DIR/move-into-closure.rs:54:38 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -103,13 +133,18 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | if let Either::One(mut _t) = em { } - | ------ ^^ help: consider borrowing here: `&em` + | ------ ^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | if let Either::One(mut _t) = &em { } + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:64:41 + --> $DIR/move-into-closure.rs:57:41 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -118,13 +153,18 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | while let Either::One(mut _t) = em { } - | ------ ^^ help: consider borrowing here: `&em` + | ------ ^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | while let Either::One(mut _t) = &em { } + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:68:15 + --> $DIR/move-into-closure.rs:60:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -133,16 +173,21 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | match em { - | ^^ help: consider borrowing here: `&em` + | ^^ ... LL | Either::One(mut _t) | ------ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &em { + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:75:15 + --> $DIR/move-into-closure.rs:66:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -151,16 +196,21 @@ LL | consume_fn(|| { | -- captured by this `Fn` closure ... LL | match em { - | ^^ help: consider borrowing here: `&em` + | ^^ ... LL | Either::One(mut _t) => (), | ------ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &em { + | + error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:95:21 + --> $DIR/move-into-closure.rs:85:21 | LL | let x = X(Y); | - captured outer variable @@ -168,13 +218,18 @@ LL | let x = X(Y); LL | consume_fnmut(|| { | -- captured by this `FnMut` closure LL | let X(_t) = x; - | -- ^ help: consider borrowing here: `&x` + | -- ^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let X(_t) = &x; + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:99:34 + --> $DIR/move-into-closure.rs:88:34 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -183,13 +238,18 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | if let Either::One(_t) = e { } - | -- ^ help: consider borrowing here: `&e` + | -- ^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | if let Either::One(_t) = &e { } + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:103:37 + --> $DIR/move-into-closure.rs:91:37 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -198,13 +258,18 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | while let Either::One(_t) = e { } - | -- ^ help: consider borrowing here: `&e` + | -- ^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | while let Either::One(_t) = &e { } + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:107:15 + --> $DIR/move-into-closure.rs:94:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -213,16 +278,21 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | match e { - | ^ help: consider borrowing here: `&e` + | ^ ... LL | Either::One(_t) | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &e { + | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:114:15 + --> $DIR/move-into-closure.rs:100:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -231,16 +301,21 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | match e { - | ^ help: consider borrowing here: `&e` + | ^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &e { + | + error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:123:25 + --> $DIR/move-into-closure.rs:108:25 | LL | let x = X(Y); | - captured outer variable @@ -249,13 +324,18 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | let X(mut _t) = x; - | ------ ^ help: consider borrowing here: `&x` + | ------ ^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let X(mut _t) = &x; + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:127:38 + --> $DIR/move-into-closure.rs:111:38 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -264,13 +344,18 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | if let Either::One(mut _t) = em { } - | ------ ^^ help: consider borrowing here: `&em` + | ------ ^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | if let Either::One(mut _t) = &em { } + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:131:41 + --> $DIR/move-into-closure.rs:114:41 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -279,13 +364,18 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | while let Either::One(mut _t) = em { } - | ------ ^^ help: consider borrowing here: `&em` + | ------ ^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | while let Either::One(mut _t) = &em { } + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:135:15 + --> $DIR/move-into-closure.rs:117:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -294,16 +384,21 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | match em { - | ^^ help: consider borrowing here: `&em` + | ^^ ... LL | Either::One(mut _t) | ------ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &em { + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:142:15 + --> $DIR/move-into-closure.rs:123:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -312,16 +407,21 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | match em { - | ^^ help: consider borrowing here: `&em` + | ^^ ... LL | Either::One(mut _t) => (), | ------ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &em { + | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:150:15 + --> $DIR/move-into-closure.rs:130:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -330,13 +430,18 @@ LL | consume_fnmut(|| { | -- captured by this `FnMut` closure ... LL | match em { - | ^^ help: consider borrowing here: `&em` + | ^^ ... LL | Either::One(mut _t) => (), | ------ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &em { + | + error: aborting due to 21 previous errors diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.rs b/src/test/ui/suggestions/dont-suggest-ref/simple.rs index c53ac3d2cd684..1e40e60a1ce12 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/simple.rs +++ b/src/test/ui/suggestions/dont-suggest-ref/simple.rs @@ -37,27 +37,22 @@ pub fn main() { let X(_t) = *s; //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION s + //~| HELP consider removing the dereference here if let Either::One(_t) = *r { } //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION r + //~| HELP consider removing the dereference here while let Either::One(_t) = *r { } //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION r + //~| HELP consider removing the dereference here match *r { //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION r + //~| HELP consider removing the dereference here Either::One(_t) | Either::Two(_t) => (), } match *r { //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION r + //~| HELP consider removing the dereference here Either::One(_t) => (), Either::Two(ref _t) => (), // FIXME: should suggest removing `ref` too @@ -65,35 +60,29 @@ pub fn main() { let X(_t) = *sm; //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION sm + //~| HELP consider removing the dereference here if let Either::One(_t) = *rm { } //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION rm + //~| HELP consider removing the dereference here while let Either::One(_t) = *rm { } //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION rm + //~| HELP consider removing the dereference here match *rm { //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION rm + //~| HELP consider removing the dereference here Either::One(_t) | Either::Two(_t) => (), } match *rm { //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION rm + //~| HELP consider removing the dereference here Either::One(_t) => (), Either::Two(ref _t) => (), // FIXME: should suggest removing `ref` too } match *rm { //~^ ERROR cannot move - //~| HELP consider borrowing here - //~| SUGGESTION rm + //~| HELP consider removing the dereference here Either::One(_t) => (), Either::Two(ref mut _t) => (), // FIXME: should suggest removing `ref` too @@ -102,26 +91,21 @@ pub fn main() { let X(_t) = vs[0]; //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vs[0] if let Either::One(_t) = vr[0] { } //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vr[0] while let Either::One(_t) = vr[0] { } //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vr[0] match vr[0] { //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vr[0] Either::One(_t) | Either::Two(_t) => (), } match vr[0] { //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vr[0] Either::One(_t) => (), Either::Two(ref _t) => (), // FIXME: should suggest removing `ref` too @@ -130,26 +114,21 @@ pub fn main() { let X(_t) = vsm[0]; //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vsm[0] if let Either::One(_t) = vrm[0] { } //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vrm[0] while let Either::One(_t) = vrm[0] { } //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vrm[0] match vrm[0] { //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vrm[0] Either::One(_t) | Either::Two(_t) => (), } match vrm[0] { //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref _t) => (), // FIXME: should suggest removing `ref` too @@ -157,7 +136,6 @@ pub fn main() { match vrm[0] { //~^ ERROR cannot move //~| HELP consider borrowing here - //~| SUGGESTION &vrm[0] Either::One(_t) => (), Either::Two(ref mut _t) => (), // FIXME: should suggest removing `ref` too @@ -167,89 +145,73 @@ pub fn main() { let &X(_t) = s; //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION X(_t) + //~| HELP consider removing if let &Either::One(_t) = r { } //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing while let &Either::One(_t) = r { } //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing match r { //~^ ERROR cannot move &Either::One(_t) - //~^ HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing | &Either::Two(_t) => (), // FIXME: would really like a suggestion here too } match r { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &Either::Two(ref _t) => (), } match r { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing Either::Two(_t) => (), } fn f1(&X(_t): &X) { } //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION X(_t) + //~| HELP consider removing let &mut X(_t) = sm; //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION X(_t) + //~| HELP consider removing if let &mut Either::One(_t) = rm { } //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing while let &mut Either::One(_t) = rm { } //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &mut Either::Two(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::Two(_t) + //~^ HELP consider removing } match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &mut Either::Two(ref _t) => (), } match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &mut Either::Two(ref mut _t) => (), } match rm { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing Either::Two(_t) => (), } fn f2(&mut X(_t): &mut X) { } //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION X(_t) + //~| HELP consider removing // move from tuple of &Either/&X @@ -257,108 +219,118 @@ pub fn main() { let (&X(_t),) = (&x.clone(),); //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding if let (&Either::One(_t),) = (&e.clone(),) { } //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding while let (&Either::One(_t),) = (&e.clone(),) { } //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding match (&e.clone(),) { //~^ ERROR cannot move (&Either::One(_t),) + //~^ HELP consider borrowing the pattern binding | (&Either::Two(_t),) => (), } fn f3((&X(_t),): (&X,)) { } //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding let (&mut X(_t),) = (&mut xm.clone(),); //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding if let (&mut Either::One(_t),) = (&mut em.clone(),) { } //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding while let (&mut Either::One(_t),) = (&mut em.clone(),) { } //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding match (&mut em.clone(),) { //~^ ERROR cannot move (&mut Either::One(_t),) => (), + //~^ HELP consider borrowing the pattern binding (&mut Either::Two(_t),) => (), + //~^ HELP consider borrowing the pattern binding } fn f4((&mut X(_t),): (&mut X,)) { } //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding // move from &Either/&X value let &X(_t) = &x; //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION X(_t) + //~| HELP consider removing if let &Either::One(_t) = &e { } //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing while let &Either::One(_t) = &e { } //~^ ERROR cannot move - //~| HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing match &e { //~^ ERROR cannot move &Either::One(_t) - //~^ HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing | &Either::Two(_t) => (), // FIXME: would really like a suggestion here too } match &e { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &Either::Two(ref _t) => (), } match &e { //~^ ERROR cannot move &Either::One(_t) => (), - //~^ HELP consider removing the `&` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing Either::Two(_t) => (), } let &mut X(_t) = &mut xm; //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION X(_t) + //~| HELP consider removing if let &mut Either::One(_t) = &mut em { } //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing while let &mut Either::One(_t) = &mut em { } //~^ ERROR cannot move - //~| HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~| HELP consider removing match &mut em { //~^ ERROR cannot move &mut Either::One(_t) - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing | &mut Either::Two(_t) => (), // FIXME: would really like a suggestion here too } match &mut em { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &mut Either::Two(ref _t) => (), } match &mut em { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing &mut Either::Two(ref mut _t) => (), } match &mut em { //~^ ERROR cannot move &mut Either::One(_t) => (), - //~^ HELP consider removing the `&mut` - //~| SUGGESTION Either::One(_t) + //~^ HELP consider removing Either::Two(_t) => (), } } + +struct Testing { + a: Option +} + +fn testing(a: &Testing) { + let Some(_s) = a.a else { + //~^ ERROR cannot move + //~| HELP consider borrowing the pattern binding + return; + }; +} diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr index e5443290f9e7a..5263265242318 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr @@ -2,262 +2,398 @@ error[E0507]: cannot move out of `s` which is behind a shared reference --> $DIR/simple.rs:38:17 | LL | let X(_t) = *s; - | -- ^^ help: consider borrowing here: `&*s` + | -- ^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let X(_t) = *s; +LL + let X(_t) = s; + | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:42:30 + --> $DIR/simple.rs:41:30 | LL | if let Either::One(_t) = *r { } - | -- ^^ help: consider borrowing here: `&*r` + | -- ^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - if let Either::One(_t) = *r { } +LL + if let Either::One(_t) = r { } + | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:46:33 + --> $DIR/simple.rs:44:33 | LL | while let Either::One(_t) = *r { } - | -- ^^ help: consider borrowing here: `&*r` + | -- ^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - while let Either::One(_t) = *r { } +LL + while let Either::One(_t) = r { } + | error[E0507]: cannot move out of `r` as enum variant `Two` which is behind a shared reference - --> $DIR/simple.rs:50:11 + --> $DIR/simple.rs:47:11 | LL | match *r { - | ^^ help: consider borrowing here: `&*r` + | ^^ ... LL | Either::One(_t) | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *r { +LL + match r { + | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:57:11 + --> $DIR/simple.rs:53:11 | LL | match *r { - | ^^ help: consider borrowing here: `&*r` + | ^^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *r { +LL + match r { + | error[E0507]: cannot move out of `sm` which is behind a mutable reference - --> $DIR/simple.rs:66:17 + --> $DIR/simple.rs:61:17 | LL | let X(_t) = *sm; - | -- ^^^ help: consider borrowing here: `&*sm` + | -- ^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - let X(_t) = *sm; +LL + let X(_t) = sm; + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:70:30 + --> $DIR/simple.rs:64:30 | LL | if let Either::One(_t) = *rm { } - | -- ^^^ help: consider borrowing here: `&*rm` + | -- ^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - if let Either::One(_t) = *rm { } +LL + if let Either::One(_t) = rm { } + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:74:33 + --> $DIR/simple.rs:67:33 | LL | while let Either::One(_t) = *rm { } - | -- ^^^ help: consider borrowing here: `&*rm` + | -- ^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - while let Either::One(_t) = *rm { } +LL + while let Either::One(_t) = rm { } + | error[E0507]: cannot move out of `rm` as enum variant `Two` which is behind a mutable reference - --> $DIR/simple.rs:78:11 + --> $DIR/simple.rs:70:11 | LL | match *rm { - | ^^^ help: consider borrowing here: `&*rm` + | ^^^ ... LL | Either::One(_t) | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *rm { +LL + match rm { + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:85:11 + --> $DIR/simple.rs:76:11 | LL | match *rm { - | ^^^ help: consider borrowing here: `&*rm` + | ^^^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *rm { +LL + match rm { + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:93:11 + --> $DIR/simple.rs:83:11 | LL | match *rm { - | ^^^ help: consider borrowing here: `&*rm` + | ^^^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the dereference here + | +LL - match *rm { +LL + match rm { + | error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:102:17 + --> $DIR/simple.rs:91:17 | LL | let X(_t) = vs[0]; - | -- ^^^^^ help: consider borrowing here: `&vs[0]` + | -- ^^^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let X(_t) = &vs[0]; + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:106:30 + --> $DIR/simple.rs:94:30 | LL | if let Either::One(_t) = vr[0] { } - | -- ^^^^^ help: consider borrowing here: `&vr[0]` + | -- ^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | if let Either::One(_t) = &vr[0] { } + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:110:33 + --> $DIR/simple.rs:97:33 | LL | while let Either::One(_t) = vr[0] { } - | -- ^^^^^ help: consider borrowing here: `&vr[0]` + | -- ^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | while let Either::One(_t) = &vr[0] { } + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:114:11 + --> $DIR/simple.rs:100:11 | LL | match vr[0] { - | ^^^^^ help: consider borrowing here: `&vr[0]` + | ^^^^^ ... LL | Either::One(_t) | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &vr[0] { + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:121:11 + --> $DIR/simple.rs:106:11 | LL | match vr[0] { - | ^^^^^ help: consider borrowing here: `&vr[0]` + | ^^^^^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &vr[0] { + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:130:17 + --> $DIR/simple.rs:114:17 | LL | let X(_t) = vsm[0]; - | -- ^^^^^^ help: consider borrowing here: `&vsm[0]` + | -- ^^^^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let X(_t) = &vsm[0]; + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:134:30 + --> $DIR/simple.rs:117:30 | LL | if let Either::One(_t) = vrm[0] { } - | -- ^^^^^^ help: consider borrowing here: `&vrm[0]` + | -- ^^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | if let Either::One(_t) = &vrm[0] { } + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:138:33 + --> $DIR/simple.rs:120:33 | LL | while let Either::One(_t) = vrm[0] { } - | -- ^^^^^^ help: consider borrowing here: `&vrm[0]` + | -- ^^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | while let Either::One(_t) = &vrm[0] { } + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:142:11 + --> $DIR/simple.rs:123:11 | LL | match vrm[0] { - | ^^^^^^ help: consider borrowing here: `&vrm[0]` + | ^^^^^^ ... LL | Either::One(_t) | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &vrm[0] { + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:149:11 + --> $DIR/simple.rs:129:11 | LL | match vrm[0] { - | ^^^^^^ help: consider borrowing here: `&vrm[0]` + | ^^^^^^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &vrm[0] { + | + error[E0507]: cannot move out of index of `Vec` - --> $DIR/simple.rs:157:11 + --> $DIR/simple.rs:136:11 | LL | match vrm[0] { - | ^^^^^^ help: consider borrowing here: `&vrm[0]` + | ^^^^^^ ... LL | Either::One(_t) => (), | -- | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | match &vrm[0] { + | + error[E0507]: cannot move out of `s` which is behind a shared reference - --> $DIR/simple.rs:168:18 + --> $DIR/simple.rs:146:18 | LL | let &X(_t) = s; - | ------ ^ - | | | - | | data moved here - | | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - | help: consider removing the `&`: `X(_t)` + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let &X(_t) = s; +LL + let X(_t) = s; + | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:172:31 + --> $DIR/simple.rs:149:31 | LL | if let &Either::One(_t) = r { } - | ---------------- ^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - if let &Either::One(_t) = r { } +LL + if let Either::One(_t) = r { } + | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:176:34 + --> $DIR/simple.rs:152:34 | LL | while let &Either::One(_t) = r { } - | ---------------- ^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - while let &Either::One(_t) = r { } +LL + while let Either::One(_t) = r { } + | error[E0507]: cannot move out of `r` as enum variant `Two` which is behind a shared reference - --> $DIR/simple.rs:180:11 + --> $DIR/simple.rs:155:11 | LL | match r { | ^ @@ -268,160 +404,215 @@ LL | &Either::One(_t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider removing the `&` +help: consider removing the borrow | -LL ~ Either::One(_t) -LL + -LL + -LL ~ | &Either::Two(_t) => (), +LL - &Either::One(_t) +LL + Either::One(_t) | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:188:11 + --> $DIR/simple.rs:162:11 | LL | match r { | ^ LL | LL | &Either::One(_t) => (), - | ---------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference - --> $DIR/simple.rs:195:11 + --> $DIR/simple.rs:168:11 | LL | match r { | ^ LL | LL | &Either::One(_t) => (), - | ---------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of `sm` which is behind a mutable reference - --> $DIR/simple.rs:207:22 + --> $DIR/simple.rs:178:22 | LL | let &mut X(_t) = sm; - | ---------- ^^ - | | | - | | data moved here - | | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `X(_t)` + | -- ^^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - let &mut X(_t) = sm; +LL + let X(_t) = sm; + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:211:35 + --> $DIR/simple.rs:181:35 | LL | if let &mut Either::One(_t) = rm { } - | -------------------- ^^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - if let &mut Either::One(_t) = rm { } +LL + if let Either::One(_t) = rm { } + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:215:38 + --> $DIR/simple.rs:184:38 | LL | while let &mut Either::One(_t) = rm { } - | -------------------- ^^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - while let &mut Either::One(_t) = rm { } +LL + while let Either::One(_t) = rm { } + | error[E0507]: cannot move out of `rm` as enum variant `Two` which is behind a mutable reference - --> $DIR/simple.rs:219:11 + --> $DIR/simple.rs:187:11 | LL | match rm { | ^^ LL | LL | &mut Either::One(_t) => (), | -- data moved here -... +LL | LL | &mut Either::Two(_t) => (), | -- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait -help: consider removing the `&mut` +help: consider removing the mutable borrow | -LL | Either::One(_t) => (), - | ~~~~~~~~~~~~~~~ -help: consider removing the `&mut` +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | +help: consider removing the mutable borrow + | +LL - &mut Either::Two(_t) => (), +LL + Either::Two(_t) => (), | -LL | Either::Two(_t) => (), - | ~~~~~~~~~~~~~~~ error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:228:11 + --> $DIR/simple.rs:194:11 | LL | match rm { | ^^ LL | LL | &mut Either::One(_t) => (), - | -------------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:235:11 + --> $DIR/simple.rs:200:11 | LL | match rm { | ^^ LL | LL | &mut Either::One(_t) => (), - | -------------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference - --> $DIR/simple.rs:242:11 + --> $DIR/simple.rs:206:11 | LL | match rm { | ^^ LL | LL | &mut Either::One(_t) => (), - | -------------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:258:21 + --> $DIR/simple.rs:220:21 | LL | let (&X(_t),) = (&x.clone(),); | -- ^^^^^^^^^^^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let (&X(ref _t),) = (&x.clone(),); + | +++ error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:260:34 + --> $DIR/simple.rs:223:34 | LL | if let (&Either::One(_t),) = (&e.clone(),) { } | -- ^^^^^^^^^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | if let (&Either::One(ref _t),) = (&e.clone(),) { } + | +++ error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:262:37 + --> $DIR/simple.rs:226:37 | LL | while let (&Either::One(_t),) = (&e.clone(),) { } | -- ^^^^^^^^^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | while let (&Either::One(ref _t),) = (&e.clone(),) { } + | +++ error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:264:11 + --> $DIR/simple.rs:229:11 | LL | match (&e.clone(),) { | ^^^^^^^^^^^^^ @@ -431,79 +622,123 @@ LL | (&Either::One(_t),) | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | (&Either::One(ref _t),) + | +++ error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:272:25 + --> $DIR/simple.rs:239:25 | LL | let (&mut X(_t),) = (&mut xm.clone(),); | -- ^^^^^^^^^^^^^^^^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let (&mut X(ref _t),) = (&mut xm.clone(),); + | +++ error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:274:38 + --> $DIR/simple.rs:242:38 | LL | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | -- ^^^^^^^^^^^^^^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | if let (&mut Either::One(ref _t),) = (&mut em.clone(),) { } + | +++ error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:276:41 + --> $DIR/simple.rs:245:41 | LL | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | -- ^^^^^^^^^^^^^^^^^^ | | | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | while let (&mut Either::One(ref _t),) = (&mut em.clone(),) { } + | +++ error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:278:11 + --> $DIR/simple.rs:248:11 | LL | match (&mut em.clone(),) { | ^^^^^^^^^^^^^^^^^^ LL | LL | (&mut Either::One(_t),) => (), | -- data moved here +LL | LL | (&mut Either::Two(_t),) => (), | -- ...and here | = note: move occurs because these variables have types that don't implement the `Copy` trait +help: consider borrowing the pattern binding + | +LL | (&mut Either::One(ref _t),) => (), + | +++ +help: consider borrowing the pattern binding + | +LL | (&mut Either::Two(ref _t),) => (), + | +++ error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:288:18 + --> $DIR/simple.rs:261:18 | LL | let &X(_t) = &x; - | ------ ^^ - | | | - | | data moved here - | | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - | help: consider removing the `&`: `X(_t)` + | -- ^^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let &X(_t) = &x; +LL + let X(_t) = &x; + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:292:31 + --> $DIR/simple.rs:264:31 | LL | if let &Either::One(_t) = &e { } - | ---------------- ^^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - if let &Either::One(_t) = &e { } +LL + if let Either::One(_t) = &e { } + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:296:34 + --> $DIR/simple.rs:267:34 | LL | while let &Either::One(_t) = &e { } - | ---------------- ^^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - while let &Either::One(_t) = &e { } +LL + while let Either::One(_t) = &e { } + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:300:11 + --> $DIR/simple.rs:270:11 | LL | match &e { | ^^ @@ -514,72 +749,95 @@ LL | &Either::One(_t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider removing the `&` +help: consider removing the borrow | -LL ~ Either::One(_t) -LL + -LL + -LL ~ | &Either::Two(_t) => (), +LL - &Either::One(_t) +LL + Either::One(_t) | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:308:11 + --> $DIR/simple.rs:277:11 | LL | match &e { | ^^ LL | LL | &Either::One(_t) => (), - | ---------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:315:11 + --> $DIR/simple.rs:283:11 | LL | match &e { | ^^ LL | LL | &Either::One(_t) => (), - | ---------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:323:22 + --> $DIR/simple.rs:290:22 | LL | let &mut X(_t) = &mut xm; - | ---------- ^^^^^^^ - | | | - | | data moved here - | | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `X(_t)` + | -- ^^^^^^^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - let &mut X(_t) = &mut xm; +LL + let X(_t) = &mut xm; + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:327:35 + --> $DIR/simple.rs:293:35 | LL | if let &mut Either::One(_t) = &mut em { } - | -------------------- ^^^^^^^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- ^^^^^^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - if let &mut Either::One(_t) = &mut em { } +LL + if let Either::One(_t) = &mut em { } + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:331:38 + --> $DIR/simple.rs:296:38 | LL | while let &mut Either::One(_t) = &mut em { } - | -------------------- ^^^^^^^ - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- ^^^^^^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - while let &mut Either::One(_t) = &mut em { } +LL + while let Either::One(_t) = &mut em { } + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:335:11 + --> $DIR/simple.rs:299:11 | LL | match &mut em { | ^^^^^^^ @@ -590,91 +848,138 @@ LL | &mut Either::One(_t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | -help: consider removing the `&mut` +help: consider removing the mutable borrow | -LL ~ Either::One(_t) -LL + -LL + -LL ~ | &mut Either::Two(_t) => (), +LL - &mut Either::One(_t) +LL + Either::One(_t) | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:343:11 + --> $DIR/simple.rs:306:11 | LL | match &mut em { | ^^^^^^^ LL | LL | &mut Either::One(_t) => (), - | -------------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:350:11 + --> $DIR/simple.rs:312:11 | LL | match &mut em { | ^^^^^^^ LL | LL | &mut Either::One(_t) => (), - | -------------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:357:11 + --> $DIR/simple.rs:318:11 | LL | match &mut em { | ^^^^^^^ LL | LL | &mut Either::One(_t) => (), - | -------------------- - | | | - | | data moved here - | | move occurs because `_t` has type `X`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `Either::One(_t)` + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - &mut Either::One(_t) => (), +LL + Either::One(_t) => (), + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:202:11 + --> $DIR/simple.rs:174:11 | LL | fn f1(&X(_t): &X) { } | ^^^--^ - | | | - | | data moved here - | | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - | help: consider removing the `&`: `X(_t)` + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - fn f1(&X(_t): &X) { } +LL + fn f1(X(_t): &X) { } + | error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:249:11 + --> $DIR/simple.rs:212:11 | LL | fn f2(&mut X(_t): &mut X) { } | ^^^^^^^--^ - | | | - | | data moved here - | | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait - | help: consider removing the `&mut`: `X(_t)` + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider removing the mutable borrow + | +LL - fn f2(&mut X(_t): &mut X) { } +LL + fn f2(X(_t): &mut X) { } + | error[E0507]: cannot move out of a shared reference - --> $DIR/simple.rs:269:11 + --> $DIR/simple.rs:235:11 | LL | fn f3((&X(_t),): (&X,)) { } | ^^^^--^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | fn f3((&X(ref _t),): (&X,)) { } + | +++ error[E0507]: cannot move out of a mutable reference - --> $DIR/simple.rs:283:11 + --> $DIR/simple.rs:255:11 | LL | fn f4((&mut X(_t),): (&mut X,)) { } | ^^^^^^^^--^^^ | | | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | fn f4((&mut X(ref _t),): (&mut X,)) { } + | +++ + +error[E0507]: cannot move out of `a.a` as enum variant `Some` which is behind a shared reference + --> $DIR/simple.rs:331:20 + | +LL | let Some(_s) = a.a else { + | -- ^^^ + | | + | data moved here + | move occurs because `_s` has type `String`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let Some(ref _s) = a.a else { + | +++ -error: aborting due to 60 previous errors +error: aborting due to 61 previous errors For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/suggestions/option-content-move-from-tuple-match.stderr b/src/test/ui/suggestions/option-content-move-from-tuple-match.stderr index debb8cabaea02..97d05d9dcffaf 100644 --- a/src/test/ui/suggestions/option-content-move-from-tuple-match.stderr +++ b/src/test/ui/suggestions/option-content-move-from-tuple-match.stderr @@ -9,6 +9,11 @@ LL | (None, &c) => &c.unwrap(), | | | data moved here | move occurs because `c` has type `Option`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | (None, &ref c) => &c.unwrap(), + | +++ error: aborting due to previous error diff --git a/src/test/ui/union/union-borrow-move-parent-sibling.mirunsafeck.stderr b/src/test/ui/union/union-borrow-move-parent-sibling.mirunsafeck.stderr index ca02de4c61bb8..7f931b49a58f5 100644 --- a/src/test/ui/union/union-borrow-move-parent-sibling.mirunsafeck.stderr +++ b/src/test/ui/union/union-borrow-move-parent-sibling.mirunsafeck.stderr @@ -14,10 +14,12 @@ error[E0507]: cannot move out of dereference of `ManuallyDrop<((MockVec, Moc --> $DIR/union-borrow-move-parent-sibling.rs:62:13 | LL | let a = u.x.0; - | ^^^^^ - | | - | move occurs because value has type `(MockVec, MockVec)`, which does not implement the `Copy` trait - | help: consider borrowing here: `&u.x.0` + | ^^^^^ move occurs because value has type `(MockVec, MockVec)`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let a = &u.x.0; + | + error[E0382]: use of moved value: `u` --> $DIR/union-borrow-move-parent-sibling.rs:64:13 @@ -46,10 +48,12 @@ error[E0507]: cannot move out of dereference of `ManuallyDrop<((MockVec, Moc --> $DIR/union-borrow-move-parent-sibling.rs:76:13 | LL | let a = (u.x.0).0; - | ^^^^^^^^^ - | | - | move occurs because value has type `MockVec`, which does not implement the `Copy` trait - | help: consider borrowing here: `&(u.x.0).0` + | ^^^^^^^^^ move occurs because value has type `MockVec`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let a = &(u.x.0).0; + | + error[E0382]: use of moved value: `u` --> $DIR/union-borrow-move-parent-sibling.rs:78:13 diff --git a/src/test/ui/union/union-borrow-move-parent-sibling.thirunsafeck.stderr b/src/test/ui/union/union-borrow-move-parent-sibling.thirunsafeck.stderr index ca02de4c61bb8..7f931b49a58f5 100644 --- a/src/test/ui/union/union-borrow-move-parent-sibling.thirunsafeck.stderr +++ b/src/test/ui/union/union-borrow-move-parent-sibling.thirunsafeck.stderr @@ -14,10 +14,12 @@ error[E0507]: cannot move out of dereference of `ManuallyDrop<((MockVec, Moc --> $DIR/union-borrow-move-parent-sibling.rs:62:13 | LL | let a = u.x.0; - | ^^^^^ - | | - | move occurs because value has type `(MockVec, MockVec)`, which does not implement the `Copy` trait - | help: consider borrowing here: `&u.x.0` + | ^^^^^ move occurs because value has type `(MockVec, MockVec)`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let a = &u.x.0; + | + error[E0382]: use of moved value: `u` --> $DIR/union-borrow-move-parent-sibling.rs:64:13 @@ -46,10 +48,12 @@ error[E0507]: cannot move out of dereference of `ManuallyDrop<((MockVec, Moc --> $DIR/union-borrow-move-parent-sibling.rs:76:13 | LL | let a = (u.x.0).0; - | ^^^^^^^^^ - | | - | move occurs because value has type `MockVec`, which does not implement the `Copy` trait - | help: consider borrowing here: `&(u.x.0).0` + | ^^^^^^^^^ move occurs because value has type `MockVec`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | let a = &(u.x.0).0; + | + error[E0382]: use of moved value: `u` --> $DIR/union-borrow-move-parent-sibling.rs:78:13