From 763392cb8ca09e0f332c1ab9b75376afbdafc18f Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Wed, 16 Jan 2019 23:05:50 +0900 Subject: [PATCH 01/14] Fix memory leak in P::filter_map --- src/libsyntax/ptr.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index bb1744e2df169..3effe53cd29b0 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -101,6 +101,7 @@ impl P { // Recreate self from the raw pointer. Some(P { ptr: Box::from_raw(p) }) } else { + drop(Box::from_raw(p)); None } } From 13dc584db39e5f36755b7b051a908277f5e5505f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 18 Jan 2019 12:35:14 +0100 Subject: [PATCH 02/14] Merge visitors in AST validation --- src/librustc_passes/ast_validation.rs | 255 +++++++++++--------------- 1 file changed, 111 insertions(+), 144 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 3d0e46d998622..20f63b142997c 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -20,9 +20,79 @@ use errors::Applicability; struct AstValidator<'a> { session: &'a Session, + + // Used to ban nested `impl Trait`, e.g., `impl Into`. + // Nested `impl Trait` _is_ allowed in associated type position, + // e.g `impl Iterator` + outer_impl_trait: Option, + + // Used to ban `impl Trait` in path projections like `::Item` + // or `Foo::Bar` + is_impl_trait_banned: bool, } impl<'a> AstValidator<'a> { + fn with_banned_impl_trait(&mut self, f: F) + where F: FnOnce(&mut Self) + { + let old_is_impl_trait_banned = self.is_impl_trait_banned; + self.is_impl_trait_banned = true; + f(self); + self.is_impl_trait_banned = old_is_impl_trait_banned; + } + + fn with_impl_trait(&mut self, outer_impl_trait: Option, f: F) + where F: FnOnce(&mut Self) + { + let old_outer_impl_trait = self.outer_impl_trait; + self.outer_impl_trait = outer_impl_trait; + f(self); + self.outer_impl_trait = old_outer_impl_trait; + } + + // Mirrors visit::walk_ty, but tracks relevant state + fn walk_ty(&mut self, t: &'a Ty) { + match t.node { + TyKind::ImplTrait(..) => { + self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t)) + } + TyKind::Path(ref qself, ref path) => { + // We allow these: + // - `Option` + // - `option::Option` + // - `option::Option::Foo + // + // But not these: + // - `::Foo` + // - `option::Option::Foo`. + // + // To implement this, we disallow `impl Trait` from `qself` + // (for cases like `::Foo>`) + // but we allow `impl Trait` in `GenericArgs` + // iff there are no more PathSegments. + if let Some(ref qself) = *qself { + // `impl Trait` in `qself` is always illegal + self.with_banned_impl_trait(|this| this.visit_ty(&qself.ty)); + } + + // Note that there should be a call to visit_path here, + // so if any logic is added to process `Path`s a call to it should be + // added both in visit_path and here. This code mirrors visit::walk_path. + for (i, segment) in path.segments.iter().enumerate() { + // Allow `impl Trait` iff we're on the final path segment + if i == path.segments.len() - 1 { + self.visit_path_segment(path.span, segment); + } else { + self.with_banned_impl_trait(|this| { + this.visit_path_segment(path.span, segment) + }); + } + } + } + _ => visit::walk_ty(self, t), + } + } + fn err_handler(&self) -> &errors::Handler { &self.session.diagnostic() } @@ -267,6 +337,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.no_questions_in_bounds(bounds, "trait object types", false); } TyKind::ImplTrait(_, ref bounds) => { + if self.is_impl_trait_banned { + struct_span_err!(self.session, ty.span, E0667, + "`impl Trait` is not allowed in path parameters").emit(); + } + + if let Some(outer_impl_trait) = self.outer_impl_trait { + struct_span_err!(self.session, ty.span, E0666, + "nested `impl Trait` is not allowed") + .span_label(outer_impl_trait, "outer `impl Trait`") + .span_label(ty.span, "nested `impl Trait` here") + .emit(); + + } if !bounds.iter() .any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) { self.err_handler().span_err(ty.span, "at least one trait must be specified"); @@ -275,7 +358,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { _ => {} } - visit::walk_ty(self, ty) + self.walk_ty(ty) } fn visit_label(&mut self, label: &'a Label) { @@ -414,6 +497,28 @@ impl<'a> Visitor<'a> for AstValidator<'a> { visit::walk_foreign_item(self, fi) } + // Mirrors visit::walk_generic_args, but tracks relevant state + fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) { + match *generic_args { + GenericArgs::AngleBracketed(ref data) => { + walk_list!(self, visit_generic_arg, &data.args); + // Type bindings such as `Item=impl Debug` in `Iterator` + // are allowed to contain nested `impl Trait`. + self.with_impl_trait(None, |this| { + walk_list!(this, visit_assoc_type_binding, &data.bindings); + }); + } + GenericArgs::Parenthesized(ref data) => { + walk_list!(self, visit_ty, &data.inputs); + if let Some(ref type_) = data.output { + // `-> Foo` syntax is essentially an associated type binding, + // so it is also allowed to contain nested `impl Trait`. + self.with_impl_trait(None, |this| visit::walk_ty(this, type_)); + } + } + } + } + fn visit_generics(&mut self, generics: &'a Generics) { let mut seen_non_lifetime_param = false; let mut seen_default = None; @@ -490,148 +595,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } } -// Bans nested `impl Trait`, e.g., `impl Into`. -// Nested `impl Trait` _is_ allowed in associated type position, -// e.g `impl Iterator` -struct NestedImplTraitVisitor<'a> { - session: &'a Session, - outer_impl_trait: Option, -} - -impl<'a> NestedImplTraitVisitor<'a> { - fn with_impl_trait(&mut self, outer_impl_trait: Option, f: F) - where F: FnOnce(&mut NestedImplTraitVisitor<'a>) - { - let old_outer_impl_trait = self.outer_impl_trait; - self.outer_impl_trait = outer_impl_trait; - f(self); - self.outer_impl_trait = old_outer_impl_trait; - } -} - - -impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> { - fn visit_ty(&mut self, t: &'a Ty) { - if let TyKind::ImplTrait(..) = t.node { - if let Some(outer_impl_trait) = self.outer_impl_trait { - struct_span_err!(self.session, t.span, E0666, - "nested `impl Trait` is not allowed") - .span_label(outer_impl_trait, "outer `impl Trait`") - .span_label(t.span, "nested `impl Trait` here") - .emit(); - - } - self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t)); - } else { - visit::walk_ty(self, t); - } - } - fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) { - match *generic_args { - GenericArgs::AngleBracketed(ref data) => { - for arg in &data.args { - self.visit_generic_arg(arg) - } - for type_binding in &data.bindings { - // Type bindings such as `Item=impl Debug` in `Iterator` - // are allowed to contain nested `impl Trait`. - self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty)); - } - } - GenericArgs::Parenthesized(ref data) => { - for type_ in &data.inputs { - self.visit_ty(type_); - } - if let Some(ref type_) = data.output { - // `-> Foo` syntax is essentially an associated type binding, - // so it is also allowed to contain nested `impl Trait`. - self.with_impl_trait(None, |this| visit::walk_ty(this, type_)); - } - } - } - } - - fn visit_mac(&mut self, _mac: &Spanned) { - // covered in AstValidator - } -} - -// Bans `impl Trait` in path projections like `::Item` or `Foo::Bar`. -struct ImplTraitProjectionVisitor<'a> { - session: &'a Session, - is_banned: bool, -} - -impl<'a> ImplTraitProjectionVisitor<'a> { - fn with_ban(&mut self, f: F) - where F: FnOnce(&mut ImplTraitProjectionVisitor<'a>) - { - let old_is_banned = self.is_banned; - self.is_banned = true; - f(self); - self.is_banned = old_is_banned; - } -} - -impl<'a> Visitor<'a> for ImplTraitProjectionVisitor<'a> { - fn visit_ty(&mut self, t: &'a Ty) { - match t.node { - TyKind::ImplTrait(..) => { - if self.is_banned { - struct_span_err!(self.session, t.span, E0667, - "`impl Trait` is not allowed in path parameters").emit(); - } - } - TyKind::Path(ref qself, ref path) => { - // We allow these: - // - `Option` - // - `option::Option` - // - `option::Option::Foo - // - // But not these: - // - `::Foo` - // - `option::Option::Foo`. - // - // To implement this, we disallow `impl Trait` from `qself` - // (for cases like `::Foo>`) - // but we allow `impl Trait` in `GenericArgs` - // iff there are no more PathSegments. - if let Some(ref qself) = *qself { - // `impl Trait` in `qself` is always illegal - self.with_ban(|this| this.visit_ty(&qself.ty)); - } - - for (i, segment) in path.segments.iter().enumerate() { - // Allow `impl Trait` iff we're on the final path segment - if i == path.segments.len() - 1 { - visit::walk_path_segment(self, path.span, segment); - } else { - self.with_ban(|this| - visit::walk_path_segment(this, path.span, segment)); - } - } - } - _ => visit::walk_ty(self, t), - } - } - - fn visit_mac(&mut self, _mac: &Spanned) { - // covered in AstValidator - } -} - pub fn check_crate(session: &Session, krate: &Crate) { - visit::walk_crate( - &mut NestedImplTraitVisitor { - session, - outer_impl_trait: None, - }, krate); - - visit::walk_crate( - &mut ImplTraitProjectionVisitor { - session, - is_banned: false, - }, krate); - - visit::walk_crate(&mut AstValidator { session }, krate) + visit::walk_crate(&mut AstValidator { + session, + outer_impl_trait: None, + is_impl_trait_banned: false, + }, krate) } From eb5a25314df50f4d1b2b962af6ab8ae8f65abeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 2 Jan 2019 16:43:08 -0800 Subject: [PATCH 03/14] When using value after move, point at span of local When trying to use a value after move, instead of using a note, point at the local declaration that has a type that doesn't implement `Copy` trait. --- .../borrow_check/error_reporting.rs | 34 +++++++++++++------ src/test/ui/borrowck/borrowck-asm.mir.stderr | 10 +++--- .../borrowck/borrowck-drop-from-guard.stderr | 5 +-- .../ui/borrowck/borrowck-issue-48962.stderr | 8 ++--- ...k-move-moved-value-into-closure.mir.stderr | 5 +-- src/test/ui/borrowck/borrowck-reinit.stderr | 5 +-- src/test/ui/borrowck/issue-41962.stderr | 5 ++- ...-mutation-of-moved-out-with-mut.nll.stderr | 12 +++---- ...499-field-mutation-of-moved-out.nll.stderr | 12 +++---- ...e-27282-move-match-input-into-guard.stderr | 5 +-- src/test/ui/issues/issue-29723.stderr | 5 +-- .../ui/moves/moves-based-on-type-tuple.stderr | 4 +-- src/test/ui/nll/closure-access-spans.stderr | 16 ++++----- src/test/ui/nll/closure-move-spans.stderr | 12 +++---- src/test/ui/nll/closures-in-loops.stderr | 5 +-- ...1232-partial-init-and-erroneous-use.stderr | 8 ++--- .../issue-21232-partial-init-and-use.stderr | 34 ++++++++++--------- src/test/ui/nll/issue-51512.stderr | 4 +-- src/test/ui/nll/issue-52669.stderr | 5 +-- .../try-block/try-block-bad-lifetime.stderr | 5 +-- .../try-block-maybe-bad-lifetime.stderr | 5 +-- 21 files changed, 116 insertions(+), 88 deletions(-) diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 233db12b03001..cbcf8c90fee41 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -198,19 +198,31 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let place = &self.move_data.move_paths[mpi].place; let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx); - let note_msg = match self.describe_place_with_options( - place, - IncludingDowncast(true), - ) { - Some(name) => format!("`{}`", name), + let opt_name = self.describe_place_with_options(place, IncludingDowncast(true)); + let note_msg = match opt_name { + Some(ref name) => format!("`{}`", name), None => "value".to_owned(), }; - - err.note(&format!( - "move occurs because {} has type `{}`, \ - which does not implement the `Copy` trait", - note_msg, ty - )); + let mut note = true; + for decl in &self.mir.local_decls { + if decl.ty == ty && decl.name.map(|x| x.to_string()) == opt_name { + err.span_label( + decl.source_info.span, + format!( + "move occurs because {} has type `{}`, \ + which does not implement the `Copy` trait", + note_msg, ty, + )); + note = false; + } + } + if note { + err.note(&format!( + "move occurs because {} has type `{}`, \ + which does not implement the `Copy` trait", + note_msg, ty + )); + } } if let Some((_, mut old_err)) = self.move_error_reported diff --git a/src/test/ui/borrowck/borrowck-asm.mir.stderr b/src/test/ui/borrowck/borrowck-asm.mir.stderr index 9c47845a52830..86e4832b3873c 100644 --- a/src/test/ui/borrowck/borrowck-asm.mir.stderr +++ b/src/test/ui/borrowck/borrowck-asm.mir.stderr @@ -1,13 +1,14 @@ error[E0382]: use of moved value: `x` --> $DIR/borrowck-asm.rs:27:17 | +LL | let x = &mut 0isize; + | - move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait +LL | unsafe { LL | asm!("nop" : : "r"(x)); | - value moved here LL | } LL | let z = x; //[ast]~ ERROR use of moved value: `x` | ^ value used here after move - | - = note: move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait error[E0503]: cannot use `x` because it was mutably borrowed --> $DIR/borrowck-asm.rs:35:32 @@ -66,12 +67,13 @@ LL | let z = y; error[E0382]: use of moved value: `x` --> $DIR/borrowck-asm.rs:86:40 | +LL | let x = &mut 2; + | - move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait +LL | unsafe { LL | asm!("nop" : : "r"(x), "r"(x) ); //[ast]~ ERROR use of moved value | - ^ value used here after move | | | value moved here - | - = note: move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait error: aborting due to 7 previous errors diff --git a/src/test/ui/borrowck/borrowck-drop-from-guard.stderr b/src/test/ui/borrowck/borrowck-drop-from-guard.stderr index d395b7734f9b7..07b597f480feb 100644 --- a/src/test/ui/borrowck/borrowck-drop-from-guard.stderr +++ b/src/test/ui/borrowck/borrowck-drop-from-guard.stderr @@ -1,13 +1,14 @@ error[E0382]: use of moved value: `my_str` --> $DIR/borrowck-drop-from-guard.rs:11:23 | +LL | let my_str = "hello".to_owned(); + | ------ move occurs because `my_str` has type `std::string::String`, which does not implement the `Copy` trait +LL | match Some(42) { LL | Some(_) if { drop(my_str); false } => {} | ------ value moved here LL | Some(_) => {} LL | None => { foo(my_str); } //~ ERROR [E0382] | ^^^^^^ value used here after move - | - = note: move occurs because `my_str` has type `std::string::String`, which does not implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-issue-48962.stderr b/src/test/ui/borrowck/borrowck-issue-48962.stderr index 9d53d82265eca..de4894d5b526b 100644 --- a/src/test/ui/borrowck/borrowck-issue-48962.stderr +++ b/src/test/ui/borrowck/borrowck-issue-48962.stderr @@ -1,22 +1,22 @@ error[E0382]: use of moved value: `src` --> $DIR/borrowck-issue-48962.rs:16:5 | +LL | let mut src = &mut node; + | ------- move occurs because `src` has type `&mut Node`, which does not implement the `Copy` trait LL | {src}; | --- value moved here LL | src.next = None; //~ ERROR use of moved value: `src` [E0382] | ^^^^^^^^ value used here after move - | - = note: move occurs because `src` has type `&mut Node`, which does not implement the `Copy` trait error[E0382]: use of moved value: `src` --> $DIR/borrowck-issue-48962.rs:22:5 | +LL | let mut src = &mut (22, 44); + | ------- move occurs because `src` has type `&mut (i32, i32)`, which does not implement the `Copy` trait LL | {src}; | --- value moved here LL | src.0 = 66; //~ ERROR use of moved value: `src` [E0382] | ^^^^^^^^^^ value used here after move - | - = note: move occurs because `src` has type `&mut (i32, i32)`, which does not implement the `Copy` trait error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/borrowck-move-moved-value-into-closure.mir.stderr b/src/test/ui/borrowck/borrowck-move-moved-value-into-closure.mir.stderr index 24b9b4338a58c..0789926563ce7 100644 --- a/src/test/ui/borrowck/borrowck-move-moved-value-into-closure.mir.stderr +++ b/src/test/ui/borrowck/borrowck-move-moved-value-into-closure.mir.stderr @@ -1,6 +1,9 @@ error[E0382]: use of moved value: `t` --> $DIR/borrowck-move-moved-value-into-closure.rs:14:12 | +LL | let t: Box<_> = box 3; + | - move occurs because `t` has type `std::boxed::Box`, which does not implement the `Copy` trait +LL | LL | call_f(move|| { *t + 1 }); | ------ - variable moved due to use in closure | | @@ -9,8 +12,6 @@ LL | call_f(move|| { *t + 1 }); //[ast]~ ERROR capture of moved value | ^^^^^^ - use occurs due to use in closure | | | value used here after move - | - = note: move occurs because `t` has type `std::boxed::Box`, which does not implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-reinit.stderr b/src/test/ui/borrowck/borrowck-reinit.stderr index 918452726a06c..96f3981ac2fe6 100644 --- a/src/test/ui/borrowck/borrowck-reinit.stderr +++ b/src/test/ui/borrowck/borrowck-reinit.stderr @@ -11,12 +11,13 @@ LL | let _ = (1,x); //~ ERROR use of moved value: `x` (Ast) error[E0382]: use of moved value: `x` (Mir) --> $DIR/borrowck-reinit.rs:8:16 | +LL | let mut x = Box::new(0); + | ----- move occurs because `x` has type `std::boxed::Box`, which does not implement the `Copy` trait +... LL | drop(x); | - value moved here LL | let _ = (1,x); //~ ERROR use of moved value: `x` (Ast) | ^ value used here after move - | - = note: move occurs because `x` has type `std::boxed::Box`, which does not implement the `Copy` trait error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr index fd4d318b5ddf1..3c0071f6b3745 100644 --- a/src/test/ui/borrowck/issue-41962.stderr +++ b/src/test/ui/borrowck/issue-41962.stderr @@ -19,10 +19,13 @@ LL | if let Some(thing) = maybe { error[E0382]: use of moved value (Mir) --> $DIR/issue-41962.rs:7:21 | +LL | let maybe = Some(vec![true, true]); + | ---------------- move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait +... LL | if let Some(thing) = maybe { | ^^^^^ value moved here, in previous iteration of loop | - = note: move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out-with-mut.nll.stderr b/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out-with-mut.nll.stderr index 7861087ad02eb..42aa038170238 100644 --- a/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out-with-mut.nll.stderr +++ b/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out-with-mut.nll.stderr @@ -1,32 +1,32 @@ error[E0382]: assign to part of moved value: `t` --> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:23:9 | +LL | let mut t: Tuple = (S(0), 0); + | ----- move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait LL | drop(t); | - value moved here LL | t.0 = S(1); | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait error[E0382]: assign to part of moved value: `u` --> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:34:9 | +LL | let mut u: Tpair = Tpair(S(0), 0); + | ----- move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait LL | drop(u); | - value moved here LL | u.0 = S(1); | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait error[E0382]: assign to part of moved value: `v` --> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:45:9 | +LL | let mut v: Spair = Spair { x: S(0), y: 0 }; + | ----- move occurs because `v` has type `Spair`, which does not implement the `Copy` trait LL | drop(v); | - value moved here LL | v.x = S(1); | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out.nll.stderr b/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out.nll.stderr index d35d0058027d4..1184907f307cb 100644 --- a/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out.nll.stderr +++ b/src/test/ui/borrowck/issue-54499-field-mutation-of-moved-out.nll.stderr @@ -10,12 +10,12 @@ LL | t.0 = S(1); error[E0382]: assign to part of moved value: `t` --> $DIR/issue-54499-field-mutation-of-moved-out.rs:23:9 | +LL | let t: Tuple = (S(0), 0); + | - move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait LL | drop(t); | - value moved here LL | t.0 = S(1); | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait error[E0594]: cannot assign to `t.1`, as `t` is not declared as mutable --> $DIR/issue-54499-field-mutation-of-moved-out.rs:27:9 @@ -38,12 +38,12 @@ LL | u.0 = S(1); error[E0382]: assign to part of moved value: `u` --> $DIR/issue-54499-field-mutation-of-moved-out.rs:38:9 | +LL | let u: Tpair = Tpair(S(0), 0); + | - move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait LL | drop(u); | - value moved here LL | u.0 = S(1); | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait error[E0594]: cannot assign to `u.1`, as `u` is not declared as mutable --> $DIR/issue-54499-field-mutation-of-moved-out.rs:42:9 @@ -66,12 +66,12 @@ LL | v.x = S(1); error[E0382]: assign to part of moved value: `v` --> $DIR/issue-54499-field-mutation-of-moved-out.rs:53:9 | +LL | let v: Spair = Spair { x: S(0), y: 0 }; + | - move occurs because `v` has type `Spair`, which does not implement the `Copy` trait LL | drop(v); | - value moved here LL | v.x = S(1); | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait error[E0594]: cannot assign to `v.y`, as `v` is not declared as mutable --> $DIR/issue-54499-field-mutation-of-moved-out.rs:57:9 diff --git a/src/test/ui/issues/issue-27282-move-match-input-into-guard.stderr b/src/test/ui/issues/issue-27282-move-match-input-into-guard.stderr index 8ea2bdb693d31..6993419326c8e 100644 --- a/src/test/ui/issues/issue-27282-move-match-input-into-guard.stderr +++ b/src/test/ui/issues/issue-27282-move-match-input-into-guard.stderr @@ -1,6 +1,9 @@ error[E0382]: use of moved value: `b` --> $DIR/issue-27282-move-match-input-into-guard.rs:18:14 | +LL | let b = &mut true; + | - move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait +... LL | _ if { (|| { let bar = b; *bar = false; })(); | -- - variable moved due to use in closure | | @@ -8,8 +11,6 @@ LL | _ if { (|| { let bar = b; *bar = false; })(); LL | false } => { }, LL | &mut true => { println!("You might think we should get here"); }, | ^^^^ value used here after move - | - = note: move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/issues/issue-29723.stderr b/src/test/ui/issues/issue-29723.stderr index de858aec881f7..7928af5d5a5cd 100644 --- a/src/test/ui/issues/issue-29723.stderr +++ b/src/test/ui/issues/issue-29723.stderr @@ -1,13 +1,14 @@ error[E0382]: use of moved value: `s` --> $DIR/issue-29723.rs:12:13 | +LL | let s = String::new(); + | - move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait +LL | let _s = match 0 { LL | 0 if { drop(s); false } => String::from("oops"), | - value moved here ... LL | s | ^ value used here after move - | - = note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/moves/moves-based-on-type-tuple.stderr b/src/test/ui/moves/moves-based-on-type-tuple.stderr index 2d2c0a15a002a..c49dbdab40210 100644 --- a/src/test/ui/moves/moves-based-on-type-tuple.stderr +++ b/src/test/ui/moves/moves-based-on-type-tuple.stderr @@ -11,12 +11,12 @@ LL | box (x, x) error[E0382]: use of moved value: `x` (Mir) --> $DIR/moves-based-on-type-tuple.rs:6:13 | +LL | fn dup(x: Box) -> Box<(Box,Box)> { + | - move occurs because `x` has type `std::boxed::Box`, which does not implement the `Copy` trait LL | box (x, x) | - ^ value used here after move | | | value moved here - | - = note: move occurs because `x` has type `std::boxed::Box`, which does not implement the `Copy` trait error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/closure-access-spans.stderr b/src/test/ui/nll/closure-access-spans.stderr index efe4c15240d20..3ca0aefb592e0 100644 --- a/src/test/ui/nll/closure-access-spans.stderr +++ b/src/test/ui/nll/closure-access-spans.stderr @@ -59,50 +59,50 @@ LL | r.use_ref(); error[E0382]: borrow of moved value: `x` --> $DIR/closure-access-spans.rs:37:5 | +LL | fn closure_imm_capture_moved(mut x: String) { + | ----- move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait LL | let r = x; | - value moved here LL | || x.len(); //~ ERROR | ^^ - borrow occurs due to use in closure | | | value borrowed here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error[E0382]: borrow of moved value: `x` --> $DIR/closure-access-spans.rs:42:5 | +LL | fn closure_mut_capture_moved(mut x: String) { + | ----- move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait LL | let r = x; | - value moved here LL | || x = String::new(); //~ ERROR | ^^ - borrow occurs due to use in closure | | | value borrowed here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error[E0382]: borrow of moved value: `x` --> $DIR/closure-access-spans.rs:47:5 | +LL | fn closure_unique_capture_moved(x: &mut String) { + | - move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait LL | let r = x; | - value moved here LL | || *x = String::new(); //~ ERROR | ^^ - borrow occurs due to use in closure | | | value borrowed here after move - | - = note: move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait error[E0382]: use of moved value: `x` --> $DIR/closure-access-spans.rs:52:5 | +LL | fn closure_move_capture_moved(x: &mut String) { + | - move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait LL | let r = x; | - value moved here LL | || x; //~ ERROR | ^^ - use occurs due to use in closure | | | value used here after move - | - = note: move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait error: aborting due to 9 previous errors diff --git a/src/test/ui/nll/closure-move-spans.stderr b/src/test/ui/nll/closure-move-spans.stderr index 3ae1912eb10bf..6750c4047601a 100644 --- a/src/test/ui/nll/closure-move-spans.stderr +++ b/src/test/ui/nll/closure-move-spans.stderr @@ -1,38 +1,38 @@ error[E0382]: use of moved value: `x` --> $DIR/closure-move-spans.rs:7:13 | +LL | fn move_after_move(x: String) { + | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait LL | || x; | -- - variable moved due to use in closure | | | value moved into closure here LL | let y = x; //~ ERROR | ^ value used here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error[E0382]: borrow of moved value: `x` --> $DIR/closure-move-spans.rs:12:13 | +LL | fn borrow_after_move(x: String) { + | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait LL | || x; | -- - variable moved due to use in closure | | | value moved into closure here LL | let y = &x; //~ ERROR | ^^ value borrowed here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error[E0382]: borrow of moved value: `x` --> $DIR/closure-move-spans.rs:17:13 | +LL | fn borrow_mut_after_move(mut x: String) { + | ----- move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait LL | || x; | -- - variable moved due to use in closure | | | value moved into closure here LL | let y = &mut x; //~ ERROR | ^^^^^^ value borrowed here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error: aborting due to 3 previous errors diff --git a/src/test/ui/nll/closures-in-loops.stderr b/src/test/ui/nll/closures-in-loops.stderr index 93e095d663cc2..6c9e1639f88dd 100644 --- a/src/test/ui/nll/closures-in-loops.stderr +++ b/src/test/ui/nll/closures-in-loops.stderr @@ -1,12 +1,13 @@ error[E0382]: use of moved value: `x` --> $DIR/closures-in-loops.rs:8:9 | +LL | fn repreated_move(x: String) { + | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait +LL | for i in 0..10 { LL | || x; //~ ERROR | ^^ - use occurs due to use in closure | | | value moved into closure here, in previous iteration of loop - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error[E0499]: cannot borrow `x` as mutable more than once at a time --> $DIR/closures-in-loops.rs:15:16 diff --git a/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr b/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr index e29c44760a987..54c728e3d2783 100644 --- a/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr +++ b/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr @@ -13,12 +13,12 @@ LL | d.x = 10; error[E0382]: assign of moved value: `d` --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:43:5 | +LL | let mut d = D { x: 0, s: S{ y: 0, z: 0 } }; + | ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait LL | drop(d); | - value moved here LL | d.x = 10; | ^^^^^^^^ value assigned here after move - | - = note: move occurs because `d` has type `D`, which does not implement the `Copy` trait error[E0381]: assign to part of possibly uninitialized variable: `d` --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:49:5 @@ -35,12 +35,12 @@ LL | d.s.y = 20; error[E0382]: assign to part of moved value: `d` --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:62:5 | +LL | let mut d = D { x: 0, s: S{ y: 0, z: 0} }; + | ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait LL | drop(d); | - value moved here LL | d.s.y = 20; | ^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `d` has type `D`, which does not implement the `Copy` trait error: aborting due to 6 previous errors diff --git a/src/test/ui/nll/issue-21232-partial-init-and-use.stderr b/src/test/ui/nll/issue-21232-partial-init-and-use.stderr index aec7f676fcebd..23da533252cb9 100644 --- a/src/test/ui/nll/issue-21232-partial-init-and-use.stderr +++ b/src/test/ui/nll/issue-21232-partial-init-and-use.stderr @@ -14,21 +14,21 @@ error[E0382]: assign to part of moved value: `s` --> $DIR/issue-21232-partial-init-and-use.rs:113:5 | LL | let mut s: S = S::new(); drop(s); - | - value moved here + | ----- - value moved here + | | + | move occurs because `s` has type `S>`, which does not implement the `Copy` trait LL | s.x = 10; s.y = Box::new(20); | ^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `s` has type `S>`, which does not implement the `Copy` trait error[E0382]: assign to part of moved value: `t` --> $DIR/issue-21232-partial-init-and-use.rs:120:5 | LL | let mut t: T = (0, Box::new(0)); drop(t); - | - value moved here + | ----- - value moved here + | | + | move occurs because `t` has type `(u32, std::boxed::Box)`, which does not implement the `Copy` trait LL | t.0 = 10; t.1 = Box::new(20); | ^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `t` has type `(u32, std::boxed::Box)`, which does not implement the `Copy` trait error[E0381]: assign to part of possibly uninitialized variable: `s` --> $DIR/issue-21232-partial-init-and-use.rs:127:5 @@ -46,21 +46,21 @@ error[E0382]: assign to part of moved value: `s` --> $DIR/issue-21232-partial-init-and-use.rs:141:5 | LL | let mut s: S = S::new(); drop(s); - | - value moved here + | ----- - value moved here + | | + | move occurs because `s` has type `S>`, which does not implement the `Copy` trait LL | s.x = 10; | ^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `s` has type `S>`, which does not implement the `Copy` trait error[E0382]: assign to part of moved value: `t` --> $DIR/issue-21232-partial-init-and-use.rs:148:5 | LL | let mut t: T = (0, Box::new(0)); drop(t); - | - value moved here + | ----- - value moved here + | | + | move occurs because `t` has type `(u32, std::boxed::Box)`, which does not implement the `Copy` trait LL | t.0 = 10; | ^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `t` has type `(u32, std::boxed::Box)`, which does not implement the `Copy` trait error[E0381]: assign to part of possibly uninitialized variable: `s` --> $DIR/issue-21232-partial-init-and-use.rs:155:5 @@ -153,22 +153,24 @@ LL | q.r.f.0 = 10; error[E0382]: assign to part of moved value: `c` --> $DIR/issue-21232-partial-init-and-use.rs:259:13 | +LL | let mut c = (1, "".to_owned()); + | ----- move occurs because `c` has type `(i32, std::string::String)`, which does not implement the `Copy` trait +LL | match c { LL | c2 => { | -- value moved here LL | c.0 = 2; //~ ERROR assign to part of moved value | ^^^^^^^ value partially assigned here after move - | - = note: move occurs because `c` has type `(i32, std::string::String)`, which does not implement the `Copy` trait error[E0382]: assign to part of moved value: `c` --> $DIR/issue-21232-partial-init-and-use.rs:269:13 | +LL | let mut c = (1, (1, "".to_owned())); + | ----- move occurs because `c` has type `(i32, (i32, std::string::String))`, which does not implement the `Copy` trait +LL | match c { LL | c2 => { | -- value moved here LL | (c.1).0 = 2; //~ ERROR assign to part of moved value | ^^^^^^^^^^^ value partially assigned here after move - | - = note: move occurs because `c` has type `(i32, (i32, std::string::String))`, which does not implement the `Copy` trait error[E0382]: assign to part of moved value: `c.1` --> $DIR/issue-21232-partial-init-and-use.rs:277:13 diff --git a/src/test/ui/nll/issue-51512.stderr b/src/test/ui/nll/issue-51512.stderr index 4717935e4b9f9..a84a236ca7772 100644 --- a/src/test/ui/nll/issue-51512.stderr +++ b/src/test/ui/nll/issue-51512.stderr @@ -1,12 +1,12 @@ error[E0382]: use of moved value: `range` --> $DIR/issue-51512.rs:7:13 | +LL | let range = 0..1; + | ----- move occurs because `range` has type `std::ops::Range`, which does not implement the `Copy` trait LL | let r = range; | ----- value moved here LL | let x = range.start; | ^^^^^^^^^^^ value used here after move - | - = note: move occurs because `range` has type `std::ops::Range`, which does not implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/nll/issue-52669.stderr b/src/test/ui/nll/issue-52669.stderr index e1fb76c6bc242..f51768c3859e4 100644 --- a/src/test/ui/nll/issue-52669.stderr +++ b/src/test/ui/nll/issue-52669.stderr @@ -1,12 +1,13 @@ error[E0382]: borrow of moved value: `a.b` --> $DIR/issue-52669.rs:15:5 | +LL | fn bar(mut a: A) -> B { + | ----- move occurs because `a` has type `A`, which does not implement the `Copy` trait +LL | a.b = B; LL | foo(a); | - value moved here LL | a.b.clone() | ^^^ value borrowed here after move - | - = note: move occurs because `a` has type `A`, which does not implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/try-block/try-block-bad-lifetime.stderr b/src/test/ui/try-block/try-block-bad-lifetime.stderr index 5bb0b099b977b..b1b925d694ff9 100644 --- a/src/test/ui/try-block/try-block-bad-lifetime.stderr +++ b/src/test/ui/try-block/try-block-bad-lifetime.stderr @@ -25,13 +25,14 @@ LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` error[E0382]: use of moved value: `k` --> $DIR/try-block-bad-lifetime.rs:31:26 | +LL | let k = &mut i; + | - move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait +LL | let mut j: Result<(), &mut i32> = try { LL | Err(k) ?; | - value moved here ... LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k` | ^ value used here after move - | - = note: move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait error[E0506]: cannot assign to `i` because it is borrowed --> $DIR/try-block-bad-lifetime.rs:32:9 diff --git a/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr b/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr index f96c7146d18d0..dafbde6a5150b 100644 --- a/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr +++ b/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr @@ -13,13 +13,14 @@ LL | do_something_with(x); error[E0382]: borrow of moved value: `x` --> $DIR/try-block-maybe-bad-lifetime.rs:28:24 | +LL | let x = String::new(); + | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait +... LL | ::std::mem::drop(x); | - value moved here LL | }; LL | println!("{}", x); //~ ERROR borrow of moved value: `x` | ^ value borrowed here after move - | - = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait error[E0506]: cannot assign to `i` because it is borrowed --> $DIR/try-block-maybe-bad-lifetime.rs:40:9 From 74a2cd07c3f2e5c3c7ea3a6ab2cfd65152ccbc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 2 Jan 2019 16:56:45 -0800 Subject: [PATCH 04/14] Add test for #34721 --- src/test/ui/issues/issue-34721.rs | 34 +++++++++++++++++++++++++++ src/test/ui/issues/issue-34721.stderr | 18 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/test/ui/issues/issue-34721.rs create mode 100644 src/test/ui/issues/issue-34721.stderr diff --git a/src/test/ui/issues/issue-34721.rs b/src/test/ui/issues/issue-34721.rs new file mode 100644 index 0000000000000..226c21446b1ed --- /dev/null +++ b/src/test/ui/issues/issue-34721.rs @@ -0,0 +1,34 @@ +#![feature(nll)] + +pub trait Foo { + fn zero(self) -> Self; +} + +impl Foo for u32 { + fn zero(self) -> u32 { 0u32 } +} + +pub mod bar { + pub use Foo; + pub fn bar(x: T) -> T { + x.zero() + } +} + +mod baz { + use bar; + use Foo; + pub fn baz(x: T) -> T { + if 0 == 1 { + bar::bar(x.zero()) + } else { + x.zero() + }; + x.zero() + //~^ ERROR use of moved value + } +} + +fn main() { + let _ = baz::baz(0u32); +} diff --git a/src/test/ui/issues/issue-34721.stderr b/src/test/ui/issues/issue-34721.stderr new file mode 100644 index 0000000000000..b4e274b1c7019 --- /dev/null +++ b/src/test/ui/issues/issue-34721.stderr @@ -0,0 +1,18 @@ +error[E0382]: use of moved value: `x` + --> $DIR/issue-34721.rs:27:9 + | +LL | pub fn baz(x: T) -> T { + | - move occurs because `x` has type `T`, which does not implement the `Copy` trait +LL | if 0 == 1 { +LL | bar::bar(x.zero()) + | - value moved here +LL | } else { +LL | x.zero() + | - value moved here +LL | }; +LL | x.zero() + | ^ value used here after move + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. From 97bc38ec5b059edb74567ca1b8717d4dbca96e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 4 Jan 2019 13:47:35 -0800 Subject: [PATCH 05/14] break eagerly from loop --- src/librustc_mir/borrow_check/error_reporting.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index cbcf8c90fee41..e3fc591bda847 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -214,6 +214,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { note_msg, ty, )); note = false; + break; } } if note { From 802d8c561c2308bea966e4f4b6b02a325a6491e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 6 Jan 2019 15:23:30 -0800 Subject: [PATCH 06/14] Point at type argument suggesting adding `Copy` constraint --- src/librustc_mir/borrow_check/error_reporting.rs | 11 +++++++++++ .../ui/borrowck/two-phase-nonrecv-autoref.nll.stderr | 2 ++ src/test/ui/issues/issue-34721.stderr | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index e3fc591bda847..d8a3cf9947024 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -217,6 +217,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { break; } } + if let ty::TyKind::Param(param_ty) = ty.sty { + let tcx = self.infcx.tcx; + let generics = tcx.generics_of(self.mir_def_id); + let def_id = generics.type_param(¶m_ty, tcx).def_id; + if let Some(sp) = tcx.hir().span_if_local(def_id) { + err.span_label( + sp, + "consider adding a `Copy` constraint to this type argument", + ); + } + } if note { err.note(&format!( "move occurs because {} has type `{}`, \ diff --git a/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr b/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr index 0e99e158eda02..d026f81b7aad6 100644 --- a/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr +++ b/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr @@ -10,6 +10,8 @@ LL | f(f(10)); error[E0382]: use of moved value: `*f` --> $DIR/two-phase-nonrecv-autoref.rs:69:11 | +LL | fn twice_ten_so i32>(f: Box) { + | - consider adding a `Copy` constraint to this type argument LL | f(f(10)); | - ^ value used here after move | | diff --git a/src/test/ui/issues/issue-34721.stderr b/src/test/ui/issues/issue-34721.stderr index b4e274b1c7019..2ed7b543e713c 100644 --- a/src/test/ui/issues/issue-34721.stderr +++ b/src/test/ui/issues/issue-34721.stderr @@ -2,7 +2,9 @@ error[E0382]: use of moved value: `x` --> $DIR/issue-34721.rs:27:9 | LL | pub fn baz(x: T) -> T { - | - move occurs because `x` has type `T`, which does not implement the `Copy` trait + | - - move occurs because `x` has type `T`, which does not implement the `Copy` trait + | | + | consider adding a `Copy` constraint to this type argument LL | if 0 == 1 { LL | bar::bar(x.zero()) | - value moved here From 09006d85e9486afd67ee0ba12f94b93dd0198246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 18 Jan 2019 15:47:25 -0800 Subject: [PATCH 07/14] review comments --- .../borrow_check/error_reporting.rs | 25 ++++++++----------- src/test/ui/borrowck/issue-41962.stderr | 5 +--- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index d8a3cf9947024..56b87feb82b2c 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -203,20 +203,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { Some(ref name) => format!("`{}`", name), None => "value".to_owned(), }; - let mut note = true; - for decl in &self.mir.local_decls { - if decl.ty == ty && decl.name.map(|x| x.to_string()) == opt_name { - err.span_label( - decl.source_info.span, - format!( - "move occurs because {} has type `{}`, \ - which does not implement the `Copy` trait", - note_msg, ty, - )); - note = false; - break; - } - } if let ty::TyKind::Param(param_ty) = ty.sty { let tcx = self.infcx.tcx; let generics = tcx.generics_of(self.mir_def_id); @@ -228,7 +214,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { ); } } - if note { + if let Place::Local(local) = place { + let decl = &self.mir.local_decls[*local]; + err.span_label( + decl.source_info.span, + format!( + "move occurs because {} has type `{}`, \ + which does not implement the `Copy` trait", + note_msg, ty, + )); + } else { err.note(&format!( "move occurs because {} has type `{}`, \ which does not implement the `Copy` trait", diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr index 3c0071f6b3745..fd4d318b5ddf1 100644 --- a/src/test/ui/borrowck/issue-41962.stderr +++ b/src/test/ui/borrowck/issue-41962.stderr @@ -19,13 +19,10 @@ LL | if let Some(thing) = maybe { error[E0382]: use of moved value (Mir) --> $DIR/issue-41962.rs:7:21 | -LL | let maybe = Some(vec![true, true]); - | ---------------- move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait -... LL | if let Some(thing) = maybe { | ^^^^^ value moved here, in previous iteration of loop | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait error: aborting due to 3 previous errors From a5d4aeddc8e2ecf1279f2138788777a29fedc3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 19 Jan 2019 04:29:26 +0100 Subject: [PATCH 08/14] Address some comments --- src/librustc_passes/ast_validation.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 20f63b142997c..d1a3d7c1f81e0 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -6,6 +6,7 @@ // This pass is supposed to perform only simple checks not requiring name resolution // or type checking or some other kind of complex analysis. +use std::mem; use rustc::lint; use rustc::session::Session; use syntax::ast::*; @@ -32,22 +33,16 @@ struct AstValidator<'a> { } impl<'a> AstValidator<'a> { - fn with_banned_impl_trait(&mut self, f: F) - where F: FnOnce(&mut Self) - { - let old_is_impl_trait_banned = self.is_impl_trait_banned; - self.is_impl_trait_banned = true; + fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) { + let old = mem::replace(&mut self.is_impl_trait_banned, true); f(self); - self.is_impl_trait_banned = old_is_impl_trait_banned; + self.is_impl_trait_banned = old; } - fn with_impl_trait(&mut self, outer_impl_trait: Option, f: F) - where F: FnOnce(&mut Self) - { - let old_outer_impl_trait = self.outer_impl_trait; - self.outer_impl_trait = outer_impl_trait; + fn with_impl_trait(&mut self, outer_impl_trait: Option, f: impl FnOnce(&mut Self)) { + let old = mem::replace(&mut self.outer_impl_trait, outer_impl_trait); f(self); - self.outer_impl_trait = old_outer_impl_trait; + self.outer_impl_trait = old; } // Mirrors visit::walk_ty, but tracks relevant state From 2200fd3c7caf19323e7bd4cf649e4ec53d1de369 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 12 Jan 2019 22:25:29 +0100 Subject: [PATCH 09/14] Add default rust logo for documentation --- src/librustdoc/html/layout.rs | 5 ++++- src/librustdoc/html/render.rs | 4 ++++ src/librustdoc/html/static/rust-logo.png | Bin 0 -> 5758 bytes src/librustdoc/html/static_files.rs | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/librustdoc/html/static/rust-logo.png diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 987cec6fbfa96..b7af28fbcc8ae 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -177,7 +177,10 @@ pub fn render( root_path = page.root_path, css_class = page.css_class, logo = if layout.logo.is_empty() { - String::new() + format!("\ + logo", + static_root_path=static_root_path, + suffix=page.resource_suffix) } else { format!("\ logo", diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 31e06cb1a045f..d050b706f1031 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -789,6 +789,10 @@ fn write_shared( themes.insert(theme.to_owned()); } + if (*cx.shared).layout.logo.is_empty() { + write(cx.dst.join(&format!("rust-logo{}.png", cx.shared.resource_suffix)), + static_files::RUST_LOGO)?; + } write(cx.dst.join(&format!("brush{}.svg", cx.shared.resource_suffix)), static_files::BRUSH_SVG)?; write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)), diff --git a/src/librustdoc/html/static/rust-logo.png b/src/librustdoc/html/static/rust-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..74b4bd695045ebc52c21af95301adc9311ca881c GIT binary patch literal 5758 zcmV-^7J=!BP)rlOar#xVHcKR}urj-85WU}*d52ce!FO;4x1(Dd{rLvS^kzaz+Qg+43&c`E^ z2A4h%FgKT)L-C6=0SiO%&803L%dQ&ad>le)iUzvAtx3hUp3qiqE4OmtpW{`0v8nBU z+vNFwgO#K7`BHl6Lk5HT&J zd0%5WX?GeMO2>h@YkR3UyYLB!%U`9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YVoA}U1iW+a>U$?V+eWExm$Z;|&sJ`_LI zHh#!j;e@l>PEio>Dyv13f$;E4ijXX~ z)1$sxGlVn+IcQ_M3rB`Bv`(txE_9%iVL;!|2KK@b;a7|Mf#0X5^HlrgJ6Q$xjGdYx zlzr^H@e-ap>;Rq3n{uW}I?l;3pxboH8__2<{6cPrr~+y}6ADQ!^v%vG_vV|)Q`JQ( za8DalZWWmtjG?EX`=vXg`U>A;Q&1TM2J@QSPK(-3G$A*XNk{H2xSwZ?vptlbofYsq zJ^i#DRxK;6D>uuL!b1`8*^M4#Q=P;28TznX2U~#AZQ6O=>}^Ne0lW*3#`Et`9Okk4 z?6%d-uk`gFA9$<0JLwfzj1{n0MTqeWY*A}@eu<`|QML8%*%iOcZPE7Kq-RKwmC=KC z|Lx!ke5bq0+BV@uC#w(~o?q&(rZ9wr8d>J~8En^y% z2znU%-$b*zNVnsnRnr>n~(ysag2rk-8fK73;m5*i>~l;9b}t zQ}yxS#iX^df3QGjgtk=z2bAl9Bq3+RPpi$90mEnHh=R=zKNKnEvBos^FE+f{UU+Ar zEodh)7J-))&=7~3uG}HG<~P;c$vXo4o$glI!1YW7{J zD9;i!RSHsE(xB`27I`%rpE6d4-(xi|mf66RwXOsx{JgT!i&sSD8cr7J-NLi% zT3|NiA>VWRl^ zwH5xSEz5vNcWCqFXGBN$dQ~;_^F8y#*}t=G0_mnXOTUitSBgJnJj3a~p>T9zV$3!y zu`0$gJXjL5ksX=G7&pk+A!NCw>`M|T?$3X_n;iTp`d`V`o4;5i<3pQt9IxY>*jcj8 z@c#DxcsVHqgM$ymU-NbO%^{PyNdN!jgQ56lze}k42l=i#eB47}N?|*bK2`Mp2a}$;#7RWswg3PC07*qoM6N<$g8zmuE&u=k literal 0 HcmV?d00001 diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index f340590e5fe33..bd048d2ec9742 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -51,6 +51,9 @@ pub static LICENSE_APACHE: &'static [u8] = include_bytes!("static/LICENSE-APACHE /// The contents of `LICENSE-MIT.txt`, the text of the MIT License. pub static LICENSE_MIT: &'static [u8] = include_bytes!("static/LICENSE-MIT.txt"); +/// The contents of `rust-logo.png`, the default icon of the documentation. +pub static RUST_LOGO: &'static [u8] = include_bytes!("static/rust-logo.png"); + /// The built-in themes given to every documentation site. pub mod themes { /// The "light" theme, selected by default when no setting is available. Used as the basis for From 98d4f33626c4a18092cd015b4e1cc15381989677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Wed, 16 Jan 2019 20:45:53 +0100 Subject: [PATCH 10/14] const_eval: Predetermine the layout of all locals when pushing a stack frame Usually the layout of any locals is required at least three times, once when it becomes live, once when it is written to, and once it is read from. By adding a cache for them, we can reduce the number of layout queries speeding up code that is heavy on const_eval. --- src/librustc_mir/const_eval.rs | 1 + src/librustc_mir/interpret/eval_context.rs | 19 ++++++++++++++----- src/librustc_mir/interpret/operand.rs | 18 ++++++------------ src/librustc_mir/interpret/snapshot.rs | 4 +++- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index f5f4048167938..105856fecc729 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -72,6 +72,7 @@ fn mk_eval_cx_inner<'a, 'mir, 'tcx>( ecx.stack.push(interpret::Frame { block: mir::START_BLOCK, locals: IndexVec::new(), + local_layouts: IndexVec::new(), instance, span, mir, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 19362b6cfdb1c..b2d3328a73fe8 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -1,3 +1,4 @@ +use std::cell::Cell; use std::fmt::Write; use std::mem; @@ -76,6 +77,7 @@ pub struct Frame<'mir, 'tcx: 'mir, Tag=(), Extra=()> { /// `None` represents a local that is currently dead, while a live local /// can either directly contain `Scalar` or refer to some part of an `Allocation`. pub locals: IndexVec>, + pub local_layouts: IndexVec>>>, //////////////////////////////////////////////////////////////////////////////// // Current position within the function @@ -290,9 +292,15 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, local: mir::Local ) -> EvalResult<'tcx, TyLayout<'tcx>> { - let local_ty = frame.mir.local_decls[local].ty; - let local_ty = self.monomorphize(local_ty, frame.instance.substs); - self.layout_of(local_ty) + let cell = &frame.local_layouts[local]; + if cell.get().is_none() { + let local_ty = frame.mir.local_decls[local].ty; + let local_ty = self.monomorphize(local_ty, frame.instance.substs); + let layout = self.layout_of(local_ty)?; + cell.set(Some(layout)); + } + + Ok(cell.get().unwrap()) } pub fn str_to_immediate(&mut self, s: &str) -> EvalResult<'tcx, Immediate> { @@ -426,6 +434,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc // empty local array, we fill it in below, after we are inside the stack frame and // all methods actually know about the frame locals: IndexVec::new(), + local_layouts: IndexVec::from_elem_n(Default::default(), mir.local_decls.len()), span, instance, stmt: 0, @@ -464,11 +473,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc }, } // Finally, properly initialize all those that still have the dummy value - for (local, decl) in locals.iter_mut().zip(mir.local_decls.iter()) { + for (idx, local) in locals.iter_enumerated_mut() { match *local { LocalValue::Live(_) => { // This needs to be peoperly initialized. - let layout = self.layout_of(self.monomorphize(decl.ty, instance.substs))?; + let layout = self.layout_of_local(self.frame(), idx)?; *local = LocalValue::Live(self.uninit_operand(layout)?); } LocalValue::Dead => { diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 04e0955ad6172..b2648480f203c 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -457,36 +457,30 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> } /// This is used by [priroda](https://github.com/oli-obk/priroda) to get an OpTy from a local - /// - /// When you know the layout of the local in advance, you can pass it as last argument - pub fn access_local( + fn access_local( &self, frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, local: mir::Local, - layout: Option>, ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> { assert_ne!(local, mir::RETURN_PLACE); let op = *frame.locals[local].access()?; - let layout = from_known_layout(layout, - || self.layout_of_local(frame, local))?; + let layout = self.layout_of_local(frame, local)?; Ok(OpTy { op, layout }) } // Evaluate a place with the goal of reading from it. This lets us sometimes - // avoid allocations. If you already know the layout, you can pass it in - // to avoid looking it up again. + // avoid allocations. fn eval_place_to_op( &self, mir_place: &mir::Place<'tcx>, - layout: Option>, ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> { use rustc::mir::Place::*; let op = match *mir_place { Local(mir::RETURN_PLACE) => return err!(ReadFromReturnPointer), - Local(local) => self.access_local(self.frame(), local, layout)?, + Local(local) => self.access_local(self.frame(), local)?, Projection(ref proj) => { - let op = self.eval_place_to_op(&proj.base, None)?; + let op = self.eval_place_to_op(&proj.base)?; self.operand_projection(op, &proj.elem)? } @@ -510,7 +504,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> // FIXME: do some more logic on `move` to invalidate the old location Copy(ref place) | Move(ref place) => - self.eval_place_to_op(place, layout)?, + self.eval_place_to_op(place)?, Constant(ref constant) => { let layout = from_known_layout(layout, || { diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index f9ce7b4319fac..53105266b3928 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -314,13 +314,14 @@ struct FrameSnapshot<'a, 'tcx: 'a> { stmt: usize, } -impl_stable_hash_for!(impl<'tcx, 'mir: 'tcx> for struct Frame<'mir, 'tcx> { +impl_stable_hash_for!(impl<'mir, 'tcx: 'mir> for struct Frame<'mir, 'tcx> { mir, instance, span, return_to_block, return_place -> (return_place.as_ref().map(|r| &**r)), locals, + local_layouts -> _, block, stmt, extra, @@ -339,6 +340,7 @@ impl<'a, 'mir, 'tcx, Ctx> Snapshot<'a, Ctx> for &'a Frame<'mir, 'tcx> return_to_block, return_place, locals, + local_layouts: _, block, stmt, extra: _, From b5d167f58a423cb0003714eceeb72172d1726473 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 12 Jan 2019 22:27:09 +0100 Subject: [PATCH 11/14] Add default favicon for documentation --- src/librustdoc/html/layout.rs | 4 +++- src/librustdoc/html/render.rs | 6 ++++-- src/librustdoc/html/static/favicon.ico | Bin 0 -> 23229 bytes src/librustdoc/html/static_files.rs | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/librustdoc/html/static/favicon.ico diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index b7af28fbcc8ae..c34dcbbb672e9 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -191,7 +191,9 @@ pub fn render( description = page.description, keywords = page.keywords, favicon = if layout.favicon.is_empty() { - String::new() + format!(r#""#, + static_root_path=static_root_path, + suffix=page.resource_suffix) } else { format!(r#""#, layout.favicon) }, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d050b706f1031..b64ac9509631b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -793,6 +793,10 @@ fn write_shared( write(cx.dst.join(&format!("rust-logo{}.png", cx.shared.resource_suffix)), static_files::RUST_LOGO)?; } + if (*cx.shared).layout.favicon.is_empty() { + write(cx.dst.join(&format!("favicon{}.ico", cx.shared.resource_suffix)), + static_files::RUST_FAVICON)?; + } write(cx.dst.join(&format!("brush{}.svg", cx.shared.resource_suffix)), static_files::BRUSH_SVG)?; write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)), @@ -1999,8 +2003,6 @@ impl Context { themes.push(PathBuf::from("settings.css")); let mut layout = self.shared.layout.clone(); layout.krate = String::new(); - layout.logo = String::new(); - layout.favicon = String::new(); try_err!(layout::render(&mut w, &layout, &page, &sidebar, &settings, self.shared.css_file_extension.is_some(), diff --git a/src/librustdoc/html/static/favicon.ico b/src/librustdoc/html/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..b8ad23769ac8d06eb5973bfb3d2acbf385240f98 GIT binary patch literal 23229 zcmeHvc|28H|Nn80c^;Zf$(*SSWu`JD(V;RG>6p@BE^{)JxkzQmP>~SI(4dfxF(slB z5)PR%L}d!)x0ZYM{hrRHTlcx&;g8>bJ@5Nj>$5(?d#%0p+H0?)2Zf?QQKG7KHQB}0m;J^5csADJ;Ux=>OHY2a((G>5y2ee}sw(wi6T`3%ZKV`TrFyPF# zt&A6CYgvuX>mI3Y4iczsT`%x-^H<4K|4iTE5A( zW;pTj)bS=iyy&B$FLZTz6sqXlO(QRPaGH6uCn|hQsGKO}S@_hL9R`fA>g_4(3L74) z=Mhj5{S+k^;9h$yrFNWoZS_9MkBle@w7uv}e0VO(;)O~BN_s=I~%uGO3%LKPp+NC_VOjyiikz7Wk2r6 z?y}oVo2#KHaFYG54CD?V{U0f#D6deJ(I;O>8=(|PlNQygb8S{K1o10}pnz1B`0*i@@Sg+EVqi&Sp>fWfI-G0X^^q3yS z7IcPUOtbmMGonZH6ft-&(L(KE8mn4Qj0<&B11j?I=GmZA?qTQH-`$art_&Zcb9PQo zG0QgY8$X9r!P{{pK4q7mw;k*Tp%SM}MKtFE!;oThbJs zORbMuJC$t^=d_P``$YQNa31F8=u<4JeOjkJXsPq;bqM%)JjBVO(}HWxT)Rh0-c{gn z)s)>SmgjB)Iwm;tBNMrrXV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;xV}QbGStccU`$d0ZOi~S z07&O5eCI)s>YxoXi7UMK&=>g)AHEw;1Bd{iiGXFOL-wN3_RkogjO2yS4L@mY(lTrV zfHsiN4cG=G>@UI(?zOLxK@`+E0pNUuZKV5gWULVXrQ}xN1J|#m+K_REZN30-eMRgV zKp6+H8sIfi51&g907qiI3rKi>riguk`)0%+t{;%^0}>q`+QAFxrU0NX#8;w@)E|jM zDi1F@|KShc9ncqYfHuMar2fUAz77EX22uh5ZRP=>4%)&x^i3p|n}Mt%mSG$G=4%9i zYYws=LA?|}AOI{wU()*rb<1G}v;_e`KFB;;oX?3rfVPYC zhd6Ge^LGNY1ptVUj1}xJ Date: Sun, 20 Jan 2019 17:14:15 -0800 Subject: [PATCH 12/14] Add regression test for #54582 --- src/test/ui/issues/issue-54582.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/ui/issues/issue-54582.rs diff --git a/src/test/ui/issues/issue-54582.rs b/src/test/ui/issues/issue-54582.rs new file mode 100644 index 0000000000000..c2dbf361911b5 --- /dev/null +++ b/src/test/ui/issues/issue-54582.rs @@ -0,0 +1,16 @@ +// run-pass + +pub trait Stage: Sync {} + +pub enum Enum { + A, + B, +} + +impl Stage for Enum {} + +pub static ARRAY: [(&Stage, &str); 1] = [ + (&Enum::A, ""), +]; + +fn main() {} From 45a95b512c6fb491518d6a3f4b667d6dd82cd56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 20 Jan 2019 19:37:38 -0800 Subject: [PATCH 13/14] Use structured suggestion in stead of notes --- src/librustc_typeck/check/method/suggest.rs | 14 ++++++++++++-- src/libsyntax/parse/parser.rs | 13 ++++++++++--- src/test/ui/auto-ref-slice-plus-ref.stderr | 3 +-- src/test/ui/block-result/issue-3563.stderr | 4 +--- src/test/ui/empty/empty-struct-braces-expr.stderr | 10 ++++------ src/test/ui/issues/issue-23217.stderr | 5 ++--- src/test/ui/issues/issue-28344.stderr | 6 ++---- src/test/ui/issues/issue-28971.stderr | 7 ++++--- .../result-deref-err.stderr | 3 +-- src/test/ui/parser/issue-17718-const-mut.rs | 2 +- src/test/ui/parser/issue-17718-const-mut.stderr | 6 +++--- src/test/ui/suggestions/suggest-methods.stderr | 12 +++--------- 12 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 23bcd88d6afb5..f71a163cee261 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -304,7 +304,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ); if let Some(suggestion) = suggestion { // enum variant - err.help(&format!("did you mean `{}`?", suggestion)); + err.span_suggestion_with_applicability( + item_name.span, + "did you mean", + suggestion.to_string(), + Applicability::MaybeIncorrect, + ); } err } @@ -440,7 +445,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } if let Some(lev_candidate) = lev_candidate { - err.help(&format!("did you mean `{}`?", lev_candidate.ident)); + err.span_suggestion_with_applicability( + span, + "did you mean", + lev_candidate.ident.to_string(), + Applicability::MaybeIncorrect, + ); } err.emit(); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7e15b23127655..d4a3411f463d0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -7271,9 +7271,16 @@ impl<'a> Parser<'a> { // CONST ITEM if self.eat_keyword(keywords::Mut) { let prev_span = self.prev_span; - self.diagnostic().struct_span_err(prev_span, "const globals cannot be mutable") - .help("did you mean to declare a static?") - .emit(); + let mut err = self.diagnostic() + .struct_span_err(prev_span, "const globals cannot be mutable"); + err.span_label(prev_span, "cannot be mutable"); + err.span_suggestion_with_applicability( + const_span, + "you might want to declare a static instead", + "static".to_owned(), + Applicability::MaybeIncorrect, + ); + err.emit(); } let (ident, item_, extra_attrs) = self.parse_item_const(None)?; let prev_span = self.prev_span; diff --git a/src/test/ui/auto-ref-slice-plus-ref.stderr b/src/test/ui/auto-ref-slice-plus-ref.stderr index ab57fec0e7337..356e24d18a78f 100644 --- a/src/test/ui/auto-ref-slice-plus-ref.stderr +++ b/src/test/ui/auto-ref-slice-plus-ref.stderr @@ -2,12 +2,11 @@ error[E0599]: no method named `test_mut` found for type `std::vec::Vec<{integer} --> $DIR/auto-ref-slice-plus-ref.rs:7:7 | LL | a.test_mut(); //~ ERROR no method named `test_mut` found - | ^^^^^^^^ + | ^^^^^^^^ help: did you mean: `get_mut` | = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `test_mut`, perhaps you need to implement it: candidate #1: `MyIter` - = help: did you mean `get_mut`? error[E0599]: no method named `test` found for type `std::vec::Vec<{integer}>` in the current scope --> $DIR/auto-ref-slice-plus-ref.rs:8:7 diff --git a/src/test/ui/block-result/issue-3563.stderr b/src/test/ui/block-result/issue-3563.stderr index 7f386630de590..a6346a5233f4c 100644 --- a/src/test/ui/block-result/issue-3563.stderr +++ b/src/test/ui/block-result/issue-3563.stderr @@ -2,9 +2,7 @@ error[E0599]: no method named `b` found for type `&Self` in the current scope --> $DIR/issue-3563.rs:3:17 | LL | || self.b() - | ^ - | - = help: did you mean `a`? + | ^ help: did you mean: `a` error: aborting due to previous error diff --git a/src/test/ui/empty/empty-struct-braces-expr.stderr b/src/test/ui/empty/empty-struct-braces-expr.stderr index e595e0ccb9293..19844503a4804 100644 --- a/src/test/ui/empty/empty-struct-braces-expr.stderr +++ b/src/test/ui/empty/empty-struct-braces-expr.stderr @@ -51,20 +51,18 @@ error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the | LL | let xe3 = XE::Empty3; //~ ERROR no variant named `Empty3` found for type | ----^^^^^^ - | | + | | | + | | help: did you mean: `XEmpty3` | variant not found in `empty_struct::XE` - | - = help: did you mean `XEmpty3`? error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the current scope --> $DIR/empty-struct-braces-expr.rs:23:19 | LL | let xe3 = XE::Empty3(); //~ ERROR no variant named `Empty3` found for type | ----^^^^^^ - | | + | | | + | | help: did you mean: `XEmpty3` | variant not found in `empty_struct::XE` - | - = help: did you mean `XEmpty3`? error: aborting due to 8 previous errors diff --git a/src/test/ui/issues/issue-23217.stderr b/src/test/ui/issues/issue-23217.stderr index 208d0cc499a80..9cad002036fff 100644 --- a/src/test/ui/issues/issue-23217.stderr +++ b/src/test/ui/issues/issue-23217.stderr @@ -5,10 +5,9 @@ LL | pub enum SomeEnum { | ----------------- variant `A` not found here LL | B = SomeEnum::A, | ----------^ - | | + | | | + | | help: did you mean: `B` | variant not found in `SomeEnum` - | - = help: did you mean `B`? error: aborting due to previous error diff --git a/src/test/ui/issues/issue-28344.stderr b/src/test/ui/issues/issue-28344.stderr index 146ebad6ce175..b6f520c644b32 100644 --- a/src/test/ui/issues/issue-28344.stderr +++ b/src/test/ui/issues/issue-28344.stderr @@ -11,8 +11,7 @@ LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8); | --------^^^^^ | | | function or associated item not found in `dyn std::ops::BitXor<_>` - | - = help: did you mean `bitxor`? + | help: did you mean: `bitxor` error[E0191]: the value of the associated type `Output` (from the trait `std::ops::BitXor`) must be specified --> $DIR/issue-28344.rs:8:13 @@ -27,8 +26,7 @@ LL | let g = BitXor::bitor; | --------^^^^^ | | | function or associated item not found in `dyn std::ops::BitXor<_>` - | - = help: did you mean `bitxor`? + | help: did you mean: `bitxor` error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-28971.stderr b/src/test/ui/issues/issue-28971.stderr index d5dbd5f64885c..77d0b53ad216b 100644 --- a/src/test/ui/issues/issue-28971.stderr +++ b/src/test/ui/issues/issue-28971.stderr @@ -5,9 +5,10 @@ LL | enum Foo { | -------- variant `Baz` not found here ... LL | Foo::Baz(..) => (), - | -----^^^---- variant not found in `Foo` - | - = help: did you mean `Bar`? + | -----^^^---- + | | | + | | help: did you mean: `Bar` + | variant not found in `Foo` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-50264-inner-deref-trait/result-deref-err.stderr b/src/test/ui/issues/issue-50264-inner-deref-trait/result-deref-err.stderr index 99c4a5b03b320..96d6814b0fe93 100644 --- a/src/test/ui/issues/issue-50264-inner-deref-trait/result-deref-err.stderr +++ b/src/test/ui/issues/issue-50264-inner-deref-trait/result-deref-err.stderr @@ -2,11 +2,10 @@ error[E0599]: no method named `deref_err` found for type `std::result::Result<_, --> $DIR/result-deref-err.rs:4:28 | LL | let _result = &Err(41).deref_err(); - | ^^^^^^^^^ + | ^^^^^^^^^ help: did you mean: `deref_ok` | = note: the method `deref_err` exists but the following trait bounds were not satisfied: `{integer} : std::ops::Deref` - = help: did you mean `deref_ok`? error: aborting due to previous error diff --git a/src/test/ui/parser/issue-17718-const-mut.rs b/src/test/ui/parser/issue-17718-const-mut.rs index 4e74516d6b6fb..795a8c7631d9a 100644 --- a/src/test/ui/parser/issue-17718-const-mut.rs +++ b/src/test/ui/parser/issue-17718-const-mut.rs @@ -1,6 +1,6 @@ const mut //~ ERROR: const globals cannot be mutable -//~^ HELP did you mean to declare a static? +//~^^ HELP you might want to declare a static instead FOO: usize = 3; fn main() { diff --git a/src/test/ui/parser/issue-17718-const-mut.stderr b/src/test/ui/parser/issue-17718-const-mut.stderr index 29a65ebe41889..19f9fe19ef5ab 100644 --- a/src/test/ui/parser/issue-17718-const-mut.stderr +++ b/src/test/ui/parser/issue-17718-const-mut.stderr @@ -1,10 +1,10 @@ error: const globals cannot be mutable --> $DIR/issue-17718-const-mut.rs:2:1 | +LL | const + | ----- help: you might want to declare a static instead: `static` LL | mut //~ ERROR: const globals cannot be mutable - | ^^^ - | - = help: did you mean to declare a static? + | ^^^ cannot be mutable error: aborting due to previous error diff --git a/src/test/ui/suggestions/suggest-methods.stderr b/src/test/ui/suggestions/suggest-methods.stderr index 39d96a943a18a..b7727cf03a4e7 100644 --- a/src/test/ui/suggestions/suggest-methods.stderr +++ b/src/test/ui/suggestions/suggest-methods.stderr @@ -5,25 +5,19 @@ LL | struct Foo; | ----------- method `bat` not found for this ... LL | f.bat(1.0); //~ ERROR no method named - | ^^^ - | - = help: did you mean `bar`? + | ^^^ help: did you mean: `bar` error[E0599]: no method named `is_emtpy` found for type `std::string::String` in the current scope --> $DIR/suggest-methods.rs:21:15 | LL | let _ = s.is_emtpy(); //~ ERROR no method named - | ^^^^^^^^ - | - = help: did you mean `is_empty`? + | ^^^^^^^^ help: did you mean: `is_empty` error[E0599]: no method named `count_eos` found for type `u32` in the current scope --> $DIR/suggest-methods.rs:25:19 | LL | let _ = 63u32.count_eos(); //~ ERROR no method named - | ^^^^^^^^^ - | - = help: did you mean `count_zeros`? + | ^^^^^^^^^ help: did you mean: `count_zeros` error[E0599]: no method named `count_o` found for type `u32` in the current scope --> $DIR/suggest-methods.rs:28:19 From 58b02000c51c1bd460f089368481e1552e0f86ac Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 21 Jan 2019 18:50:54 +0100 Subject: [PATCH 14/14] Add powerpc64-unknown-freebsd --- src/librustc_target/spec/mod.rs | 1 + .../spec/powerpc64_unknown_freebsd.rs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/librustc_target/spec/powerpc64_unknown_freebsd.rs diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 3a21ca19b176b..e47da3cff95b6 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -367,6 +367,7 @@ supported_targets! { ("aarch64-unknown-freebsd", aarch64_unknown_freebsd), ("i686-unknown-freebsd", i686_unknown_freebsd), + ("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd), ("x86_64-unknown-freebsd", x86_64_unknown_freebsd), ("i686-unknown-dragonfly", i686_unknown_dragonfly), diff --git a/src/librustc_target/spec/powerpc64_unknown_freebsd.rs b/src/librustc_target/spec/powerpc64_unknown_freebsd.rs new file mode 100644 index 0000000000000..cc7b87bfdebc3 --- /dev/null +++ b/src/librustc_target/spec/powerpc64_unknown_freebsd.rs @@ -0,0 +1,22 @@ +use spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::freebsd_base::opts(); + base.cpu = "ppc64".to_string(); + base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string()); + base.max_atomic_width = Some(64); + + Ok(Target { + llvm_target: "powerpc64-unknown-freebsd".to_string(), + target_endian: "big".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "E-m:e-i64:64-n32:64".to_string(), + arch: "powerpc64".to_string(), + target_os: "freebsd".to_string(), + target_env: String::new(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +}