diff --git a/RELEASES.md b/RELEASES.md index 70a7dab72272f..21134d50bdcc8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -64,9 +64,6 @@ Cargo - [`cargo run` doesn't require specifying a package in workspaces.][cargo/5877] - [`cargo doc` now supports `--message-format=json`.][cargo/5878] This is equivalent to calling `rustdoc --error-format=json`. -- [You can specify which edition to create a project in cargo - with `cargo new --edition`.][cargo/5984] Currently only `2015` is a - valid option. - [Cargo will now provide a progress bar for builds.][cargo/5995] Misc @@ -100,9 +97,8 @@ Misc [54404]: https://github.com/rust-lang/rust/pull/54404/ [cargo/5877]: https://github.com/rust-lang/cargo/pull/5877/ [cargo/5878]: https://github.com/rust-lang/cargo/pull/5878/ -[cargo/5984]: https://github.com/rust-lang/cargo/pull/5984/ [cargo/5995]: https://github.com/rust-lang/cargo/pull/5995/ -[proc-macros]: https://doc.rust-lang.org/book/2018-edition/ch19-06-macros.html +[proc-macros]: https://doc.rust-lang.org/stable/book/2018-edition/ch19-06-macros.html [`Ipv4Addr::BROADCAST`]: https://doc.rust-lang.org/nightly/std/net/struct.Ipv4Addr.html#associatedconstant.BROADCAST [`Ipv4Addr::LOCALHOST`]: https://doc.rust-lang.org/nightly/std/net/struct.Ipv4Addr.html#associatedconstant.LOCALHOST diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 4de899ee2d599..fea6302d0a119 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1447,8 +1447,8 @@ impl Step for Extended { tarballs.extend(rls_installer.clone()); tarballs.extend(clippy_installer.clone()); tarballs.extend(rustfmt_installer.clone()); - tarballs.extend(llvm_tools_installer.clone()); - tarballs.extend(lldb_installer.clone()); + tarballs.extend(llvm_tools_installer); + tarballs.extend(lldb_installer); tarballs.push(analysis_installer); tarballs.push(std_installer); if builder.config.docs { diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index fe04a91011ee5..f6032eb9931f7 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1052,7 +1052,7 @@ impl Step for Compiletest { let hostflags = flags.clone(); cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); - let mut targetflags = flags.clone(); + let mut targetflags = flags; targetflags.push(format!( "-Lnative={}", builder.test_helpers_out(target).display() diff --git a/src/ci/run.sh b/src/ci/run.sh index a2c271f0fc895..f51199de6ebe3 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -51,7 +51,7 @@ fi # # FIXME: need a scheme for changing this `nightly` value to `beta` and `stable` # either automatically or manually. -export RUST_RELEASE_CHANNEL=nightly +export RUST_RELEASE_CHANNEL=beta if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index afb5f23db5b83..99a1cf3c78757 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3094,7 +3094,8 @@ impl<'a> LoweringContext<'a> { // Privatize the degenerate import base, used only to check // the stability of `use a::{};`, to avoid it showing up as // a re-export by accident when `pub`, e.g. in documentation. - let path = P(self.lower_path(id, &prefix, ParamMode::Explicit)); + let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err); + let path = P(self.lower_path_extra(def, &prefix, None, ParamMode::Explicit)); *vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited); hir::ItemKind::Use(path, hir::UseKind::ListStem) } diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index 4f68569c60032..274a2df283cbd 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -606,3 +606,6 @@ impl<'a, 'gcx> HashStable> for mir::UserTypeAnnotation< } } } + +impl_stable_hash_for!(struct mir::UserTypeProjection<'tcx> { base, projs }); +impl_stable_hash_for!(struct mir::UserTypeProjections<'tcx> { contents }); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 8b4669c89fe83..d19c495af3b96 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -479,17 +479,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err.span_label(arm_span, msg); } } - hir::MatchSource::TryDesugar => { - // Issue #51632 - if let Ok(try_snippet) = self.tcx.sess.source_map().span_to_snippet(arm_span) { - err.span_suggestion_with_applicability( - arm_span, - "try wrapping with a success variant", - format!("Ok({})", try_snippet), - Applicability::MachineApplicable, - ); - } - } + hir::MatchSource::TryDesugar => {} _ => { let msg = "match arm with an incompatible type"; if self.tcx.sess.source_map().is_multiline(arm_span) { diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index 332859d4f81db..5db850f1588b6 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -458,7 +458,7 @@ where ); debug!("projection_must_outlive: unique declared bound appears in trait ref"); self.delegate - .push_sub_region_constraint(origin.clone(), region, unique_bound); + .push_sub_region_constraint(origin, region, unique_bound); return; } diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index 96278e5140c8a..c82603bf56057 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -749,7 +749,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> { a // LUB(a,a) = a } - _ => self.combine_vars(tcx, Lub, a, b, origin.clone()), + _ => self.combine_vars(tcx, Lub, a, b, origin), } } @@ -771,7 +771,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> { a // GLB(a,a) = a } - _ => self.combine_vars(tcx, Glb, a, b, origin.clone()), + _ => self.combine_vars(tcx, Glb, a, b, origin), } } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9d296e67da1ae..952783a91b2ed 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -710,7 +710,7 @@ pub struct LocalDecl<'tcx> { /// e.g. via `let x: T`, then we carry that type here. The MIR /// borrow checker needs this information since it can affect /// region inference. - pub user_ty: Option<(UserTypeAnnotation<'tcx>, Span)>, + pub user_ty: UserTypeProjections<'tcx>, /// Name of the local, used in debuginfo and pretty-printing. /// @@ -882,7 +882,7 @@ impl<'tcx> LocalDecl<'tcx> { LocalDecl { mutability, ty, - user_ty: None, + user_ty: UserTypeProjections::none(), name: None, source_info: SourceInfo { span, @@ -903,7 +903,7 @@ impl<'tcx> LocalDecl<'tcx> { LocalDecl { mutability: Mutability::Mut, ty: return_ty, - user_ty: None, + user_ty: UserTypeProjections::none(), source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE, @@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> { /// Changes a statement to a nop. This is both faster than deleting instructions and avoids /// invalidating statement indices in `Location`s. pub fn make_nop(&mut self) { + // `Statement` contributes significantly to peak memory usage. Make + // sure it doesn't get bigger. + static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::>() <= 56); + self.kind = StatementKind::Nop } @@ -1737,7 +1741,7 @@ pub enum StatementKind<'tcx> { /// - `Contravariant` -- requires that `T_y :> T` /// - `Invariant` -- requires that `T_y == T` /// - `Bivariant` -- no effect - AscribeUserType(Place<'tcx>, ty::Variance, UserTypeAnnotation<'tcx>), + AscribeUserType(Place<'tcx>, ty::Variance, Box>), /// No-op. Useful for deleting instructions without affecting statement indices. Nop, @@ -1940,6 +1944,10 @@ pub type PlaceProjection<'tcx> = Projection<'tcx, Place<'tcx>, Local, Ty<'tcx>>; /// and the index is a local. pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>; +/// Alias for projections as they appear in `UserTypeProjection`, where we +/// need neither the `V` parameter for `Index` nor the `T` for `Field`. +pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>; + newtype_index! { pub struct Field { DEBUG_FORMAT = "field[{}]" @@ -2445,6 +2453,117 @@ EnumLiftImpl! { } } +/// A collection of projections into user types. +/// +/// They are projections because a binding can occur a part of a +/// parent pattern that has been ascribed a type. +/// +/// Its a collection because there can be multiple type ascriptions on +/// the path from the root of the pattern down to the binding itself. +/// +/// An example: +/// +/// ```rust +/// struct S<'a>((i32, &'a str), String); +/// let S((_, w): (i32, &'static str), _): S = ...; +/// // ------ ^^^^^^^^^^^^^^^^^^^ (1) +/// // --------------------------------- ^ (2) +/// ``` +/// +/// The highlights labelled `(1)` show the subpattern `(_, w)` being +/// ascribed the type `(i32, &'static str)`. +/// +/// The highlights labelled `(2)` show the whole pattern being +/// ascribed the type `S`. +/// +/// In this example, when we descend to `w`, we will have built up the +/// following two projected types: +/// +/// * base: `S`, projection: `(base.0).1` +/// * base: `(i32, &'static str)`, projection: `base.1` +/// +/// The first will lead to the constraint `w: &'1 str` (for some +/// inferred region `'1`). The second will lead to the constraint `w: +/// &'static str`. +#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +pub struct UserTypeProjections<'tcx> { + pub(crate) contents: Vec<(UserTypeProjection<'tcx>, Span)>, +} + +BraceStructTypeFoldableImpl! { + impl<'tcx> TypeFoldable<'tcx> for UserTypeProjections<'tcx> { + contents + } +} + +impl<'tcx> UserTypeProjections<'tcx> { + pub fn none() -> Self { + UserTypeProjections { contents: vec![] } + } + + pub fn from_projections(projs: impl Iterator, Span)>) -> Self { + UserTypeProjections { contents: projs.collect() } + } + + pub fn projections_and_spans(&self) -> impl Iterator, Span)> { + self.contents.iter() + } + + pub fn projections(&self) -> impl Iterator> { + self.contents.iter().map(|&(ref user_type, _span)| user_type) + } +} + +/// Encodes the effect of a user-supplied type annotation on the +/// subcomponents of a pattern. The effect is determined by applying the +/// given list of proejctions to some underlying base type. Often, +/// the projection element list `projs` is empty, in which case this +/// directly encodes a type in `base`. But in the case of complex patterns with +/// subpatterns and bindings, we want to apply only a *part* of the type to a variable, +/// in which case the `projs` vector is used. +/// +/// Examples: +/// +/// * `let x: T = ...` -- here, the `projs` vector is empty. +/// +/// * `let (x, _): T = ...` -- here, the `projs` vector would contain +/// `field[0]` (aka `.0`), indicating that the type of `s` is +/// determined by finding the type of the `.0` field from `T`. +#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +pub struct UserTypeProjection<'tcx> { + pub base: UserTypeAnnotation<'tcx>, + pub projs: Vec>, +} + +impl<'tcx> Copy for ProjectionKind<'tcx> { } + +CloneTypeFoldableAndLiftImpls! { ProjectionKind<'tcx>, } + +impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> { + fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { + use mir::ProjectionElem::*; + + let base = self.base.fold_with(folder); + let projs: Vec<_> = self.projs + .iter() + .map(|elem| { + match elem { + Deref => Deref, + Field(f, ()) => Field(f.clone(), ()), + Index(()) => Index(()), + elem => elem.clone(), + }}) + .collect(); + + UserTypeProjection { base, projs } + } + + fn super_visit_with>(&self, visitor: &mut Vs) -> bool { + self.base.visit_with(visitor) + // Note: there's nothing in `self.proj` to visit. + } +} + newtype_index! { pub struct Promoted { DEBUG_FORMAT = "promoted[{}]" diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index fc7b4862b0ae5..473730c548990 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -44,11 +44,59 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> { } } + /// `place_ty.field_ty(tcx, f)` computes the type at a given field + /// of a record or enum-variant. (Most clients of `PlaceTy` can + /// instead just extract the relevant type directly from their + /// `PlaceElem`, but some instances of `ProjectionElem` do + /// not carry a `Ty` for `T`.) + /// + /// Note that the resulting type has not been normalized. + pub fn field_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, f: &Field) -> Ty<'tcx> + { + // Pass `0` here so it can be used as a "default" variant_index in first arm below + let answer = match (self, 0) { + (PlaceTy::Ty { + ty: &ty::TyS { sty: ty::TyKind::Adt(adt_def, substs), .. } }, variant_index) | + (PlaceTy::Downcast { adt_def, substs, variant_index }, _) => { + let variant_def = &adt_def.variants[variant_index]; + let field_def = &variant_def.fields[f.index()]; + field_def.ty(tcx, substs) + } + (PlaceTy::Ty { ty }, _) => { + match ty.sty { + ty::Tuple(ref tys) => tys[f.index()], + _ => bug!("extracting field of non-tuple non-adt: {:?}", self), + } + } + }; + debug!("field_ty self: {:?} f: {:?} yields: {:?}", self, f, answer); + answer + } + + /// Convenience wrapper around `projection_ty_core` for + /// `PlaceElem`, where we can just use the `Ty` that is already + /// stored inline on field projection elems. pub fn projection_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, elem: &PlaceElem<'tcx>) -> PlaceTy<'tcx> { - match *elem { + self.projection_ty_core(tcx, elem, |_, _, ty| ty) + } + + /// `place_ty.projection_ty_core(tcx, elem, |...| { ... })` + /// projects `place_ty` onto `elem`, returning the appropriate + /// `Ty` or downcast variant corresponding to that projection. + /// The `handle_field` callback must map a `Field` to its `Ty`, + /// (which should be trivial when `T` = `Ty`). + pub fn projection_ty_core(self, + tcx: TyCtxt<'a, 'gcx, 'tcx>, + elem: &ProjectionElem<'tcx, V, T>, + mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>) + -> PlaceTy<'tcx> + where + V: ::std::fmt::Debug, T: ::std::fmt::Debug + { + let answer = match *elem { ProjectionElem::Deref => { let ty = self.to_ty(tcx) .builtin_deref(true) @@ -94,8 +142,10 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> { bug!("cannot downcast non-ADT type: `{:?}`", self) } }, - ProjectionElem::Field(_, fty) => PlaceTy::Ty { ty: fty } - } + ProjectionElem::Field(ref f, ref fty) => PlaceTy::Ty { ty: handle_field(&self, f, fty) } + }; + debug!("projection_ty self: {:?} elem: {:?} yields: {:?}", self, elem, answer); + answer } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 76c76404d2fd2..bfc03923f6011 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -147,7 +147,7 @@ macro_rules! make_mir_visitor { fn visit_ascribe_user_ty(&mut self, place: & $($mutability)* Place<'tcx>, variance: & $($mutability)* ty::Variance, - user_ty: & $($mutability)* UserTypeAnnotation<'tcx>, + user_ty: & $($mutability)* UserTypeProjection<'tcx>, location: Location) { self.super_ascribe_user_ty(place, variance, user_ty, location); } @@ -175,9 +175,8 @@ macro_rules! make_mir_visitor { fn visit_projection_elem(&mut self, place: & $($mutability)* PlaceElem<'tcx>, - context: PlaceContext<'tcx>, location: Location) { - self.super_projection_elem(place, context, location); + self.super_projection_elem(place, location); } fn visit_branch(&mut self, @@ -214,6 +213,13 @@ macro_rules! make_mir_visitor { self.super_ty(ty); } + fn visit_user_type_projection( + &mut self, + ty: & $($mutability)* UserTypeProjection<'tcx>, + ) { + self.super_user_type_projection(ty); + } + fn visit_user_type_annotation( &mut self, ty: & $($mutability)* UserTypeAnnotation<'tcx>, @@ -640,10 +646,10 @@ macro_rules! make_mir_visitor { fn super_ascribe_user_ty(&mut self, place: & $($mutability)* Place<'tcx>, _variance: & $($mutability)* ty::Variance, - user_ty: & $($mutability)* UserTypeAnnotation<'tcx>, + user_ty: & $($mutability)* UserTypeProjection<'tcx>, location: Location) { self.visit_place(place, PlaceContext::Validate, location); - self.visit_user_type_annotation(user_ty); + self.visit_user_type_projection(user_ty); } fn super_place(&mut self, @@ -692,12 +698,11 @@ macro_rules! make_mir_visitor { PlaceContext::Projection(Mutability::Not) }; self.visit_place(base, context, location); - self.visit_projection_elem(elem, context, location); + self.visit_projection_elem(elem, location); } fn super_projection_elem(&mut self, proj: & $($mutability)* PlaceElem<'tcx>, - _context: PlaceContext<'tcx>, location: Location) { match *proj { ProjectionElem::Deref => { @@ -738,8 +743,8 @@ macro_rules! make_mir_visitor { local, source_info: *source_info, }); - if let Some((user_ty, _)) = user_ty { - self.visit_user_type_annotation(user_ty); + for (user_ty, _) in & $($mutability)* user_ty.contents { + self.visit_user_type_projection(user_ty); } self.visit_source_info(source_info); self.visit_source_scope(visibility_scope); @@ -786,6 +791,17 @@ macro_rules! make_mir_visitor { self.visit_source_scope(scope); } + fn super_user_type_projection( + &mut self, + ty: & $($mutability)* UserTypeProjection<'tcx>, + ) { + let UserTypeProjection { + ref $($mutability)* base, + projs: _, // Note: Does not visit projection elems! + } = *ty; + self.visit_user_type_annotation(base); + } + fn super_user_type_annotation( &mut self, _ty: & $($mutability)* UserTypeAnnotation<'tcx>, diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index ea30752a820ee..b6df8ebe909f5 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -239,7 +239,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let msg = format!("type mismatch resolving `{}`", predicate); let error_id = (DiagnosticMessageId::ErrorId(271), - Some(obligation.cause.span), msg.clone()); + Some(obligation.cause.span), msg); let fresh = self.tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id); if fresh { let mut diag = struct_span_err!( @@ -379,7 +379,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } if let Some(t) = self.get_parent_trait_ref(&obligation.cause.code) { - flags.push(("parent_trait".to_owned(), Some(t.to_string()))); + flags.push(("parent_trait".to_owned(), Some(t))); } if let Some(k) = obligation.cause.span.compiler_desugaring_kind() { diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index b266fbe0d1145..4eda47d31ebb5 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -594,7 +594,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>( // But for now, let's classify this as an overflow: let recursion_limit = *selcx.tcx().sess.recursion_limit.get(); - let obligation = Obligation::with_depth(cause.clone(), + let obligation = Obligation::with_depth(cause, recursion_limit, param_env, projection_ty); diff --git a/src/librustc/traits/query/type_op/ascribe_user_type.rs b/src/librustc/traits/query/type_op/ascribe_user_type.rs index b3955b8f864e5..23445781eb2f3 100644 --- a/src/librustc/traits/query/type_op/ascribe_user_type.rs +++ b/src/librustc/traits/query/type_op/ascribe_user_type.rs @@ -11,6 +11,7 @@ use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; use traits::query::Fallible; use hir::def_id::DefId; +use mir::ProjectionKind; use ty::{self, ParamEnvAnd, Ty, TyCtxt}; use ty::subst::UserSubsts; @@ -20,6 +21,7 @@ pub struct AscribeUserType<'tcx> { pub variance: ty::Variance, pub def_id: DefId, pub user_substs: UserSubsts<'tcx>, + pub projs: &'tcx ty::List>, } impl<'tcx> AscribeUserType<'tcx> { @@ -28,8 +30,9 @@ impl<'tcx> AscribeUserType<'tcx> { variance: ty::Variance, def_id: DefId, user_substs: UserSubsts<'tcx>, + projs: &'tcx ty::List>, ) -> Self { - AscribeUserType { mir_ty, variance, def_id, user_substs } + AscribeUserType { mir_ty, variance, def_id, user_substs, projs } } } @@ -59,19 +62,19 @@ impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for AscribeUserType<'tcx> BraceStructTypeFoldableImpl! { impl<'tcx> TypeFoldable<'tcx> for AscribeUserType<'tcx> { - mir_ty, variance, def_id, user_substs + mir_ty, variance, def_id, user_substs, projs } } BraceStructLiftImpl! { impl<'a, 'tcx> Lift<'tcx> for AscribeUserType<'a> { type Lifted = AscribeUserType<'tcx>; - mir_ty, variance, def_id, user_substs + mir_ty, variance, def_id, user_substs, projs } } impl_stable_hash_for! { struct AscribeUserType<'tcx> { - mir_ty, variance, def_id, user_substs + mir_ty, variance, def_id, user_substs, projs } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1a9f86306325f..d4b47db608163 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -31,7 +31,7 @@ use middle::cstore::EncodedMetadata; use middle::lang_items; use middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use middle::stability; -use mir::{self, Mir, interpret}; +use mir::{self, Mir, interpret, ProjectionKind}; use mir::interpret::Allocation; use ty::subst::{CanonicalUserSubsts, Kind, Substs, Subst}; use ty::ReprOptions; @@ -132,6 +132,7 @@ pub struct CtxtInterners<'tcx> { clauses: InternedSet<'tcx, List>>, goal: InternedSet<'tcx, GoalKind<'tcx>>, goal_list: InternedSet<'tcx, List>>, + projs: InternedSet<'tcx, List>>, } impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> { @@ -149,6 +150,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> { clauses: Default::default(), goal: Default::default(), goal_list: Default::default(), + projs: Default::default(), } } @@ -1200,7 +1202,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { cstore, global_arenas: &arenas.global, global_interners: interners, - dep_graph: dep_graph.clone(), + dep_graph, types: common_types, trait_map, export_map: resolutions.export_map.into_iter().map(|(k, v)| { @@ -1886,6 +1888,24 @@ impl<'a, 'tcx> Lift<'tcx> for &'a List { } } +impl<'a, 'tcx> Lift<'tcx> for &'a List> { + type Lifted = &'tcx List>; + fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { + if self.len() == 0 { + return Some(List::empty()); + } + if tcx.interners.arena.in_arena(*self as *const _) { + return Some(unsafe { mem::transmute(*self) }); + } + // Also try in the global tcx if we're not that. + if !tcx.is_global() { + self.lift_to_tcx(tcx.global_tcx()) + } else { + None + } + } +} + pub mod tls { use super::{GlobalCtxt, TyCtxt}; @@ -2294,6 +2314,13 @@ impl<'tcx: 'lcx, 'lcx> Borrow<[Kind<'lcx>]> for Interned<'tcx, Substs<'tcx>> { } } +impl<'tcx: 'lcx, 'lcx> Borrow<[ProjectionKind<'lcx>]> + for Interned<'tcx, List>> { + fn borrow<'a>(&'a self) -> &'a [ProjectionKind<'lcx>] { + &self.0[..] + } +} + impl<'tcx> Borrow for Interned<'tcx, RegionKind> { fn borrow<'a>(&'a self) -> &'a RegionKind { &self.0 @@ -2441,7 +2468,8 @@ slice_interners!( type_list: _intern_type_list(Ty), substs: _intern_substs(Kind), clauses: _intern_clauses(Clause), - goal_list: _intern_goals(Goal) + goal_list: _intern_goals(Goal), + projs: _intern_projs(ProjectionKind) ); // This isn't a perfect fit: CanonicalVarInfo slices are always @@ -2743,6 +2771,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } + pub fn intern_projs(self, ps: &[ProjectionKind<'tcx>]) -> &'tcx List> { + if ps.len() == 0 { + List::empty() + } else { + self._intern_projs(ps) + } + } + pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'gcx> { if ts.len() == 0 { List::empty() diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 273799bd4bd34..e86a790b5052b 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -13,6 +13,7 @@ //! hand, though we've recently added some macros (e.g., //! `BraceStructLiftImpl!`) to help with the tedium. +use mir::ProjectionKind; use mir::interpret::{ConstValue, ConstEvalErr}; use ty::{self, Lift, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; @@ -786,6 +787,17 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { } } +impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { + fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { + let v = self.iter().map(|t| t.fold_with(folder)).collect::>(); + folder.tcx().intern_projs(&v) + } + + fn super_visit_with>(&self, visitor: &mut V) -> bool { + self.iter().any(|t| t.visit_with(visitor)) + } +} + impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { use ty::InstanceDef::*; diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index da5c5f47c08ac..bf8d02313035c 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -695,7 +695,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { let mut err = self.cannot_act_on_moved_value(use_span, verb, msg, - Some(nl.to_string()), + Some(nl), Origin::Ast); let need_note = match lp.ty.sty { ty::Closure(id, _) => { diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index d9f223daf6091..8aa2e4641d4f9 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -347,7 +347,7 @@ impl<'a, 'tcx> MoveData<'tcx> { lp = base_lp.clone(); } - self.add_move_helper(tcx, orig_lp.clone(), id, kind); + self.add_move_helper(tcx, orig_lp, id, kind); } fn add_move_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -359,7 +359,7 @@ impl<'a, 'tcx> MoveData<'tcx> { id, kind); - let path_index = self.move_path(tcx, lp.clone()); + let path_index = self.move_path(tcx, lp); let move_index = MoveIndex(self.moves.borrow().len()); let next_move = self.path_first_move(path_index); @@ -402,7 +402,7 @@ impl<'a, 'tcx> MoveData<'tcx> { } } - self.add_assignment_helper(tcx, lp.clone(), assign_id, span); + self.add_assignment_helper(tcx, lp, assign_id, span); } fn add_assignment_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 614a562846e86..a9119d49e8b20 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -784,7 +784,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, !tcx.sess.opts.output_types.should_codegen() { let ongoing_codegen = write::start_async_codegen( tcx, - time_graph.clone(), + time_graph, metadata, rx, 1); diff --git a/src/librustc_codegen_llvm/mir/analyze.rs b/src/librustc_codegen_llvm/mir/analyze.rs index a0d6cc4629589..1602ef3c5b795 100644 --- a/src/librustc_codegen_llvm/mir/analyze.rs +++ b/src/librustc_codegen_llvm/mir/analyze.rs @@ -168,7 +168,9 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> { let base_ty = self.fx.monomorphize(&base_ty); // ZSTs don't require any actual memory access. - let elem_ty = base_ty.projection_ty(cx.tcx, &proj.elem).to_ty(cx.tcx); + let elem_ty = base_ty + .projection_ty(cx.tcx, &proj.elem) + .to_ty(cx.tcx); let elem_ty = self.fx.monomorphize(&elem_ty); if cx.layout_of(elem_ty).is_zst() { return; diff --git a/src/librustc_codegen_llvm/mir/place.rs b/src/librustc_codegen_llvm/mir/place.rs index e7b6f5908a4d1..062f7174680db 100644 --- a/src/librustc_codegen_llvm/mir/place.rs +++ b/src/librustc_codegen_llvm/mir/place.rs @@ -517,7 +517,8 @@ impl FunctionCx<'a, 'll, 'tcx> { let mut subslice = cg_base.project_index(bx, C_usize(bx.cx, from as u64)); let projected_ty = PlaceTy::Ty { ty: cg_base.layout.ty } - .projection_ty(tcx, &projection.elem).to_ty(bx.tcx()); + .projection_ty(tcx, &projection.elem) + .to_ty(bx.tcx()); subslice.layout = bx.cx.layout_of(self.monomorphize(&projected_ty)); if subslice.layout.is_unsized() { diff --git a/src/librustc_codegen_utils/link.rs b/src/librustc_codegen_utils/link.rs index 2a1fbe6ace541..66e98793f420d 100644 --- a/src/librustc_codegen_utils/link.rs +++ b/src/librustc_codegen_utils/link.rs @@ -138,7 +138,7 @@ pub fn filename_for_input(sess: &Session, let suffix = &sess.target.target.options.exe_suffix; let out_filename = outputs.path(OutputType::Exe); if suffix.is_empty() { - out_filename.to_path_buf() + out_filename } else { out_filename.with_extension(&suffix[1..]) } diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index b6bb130d3e27f..b2b92a6f85784 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -1615,7 +1615,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { ProjectionElem::Index(..) | ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => { - self.describe_field(&proj.base, field).to_string() + self.describe_field(&proj.base, field) } }, } diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index 495e84528a3c3..1d8d028137a5b 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -18,7 +18,7 @@ use rustc::mir::visit::TyContext; use rustc::mir::visit::Visitor; use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, Rvalue}; use rustc::mir::{Statement, Terminator}; -use rustc::mir::UserTypeAnnotation; +use rustc::mir::UserTypeProjection; use rustc::ty::fold::TypeFoldable; use rustc::ty::subst::Substs; use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid}; @@ -183,7 +183,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx &mut self, _place: &Place<'tcx>, _variance: &ty::Variance, - _user_ty: &UserTypeAnnotation<'tcx>, + _user_ty: &UserTypeProjection<'tcx>, _location: Location, ) { } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index bbbe02fda6a84..953fe0c9521e6 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -284,7 +284,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { if let Err(terr) = self.cx.relate_type_and_user_type( constant.ty, ty::Variance::Invariant, - user_ty, + &UserTypeProjection { base: user_ty, projs: vec![], }, location.to_locations(), ConstraintCategory::Boring, ) { @@ -310,12 +310,12 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { self.super_local_decl(local, local_decl); self.sanitize_type(local_decl, local_decl.ty); - if let Some((user_ty, span)) = local_decl.user_ty { + for (user_ty, span) in local_decl.user_ty.projections_and_spans() { if let Err(terr) = self.cx.relate_type_and_user_type( local_decl.ty, ty::Variance::Invariant, user_ty, - Locations::All(span), + Locations::All(*span), ConstraintCategory::TypeAnnotation, ) { span_mirbug!( @@ -971,7 +971,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { &mut self, a: Ty<'tcx>, v: ty::Variance, - user_ty: UserTypeAnnotation<'tcx>, + user_ty: &UserTypeProjection<'tcx>, locations: Locations, category: ConstraintCategory, ) -> Fallible<()> { @@ -980,7 +980,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { a, v, user_ty, locations, ); - match user_ty { + match user_ty.base { UserTypeAnnotation::Ty(canonical_ty) => { let (ty, _) = self.infcx .instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_ty); @@ -990,6 +990,20 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { // ambient variance to get the right relationship. let v1 = ty::Contravariant.xform(v); + let tcx = self.infcx.tcx; + let mut projected_ty = PlaceTy::from_ty(ty); + for proj in &user_ty.projs { + projected_ty = projected_ty.projection_ty_core( + tcx, proj, |this, field, &()| { + let ty = this.field_ty(tcx, field); + self.normalize(ty, locations) + }); + } + debug!("user_ty base: {:?} freshened: {:?} projs: {:?} yields: {:?}", + user_ty.base, ty, user_ty.projs, projected_ty); + + let ty = projected_ty.to_ty(tcx); + self.relate_types(ty, v1, a, locations, category)?; } UserTypeAnnotation::TypeOf(def_id, canonical_substs) => { @@ -999,11 +1013,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { ) = self.infcx .instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs); + let projs = self.infcx.tcx.intern_projs(&user_ty.projs); self.fully_perform_op( locations, category, self.param_env.and(type_op::ascribe_user_type::AscribeUserType::new( - a, v, def_id, user_substs, + a, v, def_id, user_substs, projs, )), )?; } @@ -1172,7 +1187,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { if let Err(terr) = self.relate_type_and_user_type( rv_ty, ty::Variance::Invariant, - user_ty, + &UserTypeProjection { base: user_ty, projs: vec![], }, location.to_locations(), ConstraintCategory::Boring, ) { @@ -1225,7 +1240,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { ); }; } - StatementKind::AscribeUserType(ref place, variance, c_ty) => { + StatementKind::AscribeUserType(ref place, variance, box ref c_ty) => { let place_ty = place.ty(mir, tcx).to_ty(tcx); if let Err(terr) = self.relate_type_and_user_type( place_ty, diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index b754d63f7183b..aa383a123b69a 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -151,10 +151,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { None, remainder_span, lint_level, slice::from_ref(&pattern), ArmHasGuard(false), None); - this.visit_bindings(&pattern, None, &mut |this, _, _, _, node, span, _, _| { - this.storage_live_binding(block, node, span, OutsideGuard); - this.schedule_drop_for_binding(node, span, OutsideGuard); - }) + this.visit_bindings( + &pattern, + &PatternTypeProjections::none(), + &mut |this, _, _, _, node, span, _, _| { + this.storage_live_binding(block, node, span, OutsideGuard); + this.schedule_drop_for_binding(node, span, OutsideGuard); + }) } // Enter the source scope, after evaluating the initializer. diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 820822b7f5bbd..77746e5538d65 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -147,7 +147,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( place.clone(), Variance::Invariant, - user_ty, + box UserTypeProjection { base: user_ty, projs: vec![], }, ), }, ); @@ -167,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( Place::Local(temp.clone()), Variance::Invariant, - user_ty, + box UserTypeProjection { base: user_ty, projs: vec![], }, ), }, ); diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 4f5ed34a46133..d2913872fca45 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -306,7 +306,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let ptr_temp = this.local_decls.push(LocalDecl { mutability: Mutability::Mut, ty: ptr_ty, - user_ty: None, + user_ty: UserTypeProjections::none(), name: None, source_info, visibility_scope: source_info.scope, diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index a864b39e15791..b92f270255af4 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -18,6 +18,7 @@ use build::ForGuard::{self, OutsideGuard, RefWithinGuard, ValWithinGuard}; use build::{BlockAnd, BlockAndExtension, Builder}; use build::{GuardFrame, GuardFrameLocal, LocalsForNode}; use hair::*; +use hair::pattern::PatternTypeProjections; use rustc::hir; use rustc::mir::*; use rustc::ty::{self, Ty}; @@ -31,6 +32,8 @@ mod simplify; mod test; mod util; +use std::convert::TryFrom; + /// ArmHasGuard is isomorphic to a boolean flag. It indicates whether /// a match arm has a guard expression attached to it. #[derive(Copy, Clone, Debug)] @@ -240,7 +243,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { end_block.unit() } - pub fn expr_into_pattern( + pub(super) fn expr_into_pattern( &mut self, mut block: BasicBlock, irrefutable_pat: Pattern<'tcx>, @@ -265,7 +268,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block, Statement { source_info, - kind: StatementKind::FakeRead(FakeReadCause::ForLet, place.clone()), + kind: StatementKind::FakeRead(FakeReadCause::ForLet, place), }, ); @@ -291,7 +294,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }, .. }, - user_ty: ascription_user_ty, + user_ty: pat_ascription_ty, user_ty_span, } => { let place = @@ -314,9 +317,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { Statement { source_info: ty_source_info, kind: StatementKind::AscribeUserType( - place.clone(), + place, ty::Variance::Invariant, - ascription_user_ty, + box pat_ascription_ty.user_ty(), ), }, ); @@ -415,7 +418,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let num_patterns = patterns.len(); self.visit_bindings( &patterns[0], - None, + &PatternTypeProjections::none(), &mut |this, mutability, name, mode, var, span, ty, user_ty| { if visibility_scope.is_none() { visibility_scope = @@ -488,10 +491,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ); } - pub fn visit_bindings( + pub(super) fn visit_bindings( &mut self, pattern: &Pattern<'tcx>, - mut pattern_user_ty: Option<(UserTypeAnnotation<'tcx>, Span)>, + pattern_user_ty: &PatternTypeProjections<'tcx>, f: &mut impl FnMut( &mut Self, Mutability, @@ -500,7 +503,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { NodeId, Span, Ty<'tcx>, - Option<(UserTypeAnnotation<'tcx>, Span)>, + &PatternTypeProjections<'tcx>, ), ) { match *pattern.kind { @@ -513,20 +516,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ref subpattern, .. } => { - match mode { - BindingMode::ByValue => { } + let pattern_ref_binding; // sidestep temp lifetime limitations. + let binding_user_ty = match mode { + BindingMode::ByValue => { pattern_user_ty } BindingMode::ByRef(..) => { // If this is a `ref` binding (e.g., `let ref // x: T = ..`), then the type of `x` is not - // `T` but rather `&T`, so ignore - // `pattern_user_ty` for now. - // - // FIXME(#47184): extract or handle `pattern_user_ty` somehow - pattern_user_ty = None; + // `T` but rather `&T`. + pattern_ref_binding = pattern_user_ty.ref_binding(); + &pattern_ref_binding } - } + }; - f(self, mutability, name, mode, var, pattern.span, ty, pattern_user_ty); + f(self, mutability, name, mode, var, pattern.span, ty, binding_user_ty); if let Some(subpattern) = subpattern.as_ref() { self.visit_bindings(subpattern, pattern_user_ty, f); } @@ -541,33 +543,44 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ref slice, ref suffix, } => { - // FIXME(#47184): extract or handle `pattern_user_ty` somehow - for subpattern in prefix.iter().chain(slice).chain(suffix) { - self.visit_bindings(subpattern, None, f); + let from = u32::try_from(prefix.len()).unwrap(); + let to = u32::try_from(suffix.len()).unwrap(); + for subpattern in prefix { + self.visit_bindings(subpattern, &pattern_user_ty.index(), f); + } + for subpattern in slice { + self.visit_bindings(subpattern, &pattern_user_ty.subslice(from, to), f); + } + for subpattern in suffix { + self.visit_bindings(subpattern, &pattern_user_ty.index(), f); } } PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {} PatternKind::Deref { ref subpattern } => { - // FIXME(#47184): extract or handle `pattern_user_ty` somehow - self.visit_bindings(subpattern, None, f); + self.visit_bindings(subpattern, &pattern_user_ty.deref(), f); } - PatternKind::AscribeUserType { ref subpattern, user_ty, user_ty_span } => { + PatternKind::AscribeUserType { ref subpattern, ref user_ty, user_ty_span } => { // This corresponds to something like // // ``` // let A::<'a>(_): A<'static> = ...; // ``` - // - // FIXME(#47184): handle `pattern_user_ty` somehow - self.visit_bindings(subpattern, Some((user_ty, user_ty_span)), f) + let subpattern_user_ty = pattern_user_ty.add_user_type(user_ty, user_ty_span); + self.visit_bindings(subpattern, &subpattern_user_ty, f) } - PatternKind::Leaf { ref subpatterns } - | PatternKind::Variant { - ref subpatterns, .. - } => { - // FIXME(#47184): extract or handle `pattern_user_ty` somehow + + PatternKind::Leaf { ref subpatterns } => { + for subpattern in subpatterns { + let subpattern_user_ty = pattern_user_ty.leaf(subpattern.field); + self.visit_bindings(&subpattern.pattern, &subpattern_user_ty, f); + } + } + + PatternKind::Variant { adt_def, substs: _, variant_index, ref subpatterns } => { for subpattern in subpatterns { - self.visit_bindings(&subpattern.pattern, None, f); + let subpattern_user_ty = pattern_user_ty.variant( + adt_def, variant_index, subpattern.field); + self.visit_bindings(&subpattern.pattern, &subpattern_user_ty, f); } } } @@ -626,7 +639,7 @@ struct Binding<'tcx> { struct Ascription<'tcx> { span: Span, source: Place<'tcx>, - user_ty: UserTypeAnnotation<'tcx>, + user_ty: PatternTypeProjection<'tcx>, } #[derive(Clone, Debug)] @@ -1323,7 +1336,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( ascription.source.clone(), ty::Variance::Covariant, - ascription.user_ty, + box ascription.user_ty.clone().user_ty(), ), }, ); @@ -1470,7 +1483,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { num_patterns: usize, var_id: NodeId, var_ty: Ty<'tcx>, - user_var_ty: Option<(UserTypeAnnotation<'tcx>, Span)>, + user_var_ty: &PatternTypeProjections<'tcx>, has_guard: ArmHasGuard, opt_match_place: Option<(Option>, Span)>, pat_span: Span, @@ -1489,7 +1502,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let local = LocalDecl::<'tcx> { mutability, ty: var_ty, - user_ty: user_var_ty, + user_ty: user_var_ty.clone().user_ty(), name: Some(name), source_info, visibility_scope, @@ -1522,7 +1535,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // See previous comment. mutability: Mutability::Not, ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), - user_ty: None, + user_ty: UserTypeProjections::none(), name: Some(name), source_info, visibility_scope, diff --git a/src/librustc_mir/build/matches/simplify.rs b/src/librustc_mir/build/matches/simplify.rs index 494e7c03c3e68..349d877d52474 100644 --- a/src/librustc_mir/build/matches/simplify.rs +++ b/src/librustc_mir/build/matches/simplify.rs @@ -63,10 +63,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { candidate: &mut Candidate<'pat, 'tcx>) -> Result<(), MatchPair<'pat, 'tcx>> { match *match_pair.pattern.kind { - PatternKind::AscribeUserType { ref subpattern, user_ty, user_ty_span } => { + PatternKind::AscribeUserType { ref subpattern, ref user_ty, user_ty_span } => { candidate.ascriptions.push(Ascription { span: user_ty_span, - user_ty, + user_ty: user_ty.clone(), source: match_pair.place.clone(), }); diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index c7da9c4fbd792..9e6f32909bdea 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -324,7 +324,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let ref_ty = self.hir.tcx().mk_ref(region, tam); // let lhs_ref_place = &lhs; - let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place.clone()); + let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place); let lhs_ref_place = self.temp(ref_ty, test.span); self.cfg.push_assign(block, source_info, &lhs_ref_place, ref_rvalue); let val = Operand::Move(lhs_ref_place); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index e6dd0107e9198..5b4001f0652ad 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -644,7 +644,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, }).collect() }); - let mut builder = Builder::new(hir.clone(), + let mut builder = Builder::new(hir, span, arguments.len(), safety, @@ -714,7 +714,7 @@ fn construct_const<'a, 'gcx, 'tcx>( let ty = hir.tables().expr_ty_adjusted(ast_expr); let owner_id = tcx.hir.body_owner(body_id); let span = tcx.hir.span(owner_id); - let mut builder = Builder::new(hir.clone(), span, 0, Safety::Safe, ty, ty_span,vec![]); + let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span,vec![]); let mut block = START_BLOCK; let expr = builder.hir.mirror(ast_expr); @@ -845,7 +845,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.local_decls.push(LocalDecl { mutability: Mutability::Mut, ty, - user_ty: None, + user_ty: UserTypeProjections::none(), source_info, visibility_scope: source_info.scope, name, diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 9865867a196ca..586d6d87fa0dc 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -91,7 +91,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, ty: pattern.ty, span: pattern.span, kind: Box::new(PatternKind::AscribeUserType { - user_ty: UserTypeAnnotation::Ty(user_ty), + user_ty: PatternTypeProjection::from_canonical_ty(user_ty), user_ty_span: ty.span, subpattern: pattern }) diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 788db5c0b7e52..8a24851de8149 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -28,6 +28,7 @@ pub mod cx; pub mod pattern; pub use self::pattern::{BindingMode, Pattern, PatternKind, FieldPattern}; +pub(crate) use self::pattern::{PatternTypeProjection, PatternTypeProjections}; mod util; diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index cb974366a3029..f70e93182c818 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -20,7 +20,8 @@ use const_eval::{const_field, const_variant_index}; use hair::util::UserAnnotatedTyHelpers; -use rustc::mir::{fmt_const_val, Field, BorrowKind, Mutability, UserTypeAnnotation}; +use rustc::mir::{fmt_const_val, Field, BorrowKind, Mutability}; +use rustc::mir::{ProjectionElem, UserTypeAnnotation, UserTypeProjection, UserTypeProjections}; use rustc::mir::interpret::{Scalar, GlobalId, ConstValue, sign_extend}; use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty}; use rustc::ty::subst::{Substs, Kind}; @@ -64,12 +65,123 @@ pub struct Pattern<'tcx> { pub kind: Box>, } + +#[derive(Clone, Debug)] +pub(crate) struct PatternTypeProjections<'tcx> { + contents: Vec<(PatternTypeProjection<'tcx>, Span)>, +} + +impl<'tcx> PatternTypeProjections<'tcx> { + pub(crate) fn user_ty(self) -> UserTypeProjections<'tcx> { + UserTypeProjections::from_projections( + self.contents.into_iter().map(|(pat_ty_proj, span)| (pat_ty_proj.user_ty(), span))) + } + + pub(crate) fn none() -> Self { + PatternTypeProjections { contents: vec![] } + } + + pub(crate) fn ref_binding(&self) -> Self { + // FIXME(#47184): ignore for now + PatternTypeProjections { contents: vec![] } + } + + fn map_projs(&self, + mut f: impl FnMut(&PatternTypeProjection<'tcx>) -> PatternTypeProjection<'tcx>) + -> Self + { + PatternTypeProjections { + contents: self.contents + .iter() + .map(|(proj, span)| (f(proj), *span)) + .collect(), } + } + + pub(crate) fn index(&self) -> Self { self.map_projs(|pat_ty_proj| pat_ty_proj.index()) } + + pub(crate) fn subslice(&self, from: u32, to: u32) -> Self { + self.map_projs(|pat_ty_proj| pat_ty_proj.subslice(from, to)) + } + + pub(crate) fn deref(&self) -> Self { self.map_projs(|pat_ty_proj| pat_ty_proj.deref()) } + + pub(crate) fn leaf(&self, field: Field) -> Self { + self.map_projs(|pat_ty_proj| pat_ty_proj.leaf(field)) + } + + pub(crate) fn variant(&self, + adt_def: &'tcx AdtDef, + variant_index: usize, + field: Field) -> Self { + self.map_projs(|pat_ty_proj| pat_ty_proj.variant(adt_def, variant_index, field)) + } + + pub(crate) fn add_user_type(&self, user_ty: &PatternTypeProjection<'tcx>, sp: Span) -> Self { + let mut new = self.clone(); + new.contents.push((user_ty.clone(), sp)); + new + } +} + +#[derive(Clone, Debug)] +pub struct PatternTypeProjection<'tcx>(UserTypeProjection<'tcx>); + +impl<'tcx> PatternTypeProjection<'tcx> { + pub(crate) fn index(&self) -> Self { + let mut new = self.clone(); + new.0.projs.push(ProjectionElem::Index(())); + new + } + + pub(crate) fn subslice(&self, from: u32, to: u32) -> Self { + let mut new = self.clone(); + new.0.projs.push(ProjectionElem::Subslice { from, to }); + new + } + + pub(crate) fn deref(&self) -> Self { + let mut new = self.clone(); + new.0.projs.push(ProjectionElem::Deref); + new + } + + pub(crate) fn leaf(&self, field: Field) -> Self { + let mut new = self.clone(); + new.0.projs.push(ProjectionElem::Field(field, ())); + new + } + + pub(crate) fn variant(&self, + adt_def: &'tcx AdtDef, + variant_index: usize, + field: Field) -> Self { + let mut new = self.clone(); + new.0.projs.push(ProjectionElem::Downcast(adt_def, variant_index)); + new.0.projs.push(ProjectionElem::Field(field, ())); + new + } + + pub(crate) fn from_canonical_ty(c_ty: ty::CanonicalTy<'tcx>) -> Self { + Self::from_user_type(UserTypeAnnotation::Ty(c_ty)) + } + + pub(crate) fn from_user_type(u_ty: UserTypeAnnotation<'tcx>) -> Self { + Self::from_user_type_proj(UserTypeProjection { base: u_ty, projs: vec![], }) + } + + pub(crate) fn from_user_type_proj(u_ty: UserTypeProjection<'tcx>) -> Self { + PatternTypeProjection(u_ty) + } + + pub(crate) fn user_ty(self) -> UserTypeProjection<'tcx> { self.0 } +} + #[derive(Clone, Debug)] pub enum PatternKind<'tcx> { Wild, AscribeUserType { - user_ty: UserTypeAnnotation<'tcx>, + user_ty: PatternTypeProjection<'tcx>, subpattern: Pattern<'tcx>, user_ty_span: Span, }, @@ -690,9 +802,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { debug!("pattern user_ty = {:?} for pattern at {:?}", user_ty, span); + let pat_ty = PatternTypeProjection::from_user_type(user_ty); kind = PatternKind::AscribeUserType { subpattern, - user_ty, + user_ty: pat_ty, user_ty_span: span, }; } @@ -980,7 +1093,8 @@ macro_rules! CloneImpls { CloneImpls!{ <'tcx> Span, Field, Mutability, ast::Name, ast::NodeId, usize, &'tcx ty::Const<'tcx>, Region<'tcx>, Ty<'tcx>, BindingMode<'tcx>, &'tcx AdtDef, - &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserTypeAnnotation<'tcx> + &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserTypeAnnotation<'tcx>, + UserTypeProjection<'tcx>, PatternTypeProjection<'tcx> } impl<'tcx> PatternFoldable<'tcx> for FieldPattern<'tcx> { @@ -1016,7 +1130,7 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> { PatternKind::Wild => PatternKind::Wild, PatternKind::AscribeUserType { ref subpattern, - user_ty, + ref user_ty, user_ty_span, } => PatternKind::AscribeUserType { subpattern: subpattern.fold_with(folder), diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 4b26094b9fc28..6c32690cdb340 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -142,7 +142,7 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { LocalDecl { mutability, ty, - user_ty: None, + user_ty: UserTypeProjections::none(), name: None, source_info, visibility_scope: source_info.scope, @@ -547,7 +547,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> { // `dest[i] = Clone::clone(src[beg])`; // Goto #3 if ok, #5 if unwinding happens. let dest_field = dest.clone().index(beg); - let src_field = src.clone().index(beg); + let src_field = src.index(beg); self.make_clone_call(dest_field, src_field, ty, BasicBlock::new(3), BasicBlock::new(5)); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index c2ae6832cc09f..5889fabee9d6e 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -303,7 +303,7 @@ fn replace_result_variable<'tcx>( let new_ret = LocalDecl { mutability: Mutability::Mut, ty: ret_ty, - user_ty: None, + user_ty: UserTypeProjections::none(), name: None, source_info, visibility_scope: source_info.scope, @@ -658,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>( mir.local_decls[RETURN_PLACE] = LocalDecl { mutability: Mutability::Mut, ty: tcx.mk_unit(), - user_ty: None, + user_ty: UserTypeProjections::none(), name: None, source_info, visibility_scope: source_info.scope, @@ -676,7 +676,7 @@ fn create_generator_drop_shim<'a, 'tcx>( ty: gen_ty, mutbl: hir::Mutability::MutMutable, }), - user_ty: None, + user_ty: UserTypeProjections::none(), name: None, source_info, visibility_scope: source_info.scope, diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 1dca367ffdf5f..d9a1e4a0fd639 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -753,11 +753,11 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> self.place.clone() ))); drop_block_stmts.push(self.assign(&cur, Rvalue::Cast( - CastKind::Misc, Operand::Move(tmp.clone()), iter_ty + CastKind::Misc, Operand::Move(tmp), iter_ty ))); drop_block_stmts.push(self.assign(&length_or_end, Rvalue::BinaryOp(BinOp::Offset, - Operand::Copy(cur.clone()), Operand::Move(length.clone()) + Operand::Copy(cur), Operand::Move(length) ))); } else { // index = 0 (length already pushed) diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 25bd02ff6dc5d..c74492fe64936 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -502,7 +502,7 @@ fn write_scope_tree( local, var.ty ); - if let Some(user_ty) = var.user_ty { + for user_ty in var.user_ty.projections() { write!(indented_var, " as {:?}", user_ty).unwrap(); } indented_var.push_str(";"); diff --git a/src/librustc_passes/mir_stats.rs b/src/librustc_passes/mir_stats.rs index 0b9b20d3c4539..06c8545aacfd8 100644 --- a/src/librustc_passes/mir_stats.rs +++ b/src/librustc_passes/mir_stats.rs @@ -211,7 +211,6 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> { fn visit_projection_elem(&mut self, place: &PlaceElem<'tcx>, - context: mir_visit::PlaceContext<'tcx>, location: Location) { self.record("PlaceElem", place); self.record(match *place { @@ -222,7 +221,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> { ProjectionElem::ConstantIndex { .. } => "PlaceElem::ConstantIndex", ProjectionElem::Downcast(..) => "PlaceElem::Downcast", }, place); - self.super_projection_elem(place, context, location); + self.super_projection_elem(place, location); } fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index aa7bfeae5f48b..1b7225123abca 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -35,7 +35,7 @@ use syntax::ast::{Name, Ident}; use syntax::attr; use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId}; -use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind, Variant}; +use syntax::ast::{MetaItemKind, Mutability, StmtKind, TraitItem, TraitItemKind, Variant}; use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::base::Determinacy::Undetermined; use syntax::ext::hygiene::Mark; @@ -83,12 +83,6 @@ impl<'a> ToNameBinding<'a> for (Def, ty::Visibility, Span, Mark, IsMacroExport) } } -#[derive(Default, PartialEq, Eq)] -struct LegacyMacroImports { - import_all: Option, - imports: Vec<(Name, Span)>, -} - impl<'a, 'cl> Resolver<'a, 'cl> { /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined; /// otherwise, reports an error. @@ -117,23 +111,23 @@ impl<'a, 'cl> Resolver<'a, 'cl> { fn build_reduced_graph_for_use_tree( &mut self, - root_use_tree: &ast::UseTree, - root_id: NodeId, + // This particular use tree use_tree: &ast::UseTree, id: NodeId, - vis: ty::Visibility, parent_prefix: &[Ident], - mut uniform_paths_canary_emitted: bool, nested: bool, + mut uniform_paths_canary_emitted: bool, + // The whole `use` item + parent_scope: ParentScope<'a>, item: &Item, - expansion: Mark, + vis: ty::Visibility, + root_span: Span, ) { debug!("build_reduced_graph_for_use_tree(parent_prefix={:?}, \ uniform_paths_canary_emitted={}, \ use_tree={:?}, nested={})", parent_prefix, uniform_paths_canary_emitted, use_tree, nested); - let is_prelude = attr::contains_name(&item.attrs, "prelude_import"); let uniform_paths = self.session.rust_2018() && self.session.features_untracked().uniform_paths; @@ -218,13 +212,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> { }; this.add_import_directive( base.into_iter().collect(), - subclass.clone(), + subclass, source.span, id, - root_use_tree.span, - root_id, + root_span, + item.id, ty::Visibility::Invisible, - expansion, + parent_scope.clone(), true, // is_uniform_paths_canary ); }; @@ -256,6 +250,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { uniform_paths_canary_emitted = true; } + let empty_for_self = |prefix: &[Ident]| { + prefix.is_empty() || + prefix.len() == 1 && prefix[0].name == keywords::CrateRoot.name() + }; match use_tree.kind { ast::UseTreeKind::Simple(rename, ..) => { let mut ident = use_tree.ident(); @@ -268,10 +266,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { if source.name == keywords::SelfValue.name() { type_ns_only = true; - let empty_prefix = module_path.last().map_or(true, |ident| { - ident.name == keywords::CrateRoot.name() - }); - if empty_prefix { + if empty_for_self(&module_path) { resolve_error( self, use_tree.span, @@ -345,16 +340,16 @@ impl<'a, 'cl> Resolver<'a, 'cl> { subclass, use_tree.span, id, - root_use_tree.span, - root_id, + root_span, + item.id, vis, - expansion, + parent_scope, false, // is_uniform_paths_canary ); } ast::UseTreeKind::Glob => { let subclass = GlobImport { - is_prelude, + is_prelude: attr::contains_name(&item.attrs, "prelude_import"), max_vis: Cell::new(ty::Visibility::Invisible), }; self.add_import_directive( @@ -362,10 +357,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { subclass, use_tree.span, id, - root_use_tree.span, - root_id, + root_span, + item.id, vis, - expansion, + parent_scope, false, // is_uniform_paths_canary ); } @@ -394,16 +389,34 @@ impl<'a, 'cl> Resolver<'a, 'cl> { for &(ref tree, id) in items { self.build_reduced_graph_for_use_tree( - root_use_tree, - root_id, - tree, - id, - vis, - &prefix, - uniform_paths_canary_emitted, - true, - item, - expansion, + // This particular use tree + tree, id, &prefix, true, uniform_paths_canary_emitted, + // The whole `use` item + parent_scope.clone(), item, vis, root_span, + ); + } + + // Empty groups `a::b::{}` are turned into synthetic `self` imports + // `a::b::c::{self as _}`, so that their prefixes are correctly + // resolved and checked for privacy/stability/etc. + if items.is_empty() && !empty_for_self(&prefix) { + let new_span = prefix[prefix.len() - 1].span; + let tree = ast::UseTree { + prefix: ast::Path::from_ident( + Ident::new(keywords::SelfValue.name(), new_span) + ), + kind: ast::UseTreeKind::Simple( + Some(Ident::new(keywords::Underscore.name().gensymed(), new_span)), + ast::DUMMY_NODE_ID, + ast::DUMMY_NODE_ID, + ), + span: use_tree.span, + }; + self.build_reduced_graph_for_use_tree( + // This particular use tree + &tree, id, &prefix, true, uniform_paths_canary_emitted, + // The whole `use` item + parent_scope.clone(), item, ty::Visibility::Invisible, root_span, ); } } @@ -411,8 +424,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } /// Constructs the reduced graph for one item. - fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) { - let parent = self.current_module; + fn build_reduced_graph_for_item(&mut self, item: &Item, parent_scope: ParentScope<'a>) { + let parent = parent_scope.module; + let expansion = parent_scope.expansion; let ident = item.ident; let sp = item.span; let vis = self.resolve_visibility(&item.vis); @@ -420,16 +434,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { match item.node { ItemKind::Use(ref use_tree) => { self.build_reduced_graph_for_use_tree( - use_tree, - item.id, - use_tree, - item.id, - vis, - &[], - false, // uniform_paths_canary_emitted - false, - item, - expansion, + // This particular use tree + use_tree, item.id, &[], false, false, + // The whole `use` item + parent_scope, item, vis, use_tree.span, ); } @@ -442,7 +450,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { self.injected_crate = Some(module); } - let used = self.process_legacy_macro_imports(item, module, expansion); + let used = self.process_legacy_macro_imports(item, module, &parent_scope); let binding = (module, ty::Visibility::Public, sp, expansion).to_name_binding(self.arenas); if ptr::eq(self.current_module, self.graph_root) { @@ -467,7 +475,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { let directive = self.arenas.alloc_import_directive(ImportDirective { root_id: item.id, id: item.id, - parent, + parent_scope, imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))), subclass: ImportDirectiveSubclass::ExternCrate { source: orig_name, @@ -477,7 +485,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> { span: item.span, module_path: Vec::new(), vis: Cell::new(vis), - expansion, used: Cell::new(used), is_uniform_paths_canary: false, }); @@ -850,35 +857,53 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } // This returns true if we should consider the underlying `extern crate` to be used. - fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, expansion: Mark) - -> bool { - let allow_shadowing = expansion == Mark::root(); - let legacy_imports = self.legacy_macro_imports(&item.attrs); - let used = legacy_imports != LegacyMacroImports::default(); - - // `#[macro_use]` is only allowed at the crate root. - if self.current_module.parent.is_some() && used { - span_err!(self.session, item.span, E0468, - "an `extern crate` loading macros must be at the crate root"); + fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, + parent_scope: &ParentScope<'a>) -> bool { + let mut import_all = None; + let mut single_imports = Vec::new(); + for attr in &item.attrs { + if attr.check_name("macro_use") { + if self.current_module.parent.is_some() { + span_err!(self.session, item.span, E0468, + "an `extern crate` loading macros must be at the crate root"); + } + let ill_formed = |span| span_err!(self.session, span, E0466, "bad macro import"); + match attr.meta() { + Some(meta) => match meta.node { + MetaItemKind::Word => { + import_all = Some(meta.span); + break; + } + MetaItemKind::List(nested_metas) => for nested_meta in nested_metas { + match nested_meta.word() { + Some(word) => single_imports.push((word.name(), word.span)), + None => ill_formed(nested_meta.span), + } + } + MetaItemKind::NameValue(..) => ill_formed(meta.span), + } + None => ill_formed(attr.span()), + } + } } - let (graph_root, arenas) = (self.graph_root, self.arenas); + let arenas = self.arenas; let macro_use_directive = |span| arenas.alloc_import_directive(ImportDirective { root_id: item.id, id: item.id, - parent: graph_root, + parent_scope: parent_scope.clone(), imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))), subclass: ImportDirectiveSubclass::MacroUse, root_span: span, span, module_path: Vec::new(), vis: Cell::new(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))), - expansion, used: Cell::new(false), is_uniform_paths_canary: false, }); - if let Some(span) = legacy_imports.import_all { + let allow_shadowing = parent_scope.expansion == Mark::root(); + if let Some(span) = import_all { let directive = macro_use_directive(span); self.potentially_unused_imports.push(directive); module.for_each_child(|ident, ns, binding| if ns == MacroNS { @@ -886,7 +911,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { self.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing); }); } else { - for (name, span) in legacy_imports.imports { + for (name, span) in single_imports.iter().cloned() { let ident = Ident::with_empty_ctxt(name); let result = self.resolve_ident_in_module( ModuleOrUniformRoot::Module(module), @@ -905,7 +930,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } } } - used + import_all.is_some() || !single_imports.is_empty() } // does this attribute list contain "macro_use"? @@ -931,25 +956,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> { false } - - fn legacy_macro_imports(&mut self, attrs: &[ast::Attribute]) -> LegacyMacroImports { - let mut imports = LegacyMacroImports::default(); - for attr in attrs { - if attr.check_name("macro_use") { - match attr.meta_item_list() { - Some(names) => for attr in names { - if let Some(word) = attr.word() { - imports.imports.push((word.name(), attr.span())); - } else { - span_err!(self.session, attr.span(), E0466, "bad macro import"); - } - }, - None => imports.import_all = Some(attr.span), - } - } - } - imports - } } pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> { @@ -1004,7 +1010,13 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> { let orig_current_module = self.resolver.current_module; let orig_current_legacy_scope = self.current_legacy_scope; - self.resolver.build_reduced_graph_for_item(item, self.expansion); + let parent_scope = ParentScope { + module: self.resolver.current_module, + expansion: self.expansion, + legacy: self.current_legacy_scope, + derives: Vec::new(), + }; + self.resolver.build_reduced_graph_for_item(item, parent_scope); visit::walk_item(self, item); self.resolver.current_module = orig_current_module; if !macro_use { diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs index 6fcee4051ac37..887eea4c8f9f0 100644 --- a/src/librustc_resolve/error_reporting.rs +++ b/src/librustc_resolve/error_reporting.rs @@ -9,6 +9,7 @@ // except according to those terms. use {CrateLint, PathResult}; +use macros::ParentScope; use std::collections::BTreeSet; @@ -23,8 +24,9 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { pub(crate) fn make_path_suggestion( &mut self, span: Span, - path: Vec - ) -> Option> { + path: Vec, + parent_scope: &ParentScope<'b>, + ) -> Option<(Vec, Option)> { debug!("make_path_suggestion: span={:?} path={:?}", span, path); // If we don't have a path to suggest changes to, then return. if path.is_empty() { @@ -40,10 +42,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { (Some(fst), Some(snd)) if !is_special(*fst) && !is_special(*snd) => { debug!("make_path_suggestion: fst={:?} snd={:?}", fst, snd); - self.make_missing_self_suggestion(span, path.clone()) - .or_else(|| self.make_missing_crate_suggestion(span, path.clone())) - .or_else(|| self.make_missing_super_suggestion(span, path.clone())) - .or_else(|| self.make_external_crate_suggestion(span, path.clone())) + self.make_missing_self_suggestion(span, path.clone(), parent_scope) + .or_else(|| self.make_missing_crate_suggestion(span, path.clone(), + parent_scope)) + .or_else(|| self.make_missing_super_suggestion(span, path.clone(), + parent_scope)) + .or_else(|| self.make_external_crate_suggestion(span, path, parent_scope)) }, _ => None, } @@ -59,14 +63,15 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_missing_self_suggestion( &mut self, span: Span, - mut path: Vec - ) -> Option> { + mut path: Vec, + parent_scope: &ParentScope<'b>, + ) -> Option<(Vec, Option)> { // Replace first ident with `self` and check if that is valid. path[0].name = keywords::SelfValue.name(); - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { - Some(path) + Some((path, None)) } else { None } @@ -82,14 +87,22 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_missing_crate_suggestion( &mut self, span: Span, - mut path: Vec - ) -> Option> { + mut path: Vec, + parent_scope: &ParentScope<'b>, + ) -> Option<(Vec, Option)> { // Replace first ident with `crate` and check if that is valid. path[0].name = keywords::Crate.name(); - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { - Some(path) + Some(( + path, + Some( + "`use` statements changed in Rust 2018; read more at \ + ".to_string() + ), + )) } else { None } @@ -105,14 +118,15 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_missing_super_suggestion( &mut self, span: Span, - mut path: Vec - ) -> Option> { + mut path: Vec, + parent_scope: &ParentScope<'b>, + ) -> Option<(Vec, Option)> { // Replace first ident with `crate` and check if that is valid. path[0].name = keywords::Super.name(); - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { - Some(path) + Some((path, None)) } else { None } @@ -131,8 +145,9 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_external_crate_suggestion( &mut self, span: Span, - mut path: Vec - ) -> Option> { + mut path: Vec, + parent_scope: &ParentScope<'b>, + ) -> Option<(Vec, Option)> { // Need to clone else we can't call `resolve_path` without a borrow error. We also store // into a `BTreeMap` so we can get consistent ordering (and therefore the same diagnostic) // each time. @@ -149,11 +164,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { // Replace the first after root (a placeholder we inserted) with a crate name // and check if that is valid. path[1].name = *name; - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = + self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_external_crate_suggestion: name={:?} path={:?} result={:?}", name, path, result); if let PathResult::Module(..) = result { - return Some(path) + return Some((path, None)); } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2c21067bd58c8..e30b5cfa37782 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -482,15 +482,13 @@ enum PathSource<'a> { TraitItem(Namespace), // Path in `pub(path)` Visibility, - // Path in `use a::b::{...};` - ImportPrefix, } impl<'a> PathSource<'a> { fn namespace(self) -> Namespace { match self { PathSource::Type | PathSource::Trait(_) | PathSource::Struct | - PathSource::Visibility | PathSource::ImportPrefix => TypeNS, + PathSource::Visibility => TypeNS, PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct => ValueNS, PathSource::TraitItem(ns) => ns, } @@ -498,7 +496,7 @@ impl<'a> PathSource<'a> { fn global_by_default(self) -> bool { match self { - PathSource::Visibility | PathSource::ImportPrefix => true, + PathSource::Visibility => true, PathSource::Type | PathSource::Expr(..) | PathSource::Pat | PathSource::Struct | PathSource::TupleStruct | PathSource::Trait(_) | PathSource::TraitItem(..) => false, @@ -510,7 +508,7 @@ impl<'a> PathSource<'a> { PathSource::Type | PathSource::Expr(..) | PathSource::Pat | PathSource::Struct | PathSource::TupleStruct => true, PathSource::Trait(_) | PathSource::TraitItem(..) | - PathSource::Visibility | PathSource::ImportPrefix => false, + PathSource::Visibility => false, } } @@ -522,7 +520,6 @@ impl<'a> PathSource<'a> { PathSource::Struct => "struct, variant or union type", PathSource::TupleStruct => "tuple struct/variant", PathSource::Visibility => "module", - PathSource::ImportPrefix => "module or enum", PathSource::TraitItem(ns) => match ns { TypeNS => "associated type", ValueNS => "method or associated constant", @@ -587,10 +584,6 @@ impl<'a> PathSource<'a> { Def::AssociatedTy(..) if ns == TypeNS => true, _ => false, }, - PathSource::ImportPrefix => match def { - Def::Mod(..) | Def::Enum(..) => true, - _ => false, - }, PathSource::Visibility => match def { Def::Mod(..) => true, _ => false, @@ -626,8 +619,8 @@ impl<'a> PathSource<'a> { (PathSource::Pat, false) | (PathSource::TupleStruct, false) => "E0531", (PathSource::TraitItem(..), true) => "E0575", (PathSource::TraitItem(..), false) => "E0576", - (PathSource::Visibility, true) | (PathSource::ImportPrefix, true) => "E0577", - (PathSource::Visibility, false) | (PathSource::ImportPrefix, false) => "E0578", + (PathSource::Visibility, true) => "E0577", + (PathSource::Visibility, false) => "E0578", } } } @@ -1017,7 +1010,7 @@ pub struct ModuleData<'a> { resolutions: RefCell>>>, legacy_macro_resolutions: RefCell, Option<&'a NameBinding<'a>>)>>, - macro_resolutions: RefCell, Span)>>, + macro_resolutions: RefCell, ParentScope<'a>, Span)>>, builtin_attrs: RefCell)>>, // Macro invocations that can expand into items in this module. @@ -1170,7 +1163,7 @@ enum NameBindingKind<'a> { } } -struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>); +struct PrivacyError<'a>(Span, Ident, &'a NameBinding<'a>); struct UseError<'a> { err: DiagnosticBuilder<'a>, @@ -1628,22 +1621,16 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let hir::Path { ref segments, span, ref mut def } = *path; let path: Vec<_> = segments.iter().map(|seg| seg.ident).collect(); // FIXME (Manishearth): Intra doc links won't get warned of epoch changes - match self.resolve_path(None, &path, Some(namespace), true, span, CrateLint::No) { + match self.resolve_path_without_parent_scope(None, &path, Some(namespace), true, span, + CrateLint::No) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => *def = module.def().unwrap(), PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => *def = path_res.base_def(), - PathResult::NonModule(..) => - if let PathResult::Failed(span, msg, _) = self.resolve_path( - None, - &path, - None, - true, - span, - CrateLint::No, - ) { - error_callback(self, span, ResolutionError::FailedToResolve(&msg)); - }, + PathResult::NonModule(..) => { + let msg = "type-relative paths are not supported in this context"; + error_callback(self, span, ResolutionError::FailedToResolve(msg)); + } PathResult::Module(ModuleOrUniformRoot::UniformRoot(_)) | PathResult::Indeterminate => unreachable!(), PathResult::Failed(span, msg, _) => { @@ -2297,16 +2284,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { }); } - ItemKind::Use(ref use_tree) => { - // Imports are resolved as global by default, add starting root segment. - let path = Path { - segments: use_tree.prefix.make_root().into_iter().collect(), - span: use_tree.span, - }; - self.resolve_use_tree(item.id, use_tree.span, item.id, use_tree, &path); - } - - ItemKind::ExternCrate(_) | ItemKind::MacroDef(..) | ItemKind::GlobalAsm(_) => { + ItemKind::Use(..) | ItemKind::ExternCrate(..) | + ItemKind::MacroDef(..) | ItemKind::GlobalAsm(..) => { // do nothing, these are just around to be encoded } @@ -2314,49 +2293,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } } - /// For the most part, use trees are desugared into `ImportDirective` instances - /// when building the reduced graph (see `build_reduced_graph_for_use_tree`). But - /// there is one special case we handle here: an empty nested import like - /// `a::{b::{}}`, which desugares into...no import directives. - fn resolve_use_tree( - &mut self, - root_id: NodeId, - root_span: Span, - id: NodeId, - use_tree: &ast::UseTree, - prefix: &Path, - ) { - match use_tree.kind { - ast::UseTreeKind::Nested(ref items) => { - let path = Path { - segments: prefix.segments - .iter() - .chain(use_tree.prefix.segments.iter()) - .cloned() - .collect(), - span: prefix.span.to(use_tree.prefix.span), - }; - - if items.is_empty() { - // Resolve prefix of an import with empty braces (issue #28388). - self.smart_resolve_path_with_crate_lint( - id, - None, - &path, - PathSource::ImportPrefix, - CrateLint::UsePath { root_id, root_span }, - ); - } else { - for &(ref tree, nested_id) in items { - self.resolve_use_tree(root_id, root_span, nested_id, tree, &path); - } - } - } - ast::UseTreeKind::Simple(..) => {}, - ast::UseTreeKind::Glob => {}, - } - } - fn with_type_parameter_rib<'b, F>(&'b mut self, type_parameters: TypeParameters<'a, 'b>, f: F) where F: FnOnce(&mut Resolver) { @@ -2472,10 +2408,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { new_id = Some(def.def_id()); let span = trait_ref.path.span; if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path( + self.resolve_path_without_parent_scope( None, &path, - None, + Some(TypeNS), false, span, CrateLint::SimplePath(trait_ref.ref_id), @@ -2993,8 +2929,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { (String::new(), "the crate root".to_string()) } else { let mod_path = &path[..path.len() - 1]; - let mod_prefix = match this.resolve_path(None, mod_path, Some(TypeNS), - false, span, CrateLint::No) { + let mod_prefix = match this.resolve_path_without_parent_scope( + None, mod_path, Some(TypeNS), false, span, CrateLint::No + ) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.def(), _ => None, @@ -3478,7 +3415,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { )); } - let result = match self.resolve_path( + let result = match self.resolve_path_without_parent_scope( None, &path, Some(ns), @@ -3525,7 +3462,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { path[0].name != keywords::CrateRoot.name() && path[0].name != keywords::DollarCrate.name() { let unqualified_result = { - match self.resolve_path( + match self.resolve_path_without_parent_scope( None, &[*path.last().unwrap()], Some(ns), @@ -3548,7 +3485,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { Some(result) } - fn resolve_path( + fn resolve_path_without_parent_scope( &mut self, base_module: Option>, path: &[Ident], @@ -3557,12 +3494,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { path_span: Span, crate_lint: CrateLint, ) -> PathResult<'a> { + // Macro and import paths must have full parent scope available during resolution, + // other paths will do okay with parent module alone. + assert!(opt_ns != None && opt_ns != Some(MacroNS)); let parent_scope = ParentScope { module: self.current_module, ..self.dummy_parent_scope() }; - self.resolve_path_with_parent_scope(base_module, path, opt_ns, &parent_scope, - record_used, path_span, crate_lint) + self.resolve_path(base_module, path, opt_ns, &parent_scope, + record_used, path_span, crate_lint) } - fn resolve_path_with_parent_scope( + fn resolve_path( &mut self, base_module: Option>, path: &[Ident], @@ -3749,7 +3689,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { PathResult::Module(module.unwrap_or_else(|| { span_bug!(path_span, "resolve_path: empty(?) path {:?} has no module", path); })) - } fn lint_if_path_starts_with_module( @@ -4033,8 +3972,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } else { // Search in module. let mod_path = &path[..path.len() - 1]; - if let PathResult::Module(module) = self.resolve_path(None, mod_path, Some(TypeNS), - false, span, CrateLint::No) { + if let PathResult::Module(module) = self.resolve_path_without_parent_scope( + None, mod_path, Some(TypeNS), false, span, CrateLint::No + ) { if let ModuleOrUniformRoot::Module(module) = module { add_module_candidates(module, &mut names); } @@ -4672,9 +4612,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } } - for &PrivacyError(span, name, binding) in &self.privacy_errors { - if !reported_spans.insert(span) { continue } - span_err!(self.session, span, E0603, "{} `{}` is private", binding.descr(), name); + for &PrivacyError(dedup_span, ident, binding) in &self.privacy_errors { + if reported_spans.insert(dedup_span) { + span_err!(self.session, ident.span, E0603, "{} `{}` is private", + binding.descr(), ident.name); + } } } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 3345e01a929c7..7da483903bfbd 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -43,7 +43,7 @@ use std::cell::Cell; use std::mem; use rustc_data_structures::sync::Lrc; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct InvocationData<'a> { def_index: DefIndex, /// Module in which the macro was invoked. @@ -70,6 +70,7 @@ impl<'a> InvocationData<'a> { /// Binding produced by a `macro_rules` item. /// Not modularized, can shadow previous legacy bindings, etc. +#[derive(Debug)] pub struct LegacyBinding<'a> { binding: &'a NameBinding<'a>, /// Legacy scope into which the `macro_rules` item was planted. @@ -82,7 +83,7 @@ pub struct LegacyBinding<'a> { /// (named or unnamed), or even further if it escapes with `#[macro_use]`. /// Some macro invocations need to introduce legacy scopes too because they /// potentially can expand into macro definitions. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum LegacyScope<'a> { /// Created when invocation data is allocated in the arena, /// must be replaced with a proper scope later. @@ -96,8 +97,8 @@ pub enum LegacyScope<'a> { Invocation(&'a InvocationData<'a>), } -/// Everything you need to resolve a macro path. -#[derive(Clone)] +/// Everything you need to resolve a macro or import path. +#[derive(Clone, Debug)] pub struct ParentScope<'a> { crate module: Module<'a>, crate expansion: Mark, @@ -461,8 +462,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { parent_scope: &ParentScope<'a>, force: bool, ) -> Result { - let ast::Path { ref segments, span } = *path; - let mut path: Vec<_> = segments.iter().map(|seg| seg.ident).collect(); + let path_span = path.span; + let mut path = path.segments.iter().map(|s| s.ident).collect::>(); // Possibly apply the macro helper hack if kind == MacroKind::Bang && path.len() == 1 && @@ -472,15 +473,15 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } if path.len() > 1 { - let def = match self.resolve_path_with_parent_scope(None, &path, Some(MacroNS), - parent_scope, false, span, - CrateLint::No) { + let def = match self.resolve_path(None, &path, Some(MacroNS), parent_scope, + false, path_span, CrateLint::No) { PathResult::NonModule(path_res) => match path_res.base_def() { Def::Err => Err(Determinacy::Determined), def @ _ => { if path_res.unresolved_segments() > 0 { self.found_unresolved_macro = true; - self.session.span_err(span, "fail to resolve non-ident macro path"); + self.session.span_err(path_span, + "fail to resolve non-ident macro path"); Err(Determinacy::Determined) } else { Ok(def) @@ -496,12 +497,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> { }; parent_scope.module.macro_resolutions.borrow_mut() - .push((path.into_boxed_slice(), span)); + .push((path, parent_scope.clone(), path_span)); def } else { let binding = self.early_resolve_ident_in_lexical_scope( - path[0], MacroNS, Some(kind), parent_scope, false, force, span + path[0], MacroNS, Some(kind), parent_scope, false, force, path_span ); match binding { Ok(..) => {} @@ -845,8 +846,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> { pub fn finalize_current_module_macro_resolutions(&mut self) { let module = self.current_module; - for &(ref path, span) in module.macro_resolutions.borrow().iter() { - match self.resolve_path(None, &path, Some(MacroNS), true, span, CrateLint::No) { + + let macro_resolutions = + mem::replace(&mut *module.macro_resolutions.borrow_mut(), Vec::new()); + for (path, parent_scope, path_span) in macro_resolutions { + match self.resolve_path(None, &path, Some(MacroNS), &parent_scope, + true, path_span, CrateLint::No) { PathResult::NonModule(_) => {}, PathResult::Failed(span, msg, _) => { resolve_error(self, span, ResolutionError::FailedToResolve(&msg)); diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 6c73f1bd0f8c5..a8907674a0890 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -16,6 +16,7 @@ use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError}; use Resolver; use {names_to_string, module_to_string}; use {resolve_error, ResolutionError}; +use macros::ParentScope; use rustc_data_structures::ptr_key::PtrKey; use rustc::ty; @@ -88,13 +89,12 @@ pub struct ImportDirective<'a> { /// Span of the *root* use tree (see `root_id`). pub root_span: Span, - pub parent: Module<'a>, + pub parent_scope: ParentScope<'a>, pub module_path: Vec, /// The resolution of `module_path`. pub imported_module: Cell>>, pub subclass: ImportDirectiveSubclass<'a>, pub vis: Cell, - pub expansion: Mark, pub used: Cell, /// Whether this import is a "canary" for the `uniform_paths` feature, @@ -226,6 +226,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let module = self.get_module(binding.def().def_id()); self.populate_module_if_necessary(module); return Ok(binding); + } else if !self.graph_root.unresolved_invocations.borrow().is_empty() { + // Macro-expanded `extern crate`items still can add names to extern prelude. + return Err(Undetermined); } else { return Err(Determined); } @@ -272,7 +275,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { return Ok(self.dummy_binding); } if !self.is_accessible(binding.vis) { - self.privacy_errors.push(PrivacyError(path_span, ident.name, binding)); + self.privacy_errors.push(PrivacyError(path_span, ident, binding)); } } @@ -307,8 +310,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { }; match self.resolve_ident_in_module(module, ident, ns, false, path_span) { Err(Determined) => continue, - Ok(binding) - if !self.is_accessible_from(binding.vis, single_import.parent) => continue, + Ok(binding) if !self.is_accessible_from( + binding.vis, single_import.parent_scope.module + ) => continue, Ok(_) | Err(Undetermined) => return Err(Undetermined), } } @@ -381,8 +385,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { match result { Err(Determined) => continue, - Ok(binding) - if !self.is_accessible_from(binding.vis, glob_import.parent) => continue, + Ok(binding) if !self.is_accessible_from( + binding.vis, glob_import.parent_scope.module + ) => continue, Ok(_) | Err(Undetermined) => return Err(Undetermined), } } @@ -400,11 +405,11 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { root_span: Span, root_id: NodeId, vis: ty::Visibility, - expansion: Mark, + parent_scope: ParentScope<'a>, is_uniform_paths_canary: bool) { - let current_module = self.current_module; + let current_module = parent_scope.module; let directive = self.arenas.alloc_import_directive(ImportDirective { - parent: current_module, + parent_scope, module_path, imported_module: Cell::new(None), subclass, @@ -413,7 +418,6 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { root_span, root_id, vis: Cell::new(vis), - expansion, used: Cell::new(false), is_uniform_paths_canary, }); @@ -431,7 +435,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { // We don't add prelude imports to the globs since they only affect lexical scopes, // which are not relevant to import resolution. GlobImport { is_prelude: true, .. } => {} - GlobImport { .. } => self.current_module.globs.borrow_mut().push(directive), + GlobImport { .. } => current_module.globs.borrow_mut().push(directive), _ => unreachable!(), } } @@ -462,7 +466,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { }, span: directive.span, vis, - expansion: directive.expansion, + expansion: directive.parent_scope.expansion, }) } @@ -568,12 +572,12 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let scope = match ident.span.reverse_glob_adjust(module.expansion, directive.span.ctxt().modern()) { Some(Some(def)) => self.macro_def_scope(def), - Some(None) => directive.parent, + Some(None) => directive.parent_scope.module, None => continue, }; if self.is_accessible_from(binding.vis, scope) { let imported_binding = self.import(binding, directive); - let _ = self.try_define(directive.parent, ident, ns, imported_binding); + let _ = self.try_define(directive.parent_scope.module, ident, ns, imported_binding); } } @@ -587,7 +591,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let dummy_binding = self.dummy_binding; let dummy_binding = self.import(dummy_binding, directive); self.per_ns(|this, ns| { - let _ = this.try_define(directive.parent, target, ns, dummy_binding); + let _ = this.try_define(directive.parent_scope.module, target, ns, dummy_binding); }); } } @@ -703,7 +707,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } } }); - } else if let Some((span, err)) = error { + } else if let Some((span, err, note)) = error { errors = true; if let SingleImport { source, ref result, .. } = import.subclass { @@ -731,7 +735,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { let path = import_path_to_string(&import.module_path[..], &import.subclass, span); - error_vec.push((span, path, err)); + error_vec.push((span, path, err, note)); seen_spans.insert(span); prev_root_id = import.root_id; } @@ -823,27 +827,45 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } } - fn throw_unresolved_import_error(&self, error_vec: Vec<(Span, String, String)>, - span: Option) { + fn throw_unresolved_import_error( + &self, + error_vec: Vec<(Span, String, String, Option)>, + span: Option, + ) { let max_span_label_msg_count = 10; // upper limit on number of span_label message. - let (span, msg) = if error_vec.is_empty() { - (span.unwrap(), "unresolved import".to_string()) + let (span, msg, note) = if error_vec.is_empty() { + (span.unwrap(), "unresolved import".to_string(), None) } else { - let span = MultiSpan::from_spans(error_vec.clone().into_iter() - .map(|elem: (Span, String, String)| { elem.0 }) - .collect()); + let span = MultiSpan::from_spans( + error_vec.clone().into_iter() + .map(|elem: (Span, String, String, Option)| elem.0) + .collect() + ); + + let note: Option = error_vec.clone().into_iter() + .filter_map(|elem: (Span, String, String, Option)| elem.3) + .last(); + let path_vec: Vec = error_vec.clone().into_iter() - .map(|elem: (Span, String, String)| { format!("`{}`", elem.1) }) + .map(|elem: (Span, String, String, Option)| format!("`{}`", elem.1)) .collect(); let path = path_vec.join(", "); - let msg = format!("unresolved import{} {}", - if path_vec.len() > 1 { "s" } else { "" }, path); - (span, msg) + let msg = format!( + "unresolved import{} {}", + if path_vec.len() > 1 { "s" } else { "" }, + path + ); + + (span, msg, note) }; + let mut err = struct_span_err!(self.resolver.session, span, E0432, "{}", &msg); for span_error in error_vec.into_iter().take(max_span_label_msg_count) { err.span_label(span_error.0, span_error.2); } + if let Some(note) = note { + err.note(¬e); + } err.emit(); } @@ -854,7 +876,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { names_to_string(&directive.module_path[..]), module_to_string(self.current_module).unwrap_or_else(|| "???".to_string())); - self.current_module = directive.parent; + self.current_module = directive.parent_scope.module; let module = if let Some(module) = directive.imported_module.get() { module @@ -865,12 +887,13 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { directive.vis.set(ty::Visibility::Invisible); let result = self.resolve_path( Some(if directive.is_uniform_paths_canary { - ModuleOrUniformRoot::Module(directive.parent) + ModuleOrUniformRoot::Module(directive.parent_scope.module) } else { ModuleOrUniformRoot::UniformRoot(keywords::Invalid.name()) }), &directive.module_path[..], None, + &directive.parent_scope, false, directive.span, directive.crate_lint(), @@ -907,7 +930,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { return }; - let parent = directive.parent; + let parent = directive.parent_scope.module; match result[ns].get() { Err(Undetermined) => indeterminate = true, Err(Determined) => { @@ -938,18 +961,22 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } // If appropriate, returns an error to report. - fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Span, String)> { - self.current_module = directive.parent; + fn finalize_import( + &mut self, + directive: &'b ImportDirective<'b> + ) -> Option<(Span, String, Option)> { + self.current_module = directive.parent_scope.module; let ImportDirective { ref module_path, span, .. } = *directive; let module_result = self.resolve_path( Some(if directive.is_uniform_paths_canary { - ModuleOrUniformRoot::Module(directive.parent) + ModuleOrUniformRoot::Module(directive.parent_scope.module) } else { ModuleOrUniformRoot::UniformRoot(keywords::Invalid.name()) }), &module_path, None, + &directive.parent_scope, true, span, directive.crate_lint(), @@ -961,15 +988,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { return None; } PathResult::Failed(span, msg, true) => { - return if let Some(suggested_path) = self.make_path_suggestion( - span, module_path.clone() + return if let Some((suggested_path, note)) = self.make_path_suggestion( + span, module_path.clone(), &directive.parent_scope ) { Some(( span, - format!("Did you mean `{}`?", names_to_string(&suggested_path[..])) + format!("Did you mean `{}`?", names_to_string(&suggested_path[..])), + note, )) } else { - Some((span, msg)) + Some((span, msg, None)) }; }, _ => return None, @@ -992,10 +1020,13 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } if let ModuleOrUniformRoot::Module(module) = module { - if module.def_id() == directive.parent.def_id() { + if module.def_id() == directive.parent_scope.module.def_id() { // Importing a module into itself is not allowed. - return Some((directive.span, - "Cannot glob-import a module into itself.".to_string())); + return Some(( + directive.span, + "Cannot glob-import a module into itself.".to_string(), + None, + )); } } if !is_prelude && @@ -1093,7 +1124,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } } }; - Some((span, msg)) + Some((span, msg, None)) } else { // `resolve_ident_in_module` reported a privacy error. self.import_dummy_binding(directive); @@ -1186,7 +1217,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { if let Some(Def::Trait(_)) = module.def() { self.session.span_err(directive.span, "items in traits are not importable."); return; - } else if module.def_id() == directive.parent.def_id() { + } else if module.def_id() == directive.parent_scope.module.def_id() { return; } else if let GlobImport { is_prelude: true, .. } = directive.subclass { self.prelude = Some(module); @@ -1210,7 +1241,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { }; if self.is_accessible_from(binding.pseudo_vis(), scope) { let imported_binding = self.import(binding, directive); - let _ = self.try_define(directive.parent, ident, ns, imported_binding); + let _ = self.try_define(directive.parent_scope.module, ident, ns, imported_binding); } } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 97bdb9e5fa30c..01859d683e0f8 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -107,7 +107,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { tcx: save_ctxt.tcx, save_ctxt, dumper, - span: span_utils.clone(), + span: span_utils, cur_scope: CRATE_NODE_ID, // mac_defs: FxHashSet::default(), macro_calls: FxHashSet::default(), diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 9ee4582fabf7b..d43d45f64a55c 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -1132,7 +1132,7 @@ impl ToJson for Target { macro_rules! target_val { ($attr:ident) => ( { let name = (stringify!($attr)).replace("_", "-"); - d.insert(name.to_string(), self.$attr.to_json()); + d.insert(name, self.$attr.to_json()); } ); ($attr:ident, $key_name:expr) => ( { let name = $key_name; @@ -1144,7 +1144,7 @@ impl ToJson for Target { ($attr:ident) => ( { let name = (stringify!($attr)).replace("_", "-"); if default.$attr != self.options.$attr { - d.insert(name.to_string(), self.options.$attr.to_json()); + d.insert(name, self.options.$attr.to_json()); } } ); ($attr:ident, $key_name:expr) => ( { @@ -1160,7 +1160,7 @@ impl ToJson for Target { .iter() .map(|(k, v)| (k.desc().to_owned(), v.clone())) .collect::>(); - d.insert(name.to_string(), obj.to_json()); + d.insert(name, obj.to_json()); } } ); (env - $attr:ident) => ( { @@ -1170,7 +1170,7 @@ impl ToJson for Target { .iter() .map(|&(ref k, ref v)| k.clone() + "=" + &v) .collect::>(); - d.insert(name.to_string(), obj.to_json()); + d.insert(name, obj.to_json()); } } ); diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index cf274a9c85105..2ed02a4cdab1e 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -12,6 +12,8 @@ use rustc::infer::at::ToTrace; use rustc::infer::canonical::{Canonical, QueryResponse}; use rustc::infer::InferCtxt; use rustc::hir::def_id::DefId; +use rustc::mir::ProjectionKind; +use rustc::mir::tcx::PlaceTy; use rustc::traits::query::type_op::ascribe_user_type::AscribeUserType; use rustc::traits::query::type_op::eq::Eq; use rustc::traits::query::type_op::normalize::Normalize; @@ -58,14 +60,15 @@ fn type_op_ascribe_user_type<'tcx>( variance, def_id, user_substs, + projs, }, ) = key.into_parts(); debug!( "type_op_ascribe_user_type(\ - mir_ty={:?}, variance={:?}, def_id={:?}, user_substs={:?}\ + mir_ty={:?}, variance={:?}, def_id={:?}, user_substs={:?}, projs={:?}\ )", - mir_ty, variance, def_id, user_substs, + mir_ty, variance, def_id, user_substs, projs, ); let mut cx = AscribeUserTypeCx { @@ -73,7 +76,7 @@ fn type_op_ascribe_user_type<'tcx>( param_env, fulfill_cx, }; - cx.relate_mir_and_user_ty(mir_ty, variance, def_id, user_substs)?; + cx.relate_mir_and_user_ty(mir_ty, variance, def_id, user_substs, projs)?; Ok(()) }) @@ -134,17 +137,30 @@ impl AscribeUserTypeCx<'me, 'gcx, 'tcx> { variance: Variance, def_id: DefId, user_substs: UserSubsts<'tcx>, + projs: &[ProjectionKind<'tcx>], ) -> Result<(), NoSolution> { let UserSubsts { substs, user_self_ty, } = user_substs; - let ty = self.tcx().type_of(def_id); + let tcx = self.tcx(); + + let ty = tcx.type_of(def_id); let ty = self.subst(ty, substs); debug!("relate_type_and_user_type: ty of def-id is {:?}", ty); let ty = self.normalize(ty); + let mut projected_ty = PlaceTy::from_ty(ty); + for proj in projs { + projected_ty = projected_ty.projection_ty_core( + tcx, proj, |this, field, &()| { + let ty = this.field_ty(tcx, field); + self.normalize(ty) + }); + } + let ty = projected_ty.to_ty(tcx); + self.relate(mir_ty, variance, ty)?; if let Some(UserSelfTy { diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 743a2390ec43d..73489309d0742 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -61,7 +61,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> { let suggested_limit = *tcx.sess.recursion_limit.get() * 2; let msg = format!("reached the recursion limit while auto-dereferencing {:?}", self.cur_ty); - let error_id = (DiagnosticMessageId::ErrorId(55), Some(self.span), msg.clone()); + let error_id = (DiagnosticMessageId::ErrorId(55), Some(self.span), msg); let fresh = tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id); if fresh { struct_span_err!(tcx.sess, diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 695812faafff1..54c6c8f7b9322 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -325,7 +325,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, diag.span_suggestion_with_applicability( impl_err_span, "consider change the type to match the mutability in trait", - trait_err_str.to_string(), + trait_err_str, Applicability::MachineApplicable, ); } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index f4538dbd25e2f..c506f23078f25 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1157,7 +1157,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { // Convert the bounds into obligations. let impl_obligations = traits::predicates_for_generics( - cause.clone(), self.param_env, &impl_bounds); + cause, self.param_env, &impl_bounds); debug!("impl_obligations={:?}", impl_obligations); impl_obligations.into_iter() @@ -1175,7 +1175,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { TraitCandidate(trait_ref) => { let predicate = trait_ref.to_predicate(); let obligation = - traits::Obligation::new(cause.clone(), self.param_env, predicate); + traits::Obligation::new(cause, self.param_env, predicate); if !self.predicate_may_hold(&obligation) { if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) { // This candidate's primary obligation doesn't even diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 77151351d08a1..85c69d50a1249 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4752,25 +4752,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else if !self.check_for_cast(err, expr, found, expected) { let methods = self.get_conversion_methods(expr.span, expected, found); if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { - let suggestions = iter::repeat(expr_text).zip(methods.iter()) + let suggestions = iter::repeat(&expr_text).zip(methods.iter()) .filter_map(|(receiver, method)| { let method_call = format!(".{}()", method.ident); if receiver.ends_with(&method_call) { None // do not suggest code that is already there (#53348) } else { - /* - methods defined in `method_call_list` will overwrite - `.clone()` in copy of `receiver` - */ let method_call_list = [".to_vec()", ".to_string()"]; if receiver.ends_with(".clone()") - && method_call_list.contains(&method_call.as_str()){ - // created copy of `receiver` because we don't want other - // suggestion to get affected - let mut new_receiver = receiver.clone(); - let max_len = new_receiver.rfind(".").unwrap(); - new_receiver.truncate(max_len); - Some(format!("{}{}", new_receiver, method_call)) + && method_call_list.contains(&method_call.as_str()) { + let max_len = receiver.rfind(".").unwrap(); + Some(format!("{}{}", &receiver[..max_len], method_call)) } else { Some(format!("{}{}", receiver, method_call)) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 26487605bac67..fde8648c0c40a 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { .into_iter() .chain(self.get_auto_trait_impl_for( def_id, - name.clone(), + name, generics.clone(), def_ctor, tcx.require_lang_item(lang_items::SyncTraitLangItem), diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index b6bc8d603d5ac..858685ef00e37 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -66,7 +66,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> { } let ty = self.cx.tcx.type_of(def_id); let generics = self.cx.tcx.generics_of(def_id); - let real_name = name.clone().map(|name| Ident::from_str(&name)); + let real_name = name.map(|name| Ident::from_str(&name)); let param_env = self.cx.tcx.param_env(def_id); for &trait_def_id in self.cx.all_traits.iter() { if !self.cx.renderinfo.borrow().access_levels.is_doc_reachable(trait_def_id) || @@ -109,7 +109,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> { ); let may_apply = match infcx.evaluate_obligation( &traits::Obligation::new( - cause.clone(), + cause, param_env, trait_ref.to_predicate(), ), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2e6cc4bd54c61..bed3f7f99ae02 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3611,7 +3611,7 @@ impl ToSource for syntax_pos::Span { fn to_src(&self, cx: &DocContext) -> String { debug!("converting span {:?} to snippet", self.clean(cx)); let sn = match cx.sess().source_map().span_to_snippet(*self) { - Ok(x) => x.to_string(), + Ok(x) => x, Err(_) => String::new() }; debug!("got snippet {}", sn); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index dda0f37c3f95b..9dfe77338a356 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -521,7 +521,7 @@ pub fn run(mut krate: clean::Crate, external_html: external_html.clone(), krate: krate.name.clone(), }, - css_file_extension: css_file_extension.clone(), + css_file_extension, created_dirs: Default::default(), sort_modules_alphabetically, themes, @@ -1343,7 +1343,7 @@ impl DocFolder for Cache { self.search_index.push(IndexItem { ty: item.type_(), name: s.to_string(), - path: path.join("::").to_string(), + path: path.join("::"), desc: plain_summary_line(item.doc_value()), parent, parent_idx: None, @@ -2283,7 +2283,7 @@ fn document_short(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link format!("{} [Read more]({})", &plain_summary_line(Some(s)), naive_assoc_href(item, link)) } else { - plain_summary_line(Some(s)).to_string() + plain_summary_line(Some(s)) }; render_markdown(w, cx, &markdown, item.links(), prefix)?; } else if !prefix.is_empty() { @@ -2435,7 +2435,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, // (which is the position in the vector). indices.dedup_by_key(|i| (items[*i].def_id, if items[*i].name.as_ref().is_some() { - Some(full_path(cx, &items[*i]).clone()) + Some(full_path(cx, &items[*i])) } else { None }, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 406180c09e8e4..45a0494849bfa 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -460,7 +460,7 @@ fn main_args(args: &[String]) -> isize { let externs = match parse_externs(&matches) { Ok(ex) => ex, Err(err) => { - diag.struct_err(&err.to_string()).emit(); + diag.struct_err(&err).emit(); return 1; } }; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 85cd0f84e1cb0..2e6e76b5a4039 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -208,7 +208,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, // needs to be the result of SourceMap::span_to_unmapped_path let input = config::Input::Str { name: filename.to_owned(), - input: test.to_owned(), + input: test, }; let outputs = OutputTypes::new(&[(OutputType::Exe, None)]); @@ -350,7 +350,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, let newpath = { let path = env::var_os(var).unwrap_or(OsString::new()); let mut path = env::split_paths(&path).collect::>(); - path.insert(0, libdir.clone()); + path.insert(0, libdir); env::join_paths(path).unwrap() }; cmd.env(var, &newpath); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 805aa9bef227d..36190b3273a5a 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -133,8 +133,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, // Replace all the tokens for the corresponding positions in the macro, to maintain // proper positions in error reporting, while maintaining the macro_backtrace. if rhs_spans.len() == tts.len() { - tts = tts.map_enumerated(|i, tt| { - let mut tt = tt.clone(); + tts = tts.map_enumerated(|i, mut tt| { let mut sp = rhs_spans[i]; sp = sp.with_ctxt(tt.span().ctxt()); tt.set_span(sp); diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index ae486158fee69..3d897d17e0b5c 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -219,9 +219,9 @@ impl Add for LockstepIterSize { LockstepIterSize::Unconstrained => other, LockstepIterSize::Contradiction(_) => self, LockstepIterSize::Constraint(l_len, ref l_id) => match other { - LockstepIterSize::Unconstrained => self.clone(), + LockstepIterSize::Unconstrained => self, LockstepIterSize::Contradiction(_) => other, - LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self.clone(), + LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self, LockstepIterSize::Constraint(r_len, r_id) => { let msg = format!("inconsistent lockstep iteration: \ '{}' has {} items, but '{}' has {}", diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9c47589a0bd27..964d7fcab2052 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6426,6 +6426,17 @@ impl<'a> Parser<'a> { self.directory.path.to_mut().push(&path.as_str()); self.directory.ownership = DirectoryOwnership::Owned { relative: None }; } else { + // We have to push on the current module name in the case of relative + // paths in order to ensure that any additional module paths from inline + // `mod x { ... }` come after the relative extension. + // + // For example, a `mod z { ... }` inside `x/y.rs` should set the current + // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`. + if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership { + if let Some(ident) = relative.take() { // remove the relative offset + self.directory.path.to_mut().push(ident.as_str()); + } + } self.directory.path.to_mut().push(&id.as_str()); } } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 9f554a90afbc4..8ff4b0d025c8d 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -346,7 +346,7 @@ fn mk_main(cx: &mut TestCtxt) -> P { test_runner.span = sp; - let test_main_path_expr = ecx.expr_path(test_runner.clone()); + let test_main_path_expr = ecx.expr_path(test_runner); let call_test_main = ecx.expr_call(sp, test_main_path_expr, vec![mk_tests_slice(cx)]); let call_test_main = ecx.stmt_expr(call_test_main); diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 3705a245584d0..32a58de3529fd 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -178,7 +178,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P< cx.expr_match(span, new, vec![eq_arm, neq_arm]) }, - equals_expr.clone(), + equals_expr, Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| { if self_args.len() != 2 { cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`") diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index 973ad631b8343..55b3928d68eee 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -75,7 +75,7 @@ impl MultiItemModifier for ProcMacroDerive { // Mark attributes as known, and used. MarkAttrs(&self.attrs).visit_item(&item); - let input = __internal::new_token_stream(ecx.resolver.eliminate_crate_var(item.clone())); + let input = __internal::new_token_stream(ecx.resolver.eliminate_crate_var(item)); let res = __internal::set_sess(ecx, || { let inner = self.inner; panic::catch_unwind(panic::AssertUnwindSafe(|| inner(input))) diff --git a/src/test/mir-opt/basic_assignment.rs b/src/test/mir-opt/basic_assignment.rs index 64e574fa8aee0..7ca1d01f20b7b 100644 --- a/src/test/mir-opt/basic_assignment.rs +++ b/src/test/mir-opt/basic_assignment.rs @@ -56,7 +56,7 @@ fn main() { // StorageLive(_4); // _4 = std::option::Option>::None; // FakeRead(ForLet, _4); -// AscribeUserType(_4, o, Ty(Canonical { variables: [], value: std::option::Option> })); +// AscribeUserType(_4, o, UserTypeProjection { base: Ty(Canonical { variables: [], value: std::option::Option> }), projs: [] }); // StorageLive(_5); // StorageLive(_6); // _6 = move _4; diff --git a/src/test/run-pass/macros/macro-use-all-and-none.stderr b/src/test/run-pass/macros/macro-use-all-and-none.stderr new file mode 100644 index 0000000000000..fc4b33bafa40a --- /dev/null +++ b/src/test/run-pass/macros/macro-use-all-and-none.stderr @@ -0,0 +1,8 @@ +warning: unused attribute + --> $DIR/macro-use-all-and-none.rs:15:1 + | +LL | #[macro_use()] + | ^^^^^^^^^^^^^^ + | + = note: #[warn(unused_attributes)] on by default + diff --git a/src/test/ui/error-codes/E0603.stderr b/src/test/ui/error-codes/E0603.stderr index 3447f3378294e..1159348d3db35 100644 --- a/src/test/ui/error-codes/E0603.stderr +++ b/src/test/ui/error-codes/E0603.stderr @@ -1,8 +1,8 @@ error[E0603]: constant `PRIVATE` is private - --> $DIR/E0603.rs:16:5 + --> $DIR/E0603.rs:16:17 | LL | SomeModule::PRIVATE; //~ ERROR E0603 - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/error-festival.stderr b/src/test/ui/error-festival.stderr index 69f11b4b7c08c..5f1e677ca6708 100644 --- a/src/test/ui/error-festival.stderr +++ b/src/test/ui/error-festival.stderr @@ -5,10 +5,10 @@ LL | y = 2; | ^ did you mean `x`? error[E0603]: constant `FOO` is private - --> $DIR/error-festival.rs:32:5 + --> $DIR/error-festival.rs:32:10 | LL | foo::FOO; - | ^^^^^^^^ + | ^^^ error[E0368]: binary assignment operation `+=` cannot be applied to type `&str` --> $DIR/error-festival.rs:22:5 diff --git a/src/test/ui/export-import.stderr b/src/test/ui/export-import.stderr index 2f12485f123b6..dcadad82f29ba 100644 --- a/src/test/ui/export-import.stderr +++ b/src/test/ui/export-import.stderr @@ -1,8 +1,8 @@ error[E0603]: function `unexported` is private - --> $DIR/export-import.rs:11:5 + --> $DIR/export-import.rs:11:8 | LL | use m::unexported; - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/export-tag-variant.stderr b/src/test/ui/export-tag-variant.stderr index da67e2c41990b..e835c29fda34a 100644 --- a/src/test/ui/export-tag-variant.stderr +++ b/src/test/ui/export-tag-variant.stderr @@ -1,8 +1,8 @@ error[E0603]: enum `y` is private - --> $DIR/export-tag-variant.rs:17:21 + --> $DIR/export-tag-variant.rs:17:26 | LL | fn main() { let z = foo::y::y1; } //~ ERROR: enum `y` is private - | ^^^^^^^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/export.stderr b/src/test/ui/export.stderr index dd19e83750b5f..bed650b8c511e 100644 --- a/src/test/ui/export.stderr +++ b/src/test/ui/export.stderr @@ -23,10 +23,10 @@ LL | fn z(y: isize) { log(debug, y); } | ^^^^^ not found in this scope error[E0603]: function `z` is private - --> $DIR/export.rs:20:13 + --> $DIR/export.rs:20:18 | LL | fn main() { foo::z(10); } //~ ERROR function `z` is private - | ^^^^^^ + | ^ error: aborting due to 5 previous errors diff --git a/src/test/ui/extern/extern-crate-visibility.stderr b/src/test/ui/extern/extern-crate-visibility.stderr index cadb636bf0d97..02ecf0ce6f27c 100644 --- a/src/test/ui/extern/extern-crate-visibility.stderr +++ b/src/test/ui/extern/extern-crate-visibility.stderr @@ -1,14 +1,14 @@ error[E0603]: extern crate `core` is private - --> $DIR/extern-crate-visibility.rs:16:5 + --> $DIR/extern-crate-visibility.rs:16:10 | LL | use foo::core::cell; //~ ERROR extern crate `core` is private - | ^^^^^^^^^^^^^^^ + | ^^^^ error[E0603]: extern crate `core` is private - --> $DIR/extern-crate-visibility.rs:19:5 + --> $DIR/extern-crate-visibility.rs:19:10 | LL | foo::core::cell::Cell::new(0); //~ ERROR extern crate `core` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/hygiene/privacy.stderr b/src/test/ui/hygiene/privacy.stderr index 808d244e9cdb6..b93d4da3a867b 100644 --- a/src/test/ui/hygiene/privacy.stderr +++ b/src/test/ui/hygiene/privacy.stderr @@ -1,8 +1,8 @@ error[E0603]: function `f` is private - --> $DIR/privacy.rs:26:9 + --> $DIR/privacy.rs:26:14 | LL | foo::f() //~ ERROR `f` is private - | ^^^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/import.stderr b/src/test/ui/import.stderr index 896655868441c..4cd559f5f4a46 100644 --- a/src/test/ui/import.stderr +++ b/src/test/ui/import.stderr @@ -11,10 +11,10 @@ LL | use foo; //~ ERROR unresolved import `foo` [E0432] | ^^^ no `foo` in the root error[E0603]: unresolved item `foo` is private - --> $DIR/import.rs:23:5 + --> $DIR/import.rs:23:10 | LL | zed::foo(); //~ ERROR `foo` is private - | ^^^^^^^^ + | ^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs b/src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs new file mode 100644 index 0000000000000..b1154f2076b80 --- /dev/null +++ b/src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs @@ -0,0 +1,18 @@ +// compile-pass +// edition:2018 + +#![feature(extern_crate_item_prelude)] + +macro_rules! define_iso { () => { + extern crate std as iso; +}} + +::iso::thread_local! { + static S: u8 = 0; +} + +define_iso!(); + +fn main() { + let s = S; +} diff --git a/src/test/ui/imports/reexports.stderr b/src/test/ui/imports/reexports.stderr index a166344314b90..9ed3b02591c2d 100644 --- a/src/test/ui/imports/reexports.stderr +++ b/src/test/ui/imports/reexports.stderr @@ -17,16 +17,16 @@ LL | pub use super::*; //~ ERROR must import something with the glob's v | ^^^^^^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:38:9 + --> $DIR/reexports.rs:38:15 | LL | use b::a::foo::S; //~ ERROR `foo` - | ^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:39:9 + --> $DIR/reexports.rs:39:15 | LL | use b::b::foo::S as T; //~ ERROR `foo` - | ^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-10545.stderr b/src/test/ui/issues/issue-10545.stderr index 28f95dff3bc0a..93a098432534b 100644 --- a/src/test/ui/issues/issue-10545.stderr +++ b/src/test/ui/issues/issue-10545.stderr @@ -1,8 +1,8 @@ error[E0603]: struct `S` is private - --> $DIR/issue-10545.rs:17:11 + --> $DIR/issue-10545.rs:17:14 | LL | fn foo(_: a::S) { //~ ERROR: struct `S` is private - | ^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-11593.stderr b/src/test/ui/issues/issue-11593.stderr index 24e1a5eb6f46e..bb5303cb581a1 100644 --- a/src/test/ui/issues/issue-11593.stderr +++ b/src/test/ui/issues/issue-11593.stderr @@ -1,8 +1,8 @@ error[E0603]: trait `Foo` is private - --> $DIR/issue-11593.rs:17:6 + --> $DIR/issue-11593.rs:17:24 | LL | impl private_trait_xc::Foo for Bar {} - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-11680.stderr b/src/test/ui/issues/issue-11680.stderr index 37cfe960600b0..4dfd0bf15b92a 100644 --- a/src/test/ui/issues/issue-11680.stderr +++ b/src/test/ui/issues/issue-11680.stderr @@ -1,14 +1,14 @@ error[E0603]: enum `Foo` is private - --> $DIR/issue-11680.rs:16:14 + --> $DIR/issue-11680.rs:16:21 | LL | let _b = other::Foo::Bar(1); - | ^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: enum `Foo` is private - --> $DIR/issue-11680.rs:19:14 + --> $DIR/issue-11680.rs:19:27 | LL | let _b = other::test::Foo::Bar(1); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-13407.stderr b/src/test/ui/issues/issue-13407.stderr index e5ef50e984a76..90d5ca59e1e25 100644 --- a/src/test/ui/issues/issue-13407.stderr +++ b/src/test/ui/issues/issue-13407.stderr @@ -1,8 +1,8 @@ error[E0603]: unit struct `C` is private - --> $DIR/issue-13407.rs:16:5 + --> $DIR/issue-13407.rs:16:8 | LL | A::C = 1; - | ^^^^ + | ^ error[E0308]: mismatched types --> $DIR/issue-13407.rs:16:12 diff --git a/src/test/ui/issues/issue-13641.stderr b/src/test/ui/issues/issue-13641.stderr index 0f96b5f66b1b8..cbbceb72af392 100644 --- a/src/test/ui/issues/issue-13641.stderr +++ b/src/test/ui/issues/issue-13641.stderr @@ -1,14 +1,14 @@ error[E0603]: struct `Foo` is private - --> $DIR/issue-13641.rs:19:5 + --> $DIR/issue-13641.rs:19:8 | LL | a::Foo::new(); - | ^^^^^^^^^^^ + | ^^^ error[E0603]: enum `Bar` is private - --> $DIR/issue-13641.rs:21:5 + --> $DIR/issue-13641.rs:21:8 | LL | a::Bar::new(); - | ^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-16725.stderr b/src/test/ui/issues/issue-16725.stderr index 709f3cf50b992..ba36f9b5582e5 100644 --- a/src/test/ui/issues/issue-16725.stderr +++ b/src/test/ui/issues/issue-16725.stderr @@ -1,8 +1,8 @@ error[E0603]: function `bar` is private - --> $DIR/issue-16725.rs:16:14 + --> $DIR/issue-16725.rs:16:19 | LL | unsafe { foo::bar(); } - | ^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-17718-const-privacy.stderr b/src/test/ui/issues/issue-17718-const-privacy.stderr index a453e599c8b43..7d65a97ec1d5a 100644 --- a/src/test/ui/issues/issue-17718-const-privacy.stderr +++ b/src/test/ui/issues/issue-17718-const-privacy.stderr @@ -1,8 +1,8 @@ error[E0603]: constant `B` is private - --> $DIR/issue-17718-const-privacy.rs:15:5 + --> $DIR/issue-17718-const-privacy.rs:15:8 | LL | use a::B; //~ ERROR: constant `B` is private - | ^^^^ + | ^ error[E0603]: constant `BAR` is private --> $DIR/issue-17718-const-privacy.rs:18:5 diff --git a/src/test/ui/issues/issue-28388-1.rs b/src/test/ui/issues/issue-28388-1.rs index 187d91731d0d6..b0418a513e31c 100644 --- a/src/test/ui/issues/issue-28388-1.rs +++ b/src/test/ui/issues/issue-28388-1.rs @@ -10,6 +10,6 @@ // Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. -use foo::{}; //~ ERROR cannot find module or enum `foo` in the crate root +use foo::{}; //~ ERROR unresolved import `foo` fn main() {} diff --git a/src/test/ui/issues/issue-28388-1.stderr b/src/test/ui/issues/issue-28388-1.stderr index 9f4b6cb56e727..f93252f1d7dec 100644 --- a/src/test/ui/issues/issue-28388-1.stderr +++ b/src/test/ui/issues/issue-28388-1.stderr @@ -1,9 +1,9 @@ -error[E0578]: cannot find module or enum `foo` in the crate root +error[E0432]: unresolved import `foo` --> $DIR/issue-28388-1.rs:13:5 | -LL | use foo::{}; //~ ERROR cannot find module or enum `foo` in the crate root - | ^^^ not found in the crate root +LL | use foo::{}; //~ ERROR unresolved import `foo` + | ^^^^^^^ no `foo` in the root error: aborting due to previous error -For more information about this error, try `rustc --explain E0578`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/issues/issue-28388-2.stderr b/src/test/ui/issues/issue-28388-2.stderr index 7809934942c26..02ffc4b1758f6 100644 --- a/src/test/ui/issues/issue-28388-2.stderr +++ b/src/test/ui/issues/issue-28388-2.stderr @@ -1,8 +1,8 @@ error[E0603]: module `n` is private - --> $DIR/issue-28388-2.rs:17:5 + --> $DIR/issue-28388-2.rs:17:8 | LL | use m::n::{}; - | ^^^^^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-29161.stderr b/src/test/ui/issues/issue-29161.stderr index fb6a41d2eca09..7d3bd03ba230b 100644 --- a/src/test/ui/issues/issue-29161.stderr +++ b/src/test/ui/issues/issue-29161.stderr @@ -5,10 +5,10 @@ LL | pub fn default() -> A { //~ ERROR unnecessary visibility qualifier | ^^^ `pub` not permitted here because it's implied error[E0603]: struct `A` is private - --> $DIR/issue-29161.rs:23:5 + --> $DIR/issue-29161.rs:23:8 | LL | a::A::default(); - | ^^^^^^^^^^^^^ + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-38857.stderr b/src/test/ui/issues/issue-38857.stderr index 985927c25a1ae..f6ed320267179 100644 --- a/src/test/ui/issues/issue-38857.stderr +++ b/src/test/ui/issues/issue-38857.stderr @@ -5,10 +5,10 @@ LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() | ^^^ Could not find `imp` in `sys` error[E0603]: module `sys` is private - --> $DIR/issue-38857.rs:12:13 + --> $DIR/issue-38857.rs:12:18 | LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-3993.stderr b/src/test/ui/issues/issue-3993.stderr index 4b569f2dea957..52f1985c4fbf4 100644 --- a/src/test/ui/issues/issue-3993.stderr +++ b/src/test/ui/issues/issue-3993.stderr @@ -1,8 +1,8 @@ error[E0603]: function `fly` is private - --> $DIR/issue-3993.rs:11:5 + --> $DIR/issue-3993.rs:11:10 | LL | use zoo::fly; //~ ERROR: function `fly` is private - | ^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed deleted file mode 100644 index 016cff914bd2d..0000000000000 --- a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#![allow(dead_code)] - -fn missing_discourses() -> Result { - Ok(1) -} - -fn forbidden_narratives() -> Result { - Ok(missing_discourses()?) - //~^ ERROR try expression alternatives have incompatible types - //~| HELP try wrapping with a success variant -} - -fn main() {} diff --git a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs index 315773a85f004..32ea715b64fa7 100644 --- a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs +++ b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// run-rustfix - #![allow(dead_code)] fn missing_discourses() -> Result { @@ -19,7 +17,6 @@ fn missing_discourses() -> Result { fn forbidden_narratives() -> Result { missing_discourses()? //~^ ERROR try expression alternatives have incompatible types - //~| HELP try wrapping with a success variant } fn main() {} diff --git a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr index a50af5624c0cf..590cbff67a4bc 100644 --- a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr +++ b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr @@ -1,11 +1,8 @@ error[E0308]: try expression alternatives have incompatible types - --> $DIR/issue-51632-try-desugar-incompatible-types.rs:20:5 + --> $DIR/issue-51632-try-desugar-incompatible-types.rs:18:5 | LL | missing_discourses()? - | ^^^^^^^^^^^^^^^^^^^^^ - | | - | expected enum `std::result::Result`, found isize - | help: try wrapping with a success variant: `Ok(missing_discourses()?)` + | ^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found isize | = note: expected type `std::result::Result` found type `isize` diff --git a/src/test/ui/macros/macro-local-data-key-priv.stderr b/src/test/ui/macros/macro-local-data-key-priv.stderr index 57f4f790cb11c..b5ad50fbebab2 100644 --- a/src/test/ui/macros/macro-local-data-key-priv.stderr +++ b/src/test/ui/macros/macro-local-data-key-priv.stderr @@ -1,8 +1,8 @@ error[E0603]: constant `baz` is private - --> $DIR/macro-local-data-key-priv.rs:18:5 + --> $DIR/macro-local-data-key-priv.rs:18:10 | LL | bar::baz.with(|_| ()); - | ^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs b/src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs new file mode 100644 index 0000000000000..0a8a6793dc782 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs @@ -0,0 +1,31 @@ +// compile-pass +#![feature(nll)] + +// This test is reduced from a scenario pnkfelix encountered while +// bootstrapping the compiler. + +#[derive(Copy, Clone)] +pub struct Spanned { + pub node: T, + pub span: Span, +} + +pub type Variant = Spanned; +// #[derive(Clone)] pub struct Variant { pub node: VariantKind, pub span: Span, } + +#[derive(Clone)] +pub struct VariantKind { } + +#[derive(Copy, Clone)] +pub struct Span; + +pub fn variant_to_span(variant: Variant) { + match variant { + Variant { + span: _span, + .. + } => { } + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/patterns.rs b/src/test/ui/nll/user-annotations/patterns.rs index e3bac513fa874..8c8e61cd6fbeb 100644 --- a/src/test/ui/nll/user-annotations/patterns.rs +++ b/src/test/ui/nll/user-annotations/patterns.rs @@ -9,11 +9,11 @@ fn variable_no_initializer() { } fn tuple_no_initializer() { - // FIXME(#47187): We are not propagating ascribed type through tuples. + let x = 22; let (y, z): (&'static u32, &'static u32); - y = &x; + y = &x; //~ ERROR } fn ref_with_ascribed_static_type() -> u32 { @@ -34,11 +34,23 @@ fn ref_with_ascribed_any_type() -> u32 { struct Single { value: T } fn struct_no_initializer() { - // FIXME(#47187): We are not propagating ascribed type through patterns. + let x = 22; let Single { value: y }: Single<&'static u32>; - y = &x; + y = &x; //~ ERROR +} + + +fn struct_no_initializer_must_normalize() { + trait Indirect { type Assoc; } + struct StaticU32; + impl Indirect for StaticU32 { type Assoc = &'static u32; } + struct Single2 { value: ::Assoc } + + let x = 22; + let Single2 { value: mut _y }: Single2; + _y = &x; //~ ERROR } fn variable_with_initializer() { @@ -91,26 +103,31 @@ fn struct_double_field_underscore_with_initializer() { } fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 { - // The error in this test is inconsistency with - // `static_to_a_to_static_through_tuple`, but "feels right" to - // me. It occurs because we special case the single binding case - // and force the type of `y` to be `&'a u32`, even though the - // right-hand side has type `&'static u32`. + + + + + let y: &'a u32 = &22; y //~ ERROR } fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 { - // FIXME(#47187): The fact that this type-checks is perhaps surprising. - // What happens is that the right-hand side is constrained to have - // type `&'a u32`, which is possible, because it has type - // `&'static u32`. The variable `y` is then forced to have type - // `&'static u32`, but it is constrained only by the right-hand - // side, not the ascribed type, and hence it passes. + + + + + + let (y, _z): (&'a u32, u32) = (&22, 44); - y + y //~ ERROR +} + +fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 { + let Single { value: y }: Single<&'a u32> = Single { value: &22 }; + y //~ ERROR } fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { diff --git a/src/test/ui/nll/user-annotations/patterns.stderr b/src/test/ui/nll/user-annotations/patterns.stderr index 0c50b98ee2713..b0c554e6ca1d4 100644 --- a/src/test/ui/nll/user-annotations/patterns.stderr +++ b/src/test/ui/nll/user-annotations/patterns.stderr @@ -8,6 +8,16 @@ LL | y = &x; //~ ERROR LL | } | - `x` dropped here while still borrowed +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:16:9 + | +LL | let (y, z): (&'static u32, &'static u32); + | ---------------------------- type annotation requires that `x` is borrowed for `'static` +LL | y = &x; //~ ERROR + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:22:13 | @@ -20,7 +30,27 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:46:27 + --> $DIR/patterns.rs:41:9 + | +LL | let Single { value: y }: Single<&'static u32>; + | -------------------- type annotation requires that `x` is borrowed for `'static` +LL | y = &x; //~ ERROR + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:53:10 + | +LL | let Single2 { value: mut _y }: Single2; + | ------------------ type annotation requires that `x` is borrowed for `'static` +LL | _y = &x; //~ ERROR + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:58:27 | LL | let y: &'static u32 = &x; //~ ERROR | ------------ ^^ borrowed value does not live long enough @@ -30,7 +60,7 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:51:27 + --> $DIR/patterns.rs:63:27 | LL | let _: &'static u32 = &x; //~ ERROR | ------------ ^^ borrowed value does not live long enough @@ -41,7 +71,7 @@ LL | } | - `x` dropped here while still borrowed error[E0716]: temporary value dropped while borrowed - --> $DIR/patterns.rs:53:41 + --> $DIR/patterns.rs:65:41 | LL | let _: Vec<&'static String> = vec![&String::new()]; | -------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement @@ -50,7 +80,7 @@ LL | let _: Vec<&'static String> = vec![&String::new()]; | type annotation requires that borrow lasts for `'static` error[E0716]: temporary value dropped while borrowed - --> $DIR/patterns.rs:56:52 + --> $DIR/patterns.rs:68:52 | LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44); | ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement @@ -59,7 +89,7 @@ LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44); | type annotation requires that borrow lasts for `'static` error[E0716]: temporary value dropped while borrowed - --> $DIR/patterns.rs:59:53 + --> $DIR/patterns.rs:71:53 | LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44); | ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement @@ -68,7 +98,7 @@ LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44); | type annotation requires that borrow lasts for `'static` error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:65:40 + --> $DIR/patterns.rs:77:40 | LL | let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR | ------------------- ^^ borrowed value does not live long enough @@ -78,7 +108,7 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:70:40 + --> $DIR/patterns.rs:82:40 | LL | let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR | ------------------- ^^ borrowed value does not live long enough @@ -88,7 +118,7 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:75:69 + --> $DIR/patterns.rs:87:69 | LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR | -------------------- ^^ borrowed value does not live long enough @@ -98,7 +128,7 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:80:69 + --> $DIR/patterns.rs:92:69 | LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR | -------------------- ^^ borrowed value does not live long enough @@ -108,7 +138,7 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough - --> $DIR/patterns.rs:88:17 + --> $DIR/patterns.rs:100:17 | LL | let Double { value1: _, value2: _ }: Double<&'static u32> = Double { | -------------------- type annotation requires that `x` is borrowed for `'static` @@ -119,7 +149,7 @@ LL | } | - `x` dropped here while still borrowed error: unsatisfied lifetime constraints - --> $DIR/patterns.rs:101:5 + --> $DIR/patterns.rs:113:5 | LL | fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here @@ -128,14 +158,32 @@ LL | y //~ ERROR | ^ returning this value requires that `'a` must outlive `'static` error: unsatisfied lifetime constraints - --> $DIR/patterns.rs:117:18 + --> $DIR/patterns.rs:125:5 + | +LL | fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y //~ ERROR + | ^ returning this value requires that `'a` must outlive `'static` + +error: unsatisfied lifetime constraints + --> $DIR/patterns.rs:130:5 + | +LL | fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let Single { value: y }: Single<&'a u32> = Single { value: &22 }; +LL | y //~ ERROR + | ^ returning this value requires that `'a` must outlive `'static` + +error: unsatisfied lifetime constraints + --> $DIR/patterns.rs:134:18 | LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here LL | let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` -error: aborting due to 14 previous errors +error: aborting due to 19 previous errors Some errors occurred: E0597, E0716. For more information about an error, try `rustc --explain E0597`. diff --git a/src/test/ui/non_modrs_mods_and_inline_mods/non_modrs_mods_and_inline_mods.rs b/src/test/ui/non_modrs_mods_and_inline_mods/non_modrs_mods_and_inline_mods.rs new file mode 100644 index 0000000000000..25a9c2ed98e04 --- /dev/null +++ b/src/test/ui/non_modrs_mods_and_inline_mods/non_modrs_mods_and_inline_mods.rs @@ -0,0 +1,5 @@ +// compile-pass + +mod x; + +fn main() {} diff --git a/src/test/ui/non_modrs_mods_and_inline_mods/x.rs b/src/test/ui/non_modrs_mods_and_inline_mods/x.rs new file mode 100644 index 0000000000000..a39a7c6d9b3ee --- /dev/null +++ b/src/test/ui/non_modrs_mods_and_inline_mods/x.rs @@ -0,0 +1,5 @@ +// ignore-test: not a test + +pub mod y { + pub mod z; +} diff --git a/src/test/ui/non_modrs_mods_and_inline_mods/x/y/z/mod.rs b/src/test/ui/non_modrs_mods_and_inline_mods/x/y/z/mod.rs new file mode 100644 index 0000000000000..e8442a47f2c77 --- /dev/null +++ b/src/test/ui/non_modrs_mods_and_inline_mods/x/y/z/mod.rs @@ -0,0 +1 @@ +// ignore-test: not a test diff --git a/src/test/ui/privacy/privacy-in-paths.stderr b/src/test/ui/privacy/privacy-in-paths.stderr index f0aa3d36479e4..7b72c634ebf9b 100644 --- a/src/test/ui/privacy/privacy-in-paths.stderr +++ b/src/test/ui/privacy/privacy-in-paths.stderr @@ -1,20 +1,20 @@ error[E0603]: module `bar` is private - --> $DIR/privacy-in-paths.rs:34:9 + --> $DIR/privacy-in-paths.rs:34:16 | LL | ::foo::bar::baz::f(); //~ERROR module `bar` is private - | ^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `bar` is private - --> $DIR/privacy-in-paths.rs:35:9 + --> $DIR/privacy-in-paths.rs:35:16 | LL | ::foo::bar::S::f(); //~ERROR module `bar` is private - | ^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: trait `T` is private - --> $DIR/privacy-in-paths.rs:36:9 + --> $DIR/privacy-in-paths.rs:36:23 | LL | <() as ::foo::T>::Assoc::f(); //~ERROR trait `T` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: aborting due to 3 previous errors diff --git a/src/test/ui/privacy/privacy-ns2.stderr b/src/test/ui/privacy/privacy-ns2.stderr index 0cd341d9a58b5..9243bc2459f91 100644 --- a/src/test/ui/privacy/privacy-ns2.stderr +++ b/src/test/ui/privacy/privacy-ns2.stderr @@ -55,16 +55,16 @@ LL | use foo3::Bar; | error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:70:9 + --> $DIR/privacy-ns2.rs:70:15 | LL | use foo3::Bar; //~ ERROR `Bar` is private - | ^^^^^^^^^ + | ^^^ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:74:9 + --> $DIR/privacy-ns2.rs:74:15 | LL | use foo3::Bar; //~ ERROR `Bar` is private - | ^^^^^^^^^ + | ^^^ error[E0603]: trait `Bar` is private --> $DIR/privacy-ns2.rs:81:16 diff --git a/src/test/ui/privacy/privacy-ufcs.stderr b/src/test/ui/privacy/privacy-ufcs.stderr index 2030e2e0f1b9e..5989c79bc85d3 100644 --- a/src/test/ui/privacy/privacy-ufcs.stderr +++ b/src/test/ui/privacy/privacy-ufcs.stderr @@ -1,8 +1,8 @@ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ufcs.rs:22:5 + --> $DIR/privacy-ufcs.rs:22:20 | LL | ::baz(); //~ERROR trait `Bar` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/privacy/privacy1.rs b/src/test/ui/privacy/privacy1.rs index afe8c2fda3d4c..9aff4bbc41c9c 100644 --- a/src/test/ui/privacy/privacy1.rs +++ b/src/test/ui/privacy/privacy1.rs @@ -127,7 +127,6 @@ mod foo { fn test2() { use bar::baz::{foo, bar}; //~^ ERROR: module `baz` is private - //~| ERROR: module `baz` is private foo(); bar(); diff --git a/src/test/ui/privacy/privacy1.stderr b/src/test/ui/privacy/privacy1.stderr index 344f990699f45..d6197575447e6 100644 --- a/src/test/ui/privacy/privacy1.stderr +++ b/src/test/ui/privacy/privacy1.stderr @@ -1,80 +1,74 @@ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:128:24 + --> $DIR/privacy1.rs:128:18 | LL | use bar::baz::{foo, bar}; - | ^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:128:29 - | -LL | use bar::baz::{foo, bar}; - | ^^^ - -error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:137:13 + --> $DIR/privacy1.rs:136:18 | LL | use bar::baz; - | ^^^^^^^^ + | ^^^ error[E0603]: module `i` is private - --> $DIR/privacy1.rs:161:9 + --> $DIR/privacy1.rs:160:20 | LL | use self::foo::i::A; //~ ERROR: module `i` is private - | ^^^^^^^^^^^^^^^ + | ^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:100:9 + --> $DIR/privacy1.rs:100:16 | LL | ::bar::baz::A::foo(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:101:9 + --> $DIR/privacy1.rs:101:16 | LL | ::bar::baz::A::bar(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:103:9 + --> $DIR/privacy1.rs:103:16 | LL | ::bar::baz::A.foo2(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:104:9 + --> $DIR/privacy1.rs:104:16 | LL | ::bar::baz::A.bar2(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^ + | ^^^ error[E0603]: trait `B` is private - --> $DIR/privacy1.rs:108:9 + --> $DIR/privacy1.rs:108:16 | LL | ::bar::B::foo(); //~ ERROR: trait `B` is private - | ^^^^^^^^^^^^^ + | ^ error[E0603]: function `epriv` is private - --> $DIR/privacy1.rs:114:13 + --> $DIR/privacy1.rs:114:20 | LL | ::bar::epriv(); //~ ERROR: function `epriv` is private - | ^^^^^^^^^^^^ + | ^^^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:123:9 + --> $DIR/privacy1.rs:123:16 | LL | ::bar::baz::foo(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:124:9 + --> $DIR/privacy1.rs:124:16 | LL | ::bar::baz::bar(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: trait `B` is private - --> $DIR/privacy1.rs:153:10 + --> $DIR/privacy1.rs:152:17 | LL | impl ::bar::B for f32 { fn foo() -> f32 { 1.0 } } - | ^^^^^^^^ + | ^ error[E0624]: method `bar` is private --> $DIR/privacy1.rs:73:9 @@ -106,7 +100,7 @@ error[E0624]: method `bar2` is private LL | ::bar::baz::A.bar2(); //~ ERROR: module `baz` is private | ^^^^ -error: aborting due to 18 previous errors +error: aborting due to 17 previous errors Some errors occurred: E0603, E0624. For more information about an error, try `rustc --explain E0603`. diff --git a/src/test/ui/privacy/privacy2.stderr b/src/test/ui/privacy/privacy2.stderr index ec5567b25e443..fa4da7f5181b0 100644 --- a/src/test/ui/privacy/privacy2.stderr +++ b/src/test/ui/privacy/privacy2.stderr @@ -5,10 +5,10 @@ LL | use bar::foo; | ^^^^^^^^ no `foo` in `bar` error[E0603]: function `foo` is private - --> $DIR/privacy2.rs:33:9 + --> $DIR/privacy2.rs:33:20 | LL | use bar::glob::foo; - | ^^^^^^^^^^^^^^ + | ^^^ error: requires `sized` lang_item diff --git a/src/test/ui/privacy/privacy4.stderr b/src/test/ui/privacy/privacy4.stderr index 811f5d5942a7a..8a4b7401de01a 100644 --- a/src/test/ui/privacy/privacy4.stderr +++ b/src/test/ui/privacy/privacy4.stderr @@ -1,8 +1,8 @@ error[E0603]: module `glob` is private - --> $DIR/privacy4.rs:31:9 + --> $DIR/privacy4.rs:31:14 | LL | use bar::glob::gpriv; //~ ERROR: module `glob` is private - | ^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to previous error diff --git a/src/test/ui/privacy/privacy5.stderr b/src/test/ui/privacy/privacy5.stderr index bcb6315136273..23682575cf183 100644 --- a/src/test/ui/privacy/privacy5.stderr +++ b/src/test/ui/privacy/privacy5.stderr @@ -1,290 +1,290 @@ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:61:13 + --> $DIR/privacy5.rs:61:16 | LL | let a = a::A(()); //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:62:13 + --> $DIR/privacy5.rs:62:16 | LL | let b = a::B(2); //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:63:13 + --> $DIR/privacy5.rs:63:16 | LL | let c = a::C(2, 3); //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:66:9 + --> $DIR/privacy5.rs:66:12 | LL | let a::A(()) = a; //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:67:9 + --> $DIR/privacy5.rs:67:12 | LL | let a::A(_) = a; //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:68:15 + --> $DIR/privacy5.rs:68:18 | LL | match a { a::A(()) => {} } //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:69:15 + --> $DIR/privacy5.rs:69:18 | LL | match a { a::A(_) => {} } //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:71:9 + --> $DIR/privacy5.rs:71:12 | LL | let a::B(_) = b; //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:72:9 + --> $DIR/privacy5.rs:72:12 | LL | let a::B(_b) = b; //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:73:15 + --> $DIR/privacy5.rs:73:18 | LL | match b { a::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:74:15 + --> $DIR/privacy5.rs:74:18 | LL | match b { a::B(_b) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:75:15 + --> $DIR/privacy5.rs:75:18 | LL | match b { a::B(1) => {} a::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:75:29 + --> $DIR/privacy5.rs:75:32 | LL | match b { a::B(1) => {} a::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:78:9 + --> $DIR/privacy5.rs:78:12 | LL | let a::C(_, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:79:9 + --> $DIR/privacy5.rs:79:12 | LL | let a::C(_a, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:80:9 + --> $DIR/privacy5.rs:80:12 | LL | let a::C(_, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:81:9 + --> $DIR/privacy5.rs:81:12 | LL | let a::C(_a, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:82:15 + --> $DIR/privacy5.rs:82:18 | LL | match c { a::C(_, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:83:15 + --> $DIR/privacy5.rs:83:18 | LL | match c { a::C(_a, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:84:15 + --> $DIR/privacy5.rs:84:18 | LL | match c { a::C(_, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:85:15 + --> $DIR/privacy5.rs:85:18 | LL | match c { a::C(_a, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:93:14 + --> $DIR/privacy5.rs:93:17 | LL | let a2 = a::A; //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:94:14 + --> $DIR/privacy5.rs:94:17 | LL | let b2 = a::B; //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:95:14 + --> $DIR/privacy5.rs:95:17 | LL | let c2 = a::C; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:100:13 + --> $DIR/privacy5.rs:100:20 | LL | let a = other::A(()); //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:101:13 + --> $DIR/privacy5.rs:101:20 | LL | let b = other::B(2); //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:102:13 + --> $DIR/privacy5.rs:102:20 | LL | let c = other::C(2, 3); //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:105:9 + --> $DIR/privacy5.rs:105:16 | LL | let other::A(()) = a; //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:106:9 + --> $DIR/privacy5.rs:106:16 | LL | let other::A(_) = a; //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:107:15 + --> $DIR/privacy5.rs:107:22 | LL | match a { other::A(()) => {} } //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:108:15 + --> $DIR/privacy5.rs:108:22 | LL | match a { other::A(_) => {} } //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:110:9 + --> $DIR/privacy5.rs:110:16 | LL | let other::B(_) = b; //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:111:9 + --> $DIR/privacy5.rs:111:16 | LL | let other::B(_b) = b; //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:112:15 + --> $DIR/privacy5.rs:112:22 | LL | match b { other::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:113:15 + --> $DIR/privacy5.rs:113:22 | LL | match b { other::B(_b) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:114:15 + --> $DIR/privacy5.rs:114:22 | LL | match b { other::B(1) => {} other::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:114:33 + --> $DIR/privacy5.rs:114:40 | LL | match b { other::B(1) => {} other::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:117:9 + --> $DIR/privacy5.rs:117:16 | LL | let other::C(_, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:118:9 + --> $DIR/privacy5.rs:118:16 | LL | let other::C(_a, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:119:9 + --> $DIR/privacy5.rs:119:16 | LL | let other::C(_, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:120:9 + --> $DIR/privacy5.rs:120:16 | LL | let other::C(_a, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:121:15 + --> $DIR/privacy5.rs:121:22 | LL | match c { other::C(_, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:122:15 + --> $DIR/privacy5.rs:122:22 | LL | match c { other::C(_a, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:123:15 + --> $DIR/privacy5.rs:123:22 | LL | match c { other::C(_, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:124:15 + --> $DIR/privacy5.rs:124:22 | LL | match c { other::C(_a, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:132:14 + --> $DIR/privacy5.rs:132:21 | LL | let a2 = other::A; //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:133:14 + --> $DIR/privacy5.rs:133:21 | LL | let b2 = other::B; //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:134:14 + --> $DIR/privacy5.rs:134:21 | LL | let c2 = other::C; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error: aborting due to 48 previous errors diff --git a/src/test/ui/privacy/private-item-simple.stderr b/src/test/ui/privacy/private-item-simple.stderr index 811b026eab9e3..468bfeaf32e9d 100644 --- a/src/test/ui/privacy/private-item-simple.stderr +++ b/src/test/ui/privacy/private-item-simple.stderr @@ -1,8 +1,8 @@ error[E0603]: function `f` is private - --> $DIR/private-item-simple.rs:16:5 + --> $DIR/private-item-simple.rs:16:8 | LL | a::f(); //~ ERROR function `f` is private - | ^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/privacy/restricted/test.stderr b/src/test/ui/privacy/restricted/test.stderr index 67a95c3559018..afc3ee2db4b8f 100644 --- a/src/test/ui/privacy/restricted/test.stderr +++ b/src/test/ui/privacy/restricted/test.stderr @@ -23,16 +23,16 @@ LL | pub(super) use foo::bar::f as g; //~ ERROR cannot be re-exported | ^^^^^^^^^^^^^^^^ error[E0603]: struct `Crate` is private - --> $DIR/test.rs:48:9 + --> $DIR/test.rs:48:25 | LL | use pub_restricted::Crate; //~ ERROR private - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ error[E0603]: function `f` is private - --> $DIR/test.rs:40:9 + --> $DIR/test.rs:40:19 | LL | use foo::bar::f; //~ ERROR private - | ^^^^^^^^^^^ + | ^ error[E0616]: field `x` of struct `foo::bar::S` is private --> $DIR/test.rs:41:5 diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index d8ab21ddb5f39..8e08f124d6807 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -132,28 +132,28 @@ LL | use m::n::Z; | error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:67:16 + --> $DIR/privacy-enum-ctor.rs:67:22 | LL | let _: Z = m::n::Z; - | ^^^^^^^ + | ^ error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:71:16 + --> $DIR/privacy-enum-ctor.rs:71:22 | LL | let _: Z = m::n::Z::Fn; - | ^^^^^^^^^^^ + | ^ error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:74:16 + --> $DIR/privacy-enum-ctor.rs:74:22 | LL | let _: Z = m::n::Z::Struct; - | ^^^^^^^^^^^^^^^ + | ^ error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:78:16 + --> $DIR/privacy-enum-ctor.rs:78:22 | LL | let _: Z = m::n::Z::Unit {}; - | ^^^^^^^^^^^^^ + | ^ error[E0308]: mismatched types --> $DIR/privacy-enum-ctor.rs:37:20 diff --git a/src/test/ui/resolve/privacy-struct-ctor.stderr b/src/test/ui/resolve/privacy-struct-ctor.stderr index 6ea5241fff00c..c4713bd77a87a 100644 --- a/src/test/ui/resolve/privacy-struct-ctor.stderr +++ b/src/test/ui/resolve/privacy-struct-ctor.stderr @@ -38,40 +38,40 @@ LL | use m::S; | error[E0603]: tuple struct `Z` is private - --> $DIR/privacy-struct-ctor.rs:28:9 + --> $DIR/privacy-struct-ctor.rs:28:12 | LL | n::Z; - | ^^^^ + | ^ error[E0603]: tuple struct `S` is private - --> $DIR/privacy-struct-ctor.rs:39:5 + --> $DIR/privacy-struct-ctor.rs:39:8 | LL | m::S; - | ^^^^ + | ^ error[E0603]: tuple struct `S` is private - --> $DIR/privacy-struct-ctor.rs:41:16 + --> $DIR/privacy-struct-ctor.rs:41:19 | LL | let _: S = m::S(2); - | ^^^^ + | ^ error[E0603]: tuple struct `Z` is private - --> $DIR/privacy-struct-ctor.rs:45:5 + --> $DIR/privacy-struct-ctor.rs:45:11 | LL | m::n::Z; - | ^^^^^^^ + | ^ error[E0603]: tuple struct `S` is private - --> $DIR/privacy-struct-ctor.rs:51:5 + --> $DIR/privacy-struct-ctor.rs:51:16 | LL | xcrate::m::S; - | ^^^^^^^^^^^^ + | ^ error[E0603]: tuple struct `Z` is private - --> $DIR/privacy-struct-ctor.rs:55:5 + --> $DIR/privacy-struct-ctor.rs:55:19 | LL | xcrate::m::n::Z; - | ^^^^^^^^^^^^^^^ + | ^ error: aborting due to 10 previous errors diff --git a/src/test/ui/resolve/resolve-bad-import-prefix.rs b/src/test/ui/resolve/resolve-bad-import-prefix.rs index 370782fc7d9e9..5da5a8c3fef62 100644 --- a/src/test/ui/resolve/resolve-bad-import-prefix.rs +++ b/src/test/ui/resolve/resolve-bad-import-prefix.rs @@ -17,8 +17,8 @@ use {}; // OK use ::{}; // OK use m::{}; // OK use E::{}; // OK -use S::{}; //~ ERROR expected module or enum, found struct `S` -use Tr::{}; //~ ERROR expected module or enum, found trait `Tr` -use Nonexistent::{}; //~ ERROR cannot find module or enum `Nonexistent` in the crate root +use S::{}; // FIXME, this and `use S::{self};` should be an error +use Tr::{}; // FIXME, this and `use Tr::{self};` should be an error +use Nonexistent::{}; //~ ERROR unresolved import `Nonexistent` fn main () {} diff --git a/src/test/ui/resolve/resolve-bad-import-prefix.stderr b/src/test/ui/resolve/resolve-bad-import-prefix.stderr index 76d0c035335c5..c4d9b1d0075d5 100644 --- a/src/test/ui/resolve/resolve-bad-import-prefix.stderr +++ b/src/test/ui/resolve/resolve-bad-import-prefix.stderr @@ -1,24 +1,9 @@ -error[E0577]: expected module or enum, found struct `S` - --> $DIR/resolve-bad-import-prefix.rs:20:5 - | -LL | use S::{}; //~ ERROR expected module or enum, found struct `S` - | -^^^^ - | | - | did you mean `E`? - -error[E0577]: expected module or enum, found trait `Tr` - --> $DIR/resolve-bad-import-prefix.rs:21:5 - | -LL | use Tr::{}; //~ ERROR expected module or enum, found trait `Tr` - | ^^^^^^ not a module or enum - -error[E0578]: cannot find module or enum `Nonexistent` in the crate root +error[E0432]: unresolved import `Nonexistent` --> $DIR/resolve-bad-import-prefix.rs:22:5 | -LL | use Nonexistent::{}; //~ ERROR cannot find module or enum `Nonexistent` in the crate root - | ^^^^^^^^^^^ not found in the crate root +LL | use Nonexistent::{}; //~ ERROR unresolved import `Nonexistent` + | ^^^^^^^^^^^^^^^ no `Nonexistent` in the root -error: aborting due to 3 previous errors +error: aborting due to previous error -Some errors occurred: E0577, E0578. -For more information about an error, try `rustc --explain E0577`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rfc-2008-non-exhaustive/structs.stderr b/src/test/ui/rfc-2008-non-exhaustive/structs.stderr index c0f7e2786716e..141e4b73b58af 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/structs.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/structs.stderr @@ -11,16 +11,16 @@ LL | let us = UnitStruct; | ^^^^^^^^^^ constructor is not visible here due to private fields error[E0603]: tuple struct `TupleStruct` is private - --> $DIR/structs.rs:33:23 + --> $DIR/structs.rs:33:32 | LL | let ts_explicit = structs::TupleStruct(640, 480); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^ error[E0603]: unit struct `UnitStruct` is private - --> $DIR/structs.rs:42:23 + --> $DIR/structs.rs:42:32 | LL | let us_explicit = structs::UnitStruct; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ error[E0639]: cannot create non-exhaustive struct using struct expression --> $DIR/structs.rs:17:14 diff --git a/src/test/ui/rust-2018/local-path-suggestions-2018.stderr b/src/test/ui/rust-2018/local-path-suggestions-2018.stderr index 97bf748881f29..2293f4b001749 100644 --- a/src/test/ui/rust-2018/local-path-suggestions-2018.stderr +++ b/src/test/ui/rust-2018/local-path-suggestions-2018.stderr @@ -3,6 +3,8 @@ error[E0432]: unresolved import `foo` | LL | use foo::Bar; | ^^^ Did you mean `crate::foo`? + | + = note: `use` statements changed in Rust 2018; read more at error[E0432]: unresolved import `foo` --> $DIR/local-path-suggestions-2018.rs:27:5 diff --git a/src/test/ui/shadowed/shadowed-use-visibility.stderr b/src/test/ui/shadowed/shadowed-use-visibility.stderr index 5764ed76ef418..4faaf6cce2435 100644 --- a/src/test/ui/shadowed/shadowed-use-visibility.stderr +++ b/src/test/ui/shadowed/shadowed-use-visibility.stderr @@ -1,14 +1,14 @@ error[E0603]: module `bar` is private - --> $DIR/shadowed-use-visibility.rs:19:9 + --> $DIR/shadowed-use-visibility.rs:19:14 | LL | use foo::bar::f as g; //~ ERROR module `bar` is private - | ^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `f` is private - --> $DIR/shadowed-use-visibility.rs:25:5 + --> $DIR/shadowed-use-visibility.rs:25:10 | LL | use bar::f::f; //~ ERROR module `f` is private - | ^^^^^^^^^ + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/static/static-priv-by-default2.stderr b/src/test/ui/static/static-priv-by-default2.stderr index 0f749b0e4f37a..2631e99a9b77d 100644 --- a/src/test/ui/static/static-priv-by-default2.stderr +++ b/src/test/ui/static/static-priv-by-default2.stderr @@ -1,14 +1,14 @@ error[E0603]: static `private` is private - --> $DIR/static-priv-by-default2.rs:25:9 + --> $DIR/static-priv-by-default2.rs:25:30 | LL | use child::childs_child::private; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error[E0603]: static `private` is private - --> $DIR/static-priv-by-default2.rs:33:9 + --> $DIR/static-priv-by-default2.rs:33:33 | LL | use static_priv_by_default::private; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/structs/struct-variant-privacy-xc.stderr b/src/test/ui/structs/struct-variant-privacy-xc.stderr index 731d23e6a978d..7c214f9dcea0d 100644 --- a/src/test/ui/structs/struct-variant-privacy-xc.stderr +++ b/src/test/ui/structs/struct-variant-privacy-xc.stderr @@ -1,14 +1,14 @@ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy-xc.rs:14:9 + --> $DIR/struct-variant-privacy-xc.rs:14:33 | LL | fn f(b: struct_variant_privacy::Bar) { //~ ERROR enum `Bar` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy-xc.rs:16:9 + --> $DIR/struct-variant-privacy-xc.rs:16:33 | LL | struct_variant_privacy::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/structs/struct-variant-privacy.stderr b/src/test/ui/structs/struct-variant-privacy.stderr index a82ac8ab31867..ffecd88006949 100644 --- a/src/test/ui/structs/struct-variant-privacy.stderr +++ b/src/test/ui/structs/struct-variant-privacy.stderr @@ -1,14 +1,14 @@ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy.rs:16:9 + --> $DIR/struct-variant-privacy.rs:16:14 | LL | fn f(b: foo::Bar) { //~ ERROR enum `Bar` is private - | ^^^^^^^^ + | ^^^ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy.rs:18:9 + --> $DIR/struct-variant-privacy.rs:18:14 | LL | foo::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private - | ^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/unreachable/unreachable-variant.stderr b/src/test/ui/unreachable/unreachable-variant.stderr index fff77586549d3..a998f6b0b8f22 100644 --- a/src/test/ui/unreachable/unreachable-variant.stderr +++ b/src/test/ui/unreachable/unreachable-variant.stderr @@ -1,8 +1,8 @@ error[E0603]: module `super_sekrit` is private - --> $DIR/unreachable-variant.rs:16:14 + --> $DIR/unreachable-variant.rs:16:21 | LL | let _x = other::super_sekrit::sooper_sekrit::baz; //~ ERROR is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/use/use-from-trait-xc.stderr b/src/test/ui/use/use-from-trait-xc.stderr index 130aca8162a43..f8e5e18097ba4 100644 --- a/src/test/ui/use/use-from-trait-xc.stderr +++ b/src/test/ui/use/use-from-trait-xc.stderr @@ -41,16 +41,16 @@ LL | use use_from_trait_xc::Baz::new as baznew; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `new` in `Baz` error[E0603]: struct `Foo` is private - --> $DIR/use-from-trait-xc.rs:24:5 + --> $DIR/use-from-trait-xc.rs:24:24 | LL | use use_from_trait_xc::Foo::new; //~ ERROR struct `Foo` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: struct `Foo` is private - --> $DIR/use-from-trait-xc.rs:27:5 + --> $DIR/use-from-trait-xc.rs:27:24 | LL | use use_from_trait_xc::Foo::C; //~ ERROR struct `Foo` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 9 previous errors diff --git a/src/test/ui/use/use-mod/use-mod-3.rs b/src/test/ui/use/use-mod/use-mod-3.rs index cce500800caca..2ef5fe7947e77 100644 --- a/src/test/ui/use/use-mod/use-mod-3.rs +++ b/src/test/ui/use/use-mod/use-mod-3.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use foo::bar::{ - self //~ ERROR module `bar` is private +use foo::bar::{ //~ ERROR module `bar` is private + self }; -use foo::bar::{ - Bar //~ ERROR module `bar` is private +use foo::bar::{ //~ ERROR module `bar` is private + Bar }; mod foo { diff --git a/src/test/ui/use/use-mod/use-mod-3.stderr b/src/test/ui/use/use-mod/use-mod-3.stderr index 619239846419a..9284091dfa878 100644 --- a/src/test/ui/use/use-mod/use-mod-3.stderr +++ b/src/test/ui/use/use-mod/use-mod-3.stderr @@ -1,14 +1,14 @@ error[E0603]: module `bar` is private - --> $DIR/use-mod-3.rs:12:5 + --> $DIR/use-mod-3.rs:11:10 | -LL | self //~ ERROR module `bar` is private - | ^^^^ +LL | use foo::bar::{ //~ ERROR module `bar` is private + | ^^^ error[E0603]: module `bar` is private - --> $DIR/use-mod-3.rs:15:5 + --> $DIR/use-mod-3.rs:14:10 | -LL | Bar //~ ERROR module `bar` is private - | ^^^ +LL | use foo::bar::{ //~ ERROR module `bar` is private + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/xcrate/xcrate-private-by-default.stderr b/src/test/ui/xcrate/xcrate-private-by-default.stderr index c4560b9ca7752..ea1f6aaa7d2fc 100644 --- a/src/test/ui/xcrate/xcrate-private-by-default.stderr +++ b/src/test/ui/xcrate/xcrate-private-by-default.stderr @@ -1,62 +1,62 @@ error[E0603]: static `j` is private - --> $DIR/xcrate-private-by-default.rs:33:5 + --> $DIR/xcrate-private-by-default.rs:33:29 | LL | static_priv_by_default::j; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: function `k` is private - --> $DIR/xcrate-private-by-default.rs:35:5 + --> $DIR/xcrate-private-by-default.rs:35:29 | LL | static_priv_by_default::k; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: unit struct `l` is private - --> $DIR/xcrate-private-by-default.rs:37:5 + --> $DIR/xcrate-private-by-default.rs:37:29 | LL | static_priv_by_default::l; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: enum `m` is private - --> $DIR/xcrate-private-by-default.rs:39:11 + --> $DIR/xcrate-private-by-default.rs:39:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: type alias `n` is private - --> $DIR/xcrate-private-by-default.rs:41:11 + --> $DIR/xcrate-private-by-default.rs:41:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:45:5 + --> $DIR/xcrate-private-by-default.rs:45:29 | LL | static_priv_by_default::foo::a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:47:5 + --> $DIR/xcrate-private-by-default.rs:47:29 | LL | static_priv_by_default::foo::b; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:49:5 + --> $DIR/xcrate-private-by-default.rs:49:29 | LL | static_priv_by_default::foo::c; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:51:11 + --> $DIR/xcrate-private-by-default.rs:51:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:53:11 + --> $DIR/xcrate-private-by-default.rs:53:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 10 previous errors diff --git a/src/tools/cargo b/src/tools/cargo index 2d0863f657e6f..efb7972a095bc 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 2d0863f657e6f45159fc7412267eee3e659185e5 +Subproject commit efb7972a095bcd043dfd55edca3a3fd1590b34c8