From 12f834190ab13b0410e9cfd52825f6984181193f Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 20 Aug 2018 07:18:30 +0300 Subject: [PATCH 01/10] rustc: remove Ty::{is_self, has_self_ty}. --- src/librustc/hir/lowering.rs | 13 ++------ src/librustc/infer/error_reporting/mod.rs | 32 ++++++++----------- src/librustc/traits/object_safety.rs | 13 +++++--- src/librustc/ty/error.rs | 8 +---- src/librustc/ty/flags.rs | 8 ++--- src/librustc/ty/fold.rs | 3 -- src/librustc/ty/layout.rs | 3 +- src/librustc/ty/mod.rs | 30 ++++++++--------- src/librustc/ty/sty.rs | 18 ----------- src/librustc_lint/builtin.rs | 3 +- src/librustc_typeck/astconv.rs | 4 ++- src/librustc_typeck/collect.rs | 7 ---- .../outlives/implicit_infer.rs | 7 +++- src/librustdoc/clean/simplify.rs | 3 +- .../associated-types-issue-20346.stderr | 2 +- .../reordered-type-param.stderr | 2 +- .../impl-generic-mismatch-ab.stderr | 2 +- .../universal-mismatched-type.stderr | 2 +- .../universal-two-impl-traits.stderr | 6 ++-- src/test/ui/issues/issue-13853.stderr | 2 +- src/test/ui/issues/issue-20225.stderr | 6 ++-- src/test/ui/issues/issue-24204.stderr | 2 +- src/test/ui/issues/issue-2951.rs | 2 +- src/test/ui/issues/issue-2951.stderr | 2 +- .../ui/mismatched_types/issue-35030.stderr | 4 +-- .../struct-path-self-type-mismatch.stderr | 4 +-- src/test/ui/structs/struct-path-self.rs | 6 ++-- src/test/ui/structs/struct-path-self.stderr | 6 ++-- src/test/ui/type/type-parameter-names.rs | 2 +- src/test/ui/type/type-parameter-names.stderr | 2 +- .../type/type-params-in-different-spaces-1.rs | 2 +- .../type-params-in-different-spaces-1.stderr | 2 +- .../type-params-in-different-spaces-3.stderr | 2 +- 33 files changed, 84 insertions(+), 126 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index cb05f7b44c3b9..f24cba349edbe 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2286,15 +2286,6 @@ impl<'a> LoweringContext<'a> { param } GenericParamKind::Type { ref default, .. } => { - // Don't expose `Self` (recovered "keyword used as ident" parse error). - // `rustc::ty` expects `Self` to be only used for a trait's `Self`. - // Instead, use gensym("Self") to create a distinct name that looks the same. - let ident = if param.ident.name == keywords::SelfType.name() { - param.ident.gensym() - } else { - param.ident - }; - let add_bounds = add_bounds.get(¶m.id).map_or(&[][..], |x| &x); if !add_bounds.is_empty() { let params = self.lower_param_bounds(add_bounds, itctx.reborrow()).into_iter(); @@ -2305,11 +2296,11 @@ impl<'a> LoweringContext<'a> { hir::GenericParam { id: self.lower_node_id(param.id).node_id, - name: hir::ParamName::Plain(ident), + name: hir::ParamName::Plain(param.ident), pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), attrs: self.lower_attrs(¶m.attrs), bounds, - span: ident.span, + span: param.ident.span, kind: hir::GenericParamKind::Type { default: default.as_ref().map(|x| { self.lower_ty(x, ImplTraitContext::Disallowed) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index b05ea9a5ed4b0..4688d270e0833 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1117,19 +1117,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let table = table.borrow(); table.local_id_root.and_then(|did| { let generics = self.tcx.generics_of(did); - // Account for the case where `did` corresponds to `Self`, which doesn't have - // the expected type argument. - if !param.is_self() { - let type_param = generics.type_param(param, self.tcx); - let hir = &self.tcx.hir; - hir.as_local_node_id(type_param.def_id).map(|id| { - // Get the `hir::Param` to verify whether it already has any bounds. - // We do this to avoid suggesting code that ends up as `T: 'a'b`, - // instead we suggest `T: 'a + 'b` in that case. - let mut has_bounds = false; - if let hir_map::NodeGenericParam(ref param) = hir.get(id) { - has_bounds = !param.bounds.is_empty(); - } + let type_param = generics.type_param(param, self.tcx); + let hir = &self.tcx.hir; + hir.as_local_node_id(type_param.def_id).and_then(|id| { + // Get the `hir::Param` to verify whether it already has any bounds. + // We do this to avoid suggesting code that ends up as `T: 'a'b`, + // instead we suggest `T: 'a + 'b` in that case. + // Also, `Self` isn't in the HIR so we rule it out here. + if let hir_map::NodeGenericParam(ref hir_param) = hir.get(id) { + let has_bounds = !hir_param.bounds.is_empty(); let sp = hir.span(id); // `sp` only covers `T`, change it so that it covers // `T:` when appropriate @@ -1141,11 +1137,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } else { sp }; - (sp, has_bounds) - }) - } else { - None - } + Some((sp, has_bounds)) + } else { + None + } + }) }) } _ => None, diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 17d55b77625b2..c9f18e30c6b85 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -169,6 +169,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { trait_def_id: DefId, supertraits_only: bool) -> bool { + let trait_self_ty = self.mk_self_type(); let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(self, trait_def_id)); let predicates = if supertraits_only { self.super_predicates_of(trait_def_id) @@ -183,7 +184,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { match predicate { ty::Predicate::Trait(ref data) => { // In the case of a trait predicate, we can skip the "self" type. - data.skip_binder().input_types().skip(1).any(|t| t.has_self_ty()) + data.skip_binder().input_types().skip(1).any(|t| { + t.walk().any(|ty| ty == trait_self_ty) + }) } ty::Predicate::Projection(..) | ty::Predicate::WellFormed(..) | @@ -204,6 +207,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } fn generics_require_sized_self(self, def_id: DefId) -> bool { + let trait_self_ty = self.mk_self_type(); let sized_def_id = match self.lang_items().sized_trait() { Some(def_id) => def_id, None => { return false; /* No Sized trait, can't require it! */ } @@ -216,7 +220,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { .any(|predicate| { match predicate { ty::Predicate::Trait(ref trait_pred) if trait_pred.def_id() == sized_def_id => { - trait_pred.skip_binder().self_ty().is_self() + trait_pred.skip_binder().self_ty() == trait_self_ty } ty::Predicate::Projection(..) | ty::Predicate::Trait(..) | @@ -367,12 +371,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // object type, and we cannot resolve `Self as SomeOtherTrait` // without knowing what `Self` is. + let trait_self_ty = self.mk_self_type(); let mut supertraits: Option>> = None; let mut error = false; ty.maybe_walk(|ty| { match ty.sty { - ty::Param(ref param_ty) => { - if param_ty.is_self() { + ty::Param(_) => { + if ty == trait_self_ty { error = true; } diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index aa6ee420a2162..3fd3b6b55a718 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -222,13 +222,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> { ty::Infer(ty::FreshIntTy(_)) => "skolemized integral type".to_string(), ty::Infer(ty::FreshFloatTy(_)) => "skolemized floating-point type".to_string(), ty::Projection(_) => "associated type".to_string(), - ty::Param(ref p) => { - if p.is_self() { - "Self".to_string() - } else { - "type parameter".to_string() - } - } + ty::Param(_) => format!("`{}` parameter", self), ty::Anon(..) => "anonymized type".to_string(), ty::Error => "type error".to_string(), } diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index b9371ec39ccda..fdaac2670aec5 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -90,13 +90,9 @@ impl FlagComputation { self.add_flags(TypeFlags::HAS_TY_ERR) } - &ty::Param(ref p) => { + &ty::Param(_) => { self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES); - if p.is_self() { - self.add_flags(TypeFlags::HAS_SELF); - } else { - self.add_flags(TypeFlags::HAS_PARAMS); - } + self.add_flags(TypeFlags::HAS_PARAMS); } &ty::Generator(_, ref substs, _) => { diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 26010c3d5f55c..359b522aec95e 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -93,9 +93,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { fn has_param_types(&self) -> bool { self.has_type_flags(TypeFlags::HAS_PARAMS) } - fn has_self_ty(&self) -> bool { - self.has_type_flags(TypeFlags::HAS_SELF) - } fn has_infer_types(&self) -> bool { self.has_type_flags(TypeFlags::HAS_TY_INFER) } diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index d485b9b32d431..437907e1a9e88 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1130,7 +1130,6 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { if !self.tcx.sess.opts.debugging_opts.print_type_sizes || layout.ty.has_param_types() || - layout.ty.has_self_ty() || !self.param_env.caller_bounds.is_empty() { return; @@ -1300,7 +1299,7 @@ impl<'a, 'tcx> SizeSkeleton<'tcx> { let tail = tcx.struct_tail(pointee); match tail.sty { ty::Param(_) | ty::Projection(_) => { - debug_assert!(tail.has_param_types() || tail.has_self_ty()); + debug_assert!(tail.has_param_types()); Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(&tail) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 77b4d32c397d7..a8bb206a00828 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -423,57 +423,54 @@ pub struct CReaderCacheKey { bitflags! { pub struct TypeFlags: u32 { const HAS_PARAMS = 1 << 0; - const HAS_SELF = 1 << 1; - const HAS_TY_INFER = 1 << 2; - const HAS_RE_INFER = 1 << 3; - const HAS_RE_SKOL = 1 << 4; + const HAS_TY_INFER = 1 << 1; + const HAS_RE_INFER = 1 << 2; + const HAS_RE_SKOL = 1 << 3; /// Does this have any `ReEarlyBound` regions? Used to /// determine whether substitition is required, since those /// represent regions that are bound in a `ty::Generics` and /// hence may be substituted. - const HAS_RE_EARLY_BOUND = 1 << 5; + const HAS_RE_EARLY_BOUND = 1 << 4; /// Does this have any region that "appears free" in the type? /// Basically anything but `ReLateBound` and `ReErased`. - const HAS_FREE_REGIONS = 1 << 6; + const HAS_FREE_REGIONS = 1 << 5; /// Is an error type reachable? - const HAS_TY_ERR = 1 << 7; - const HAS_PROJECTION = 1 << 8; + const HAS_TY_ERR = 1 << 6; + const HAS_PROJECTION = 1 << 7; // FIXME: Rename this to the actual property since it's used for generators too - const HAS_TY_CLOSURE = 1 << 9; + const HAS_TY_CLOSURE = 1 << 8; // true if there are "names" of types and regions and so forth // that are local to a particular fn - const HAS_FREE_LOCAL_NAMES = 1 << 10; + const HAS_FREE_LOCAL_NAMES = 1 << 9; // Present if the type belongs in a local type context. // Only set for Infer other than Fresh. - const KEEP_IN_LOCAL_TCX = 1 << 11; + const KEEP_IN_LOCAL_TCX = 1 << 10; // Is there a projection that does not involve a bound region? // Currently we can't normalize projections w/ bound regions. - const HAS_NORMALIZABLE_PROJECTION = 1 << 12; + const HAS_NORMALIZABLE_PROJECTION = 1 << 11; // Set if this includes a "canonical" type or region var -- // ought to be true only for the results of canonicalization. - const HAS_CANONICAL_VARS = 1 << 13; + const HAS_CANONICAL_VARS = 1 << 12; /// Does this have any `ReLateBound` regions? Used to check /// if a global bound is safe to evaluate. - const HAS_RE_LATE_BOUND = 1 << 14; + const HAS_RE_LATE_BOUND = 1 << 13; const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits | - TypeFlags::HAS_SELF.bits | TypeFlags::HAS_RE_EARLY_BOUND.bits; // Flags representing the nominal content of a type, // computed by FlagsComputation. If you add a new nominal // flag, it should be added here too. const NOMINAL_FLAGS = TypeFlags::HAS_PARAMS.bits | - TypeFlags::HAS_SELF.bits | TypeFlags::HAS_TY_INFER.bits | TypeFlags::HAS_RE_INFER.bits | TypeFlags::HAS_RE_SKOL.bits | @@ -1632,7 +1629,6 @@ impl<'tcx> ParamEnv<'tcx> { if value.has_skol() || value.needs_infer() || value.has_param_types() - || value.has_self_ty() { ParamEnvAnd { param_env: self, diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 7c7ee9b330ecc..3784fa2252efb 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -982,17 +982,6 @@ impl<'a, 'gcx, 'tcx> ParamTy { pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { tcx.mk_ty_param(self.idx, self.name) } - - pub fn is_self(&self) -> bool { - // FIXME(#50125): Ignoring `Self` with `idx != 0` might lead to weird behavior elsewhere, - // but this should only be possible when using `-Z continue-parse-after-error` like - // `compile-fail/issue-36638.rs`. - if self.name == keywords::SelfType.name().as_str() && self.idx == 0 { - true - } else { - false - } - } } /// A [De Bruijn index][dbi] is a standard means of representing @@ -1519,13 +1508,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { } } - pub fn is_self(&self) -> bool { - match self.sty { - Param(ref p) => p.is_self(), - _ => false, - } - } - pub fn is_slice(&self) -> bool { match self.sty { RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.sty { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 92a2ea2bf2d7e..0d9994ec65371 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1076,6 +1076,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion { // A trait method, from any number of possible sources. // Attempt to select a concrete impl before checking. ty::TraitContainer(trait_def_id) => { + let trait_self_ty = tcx.mk_self_type(); let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, callee_substs); let trait_ref = ty::Binder::bind(trait_ref); let span = tcx.hir.span(expr_id); @@ -1091,7 +1092,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion { // If `T` is `Self`, then this call is inside // a default method definition. Ok(Some(traits::VtableParam(_))) => { - let on_self = trait_ref.self_ty().is_self(); + let on_self = trait_ref.self_ty() == trait_self_ty; // We can only be recurring in a default // method if we're being called literally // on the `Self` type. diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 9d4481ce6d414..1230d1ca3400e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -597,7 +597,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { let default_needs_object_self = |param: &ty::GenericParamDef| { if let GenericParamDefKind::Type { has_default, .. } = param.kind { if is_object && has_default { - if tcx.at(span).type_of(param.def_id).has_self_ty() { + let trait_self_ty = tcx.mk_self_type(); + let default = tcx.at(span).type_of(param.def_id); + if default.walk().any(|ty| ty == trait_self_ty) { // There is no suitable inference default for a type parameter // that references self, in an object type. return true; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e404eb4ecca49..8273010bef14b 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -979,13 +979,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty synthetic, .. } => { - if param.name.ident().name == keywords::SelfType.name() { - span_bug!( - param.span, - "`Self` should not be the name of a regular parameter" - ); - } - if !allow_defaults && default.is_some() { if !tcx.features().default_type_parameter_fallback { tcx.lint_node( diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index ec36fa0fbc145..c7aa6fb88375e 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -267,6 +267,11 @@ pub fn check_explicit_predicates<'tcx>( debug!("required_predicates = {:?}", required_predicates); let explicit_predicates = explicit_map.explicit_predicates_of(tcx, *def_id); + let ignore_self_ty = if ignore_self_ty { + Some(tcx.mk_self_type()) + } else { + None + }; for outlives_predicate in explicit_predicates.iter() { debug!("outlives_predicate = {:?}", &outlives_predicate); @@ -297,7 +302,7 @@ pub fn check_explicit_predicates<'tcx>( // to apply the substs, and not filter this predicate, we might then falsely // conclude that e.g. `X: 'x` was a reasonable inferred requirement. if let UnpackedKind::Type(ty) = outlives_predicate.0.unpack() { - if ty.is_self() && ignore_self_ty { + if Some(ty) == ignore_self_ty { debug!("skipping self ty = {:?}", &ty); continue; } diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index e938d2d0a1652..61b4c347c86fe 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -156,10 +156,11 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId, if child == trait_ { return true } + let trait_self_ty = cx.tcx.mk_self_type(); let predicates = cx.tcx.super_predicates_of(child).predicates; predicates.iter().filter_map(|pred| { if let ty::Predicate::Trait(ref pred) = *pred { - if pred.skip_binder().trait_ref.self_ty().is_self() { + if pred.skip_binder().trait_ref.self_ty() == trait_self_ty { Some(pred.def_id()) } else { None diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index 6f3dfbe0898ec..7bd698401c964 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving ` as Iterator>::Item == std::op --> $DIR/associated-types-issue-20346.rs:44:5 | LL | is_iterator_of::, _>(&adapter); //~ ERROR type mismatch - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter, found enum `std::option::Option` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `T` parameter, found enum `std::option::Option` | = note: expected type `T` found type `std::option::Option` diff --git a/src/test/ui/compare-method/reordered-type-param.stderr b/src/test/ui/compare-method/reordered-type-param.stderr index 1efd5f2fb258d..6092bd94564fd 100644 --- a/src/test/ui/compare-method/reordered-type-param.stderr +++ b/src/test/ui/compare-method/reordered-type-param.stderr @@ -5,7 +5,7 @@ LL | fn b(&self, x: C) -> C; | - type in trait ... LL | fn b(&self, _x: G) -> G { panic!() } //~ ERROR method `b` has an incompatible type - | ^ expected type parameter, found a different type parameter + | ^ expected `F` parameter, found `G` parameter | = note: expected type `fn(&E, F) -> F` found type `fn(&E, G) -> G` diff --git a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr index 77ecdf2f5acf0..3c25a15142c02 100644 --- a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr +++ b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr @@ -5,7 +5,7 @@ LL | fn foo(&self, a: &A, b: &impl Debug); | -- type in trait ... LL | fn foo(&self, a: &impl Debug, b: &B) { } - | ^^^^^^^^^^^ expected type parameter, found a different type parameter + | ^^^^^^^^^^^ expected `B` parameter, found `impl Debug` parameter | = note: expected type `fn(&(), &B, &impl Debug)` found type `fn(&(), &impl Debug, &B)` diff --git a/src/test/ui/impl-trait/universal-mismatched-type.stderr b/src/test/ui/impl-trait/universal-mismatched-type.stderr index 031db511ff30d..9a85e1b9d7706 100644 --- a/src/test/ui/impl-trait/universal-mismatched-type.stderr +++ b/src/test/ui/impl-trait/universal-mismatched-type.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo(x: impl Debug) -> String { | ------ expected `std::string::String` because of return type LL | x //~ ERROR mismatched types - | ^ expected struct `std::string::String`, found type parameter + | ^ expected struct `std::string::String`, found `impl Debug` parameter | = note: expected type `std::string::String` found type `impl Debug` diff --git a/src/test/ui/impl-trait/universal-two-impl-traits.stderr b/src/test/ui/impl-trait/universal-two-impl-traits.stderr index ed406895fc699..ada72b7c802bf 100644 --- a/src/test/ui/impl-trait/universal-two-impl-traits.stderr +++ b/src/test/ui/impl-trait/universal-two-impl-traits.stderr @@ -2,10 +2,10 @@ error[E0308]: mismatched types --> $DIR/universal-two-impl-traits.rs:15:9 | LL | a = y; //~ ERROR mismatched - | ^ expected type parameter, found a different type parameter + | ^ expected `impl Debug` parameter, found a different `impl Debug` parameter | - = note: expected type `impl Debug` (type parameter) - found type `impl Debug` (type parameter) + = note: expected type `impl Debug` (`impl Debug` parameter) + found type `impl Debug` (`impl Debug` parameter) error: aborting due to previous error diff --git a/src/test/ui/issues/issue-13853.stderr b/src/test/ui/issues/issue-13853.stderr index 188bfd5930105..d85abc66d4dc4 100644 --- a/src/test/ui/issues/issue-13853.stderr +++ b/src/test/ui/issues/issue-13853.stderr @@ -5,7 +5,7 @@ LL | fn nodes<'a, I: Iterator>(&self) -> I | - expected `I` because of return type ... LL | self.iter() //~ ERROR mismatched types - | ^^^^^^^^^^^ expected type parameter, found struct `std::slice::Iter` + | ^^^^^^^^^^^ expected `I` parameter, found struct `std::slice::Iter` | = note: expected type `I` found type `std::slice::Iter<'_, N>` diff --git a/src/test/ui/issues/issue-20225.stderr b/src/test/ui/issues/issue-20225.stderr index 7813dc5c11dba..fc6dbc301a554 100644 --- a/src/test/ui/issues/issue-20225.stderr +++ b/src/test/ui/issues/issue-20225.stderr @@ -2,7 +2,7 @@ error[E0053]: method `call` has an incompatible type for trait --> $DIR/issue-20225.rs:16:3 | LL | extern "rust-call" fn call(&self, (_,): (T,)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found `T` parameter | = note: expected type `extern "rust-call" fn(&Foo, (&'a T,))` found type `extern "rust-call" fn(&Foo, (T,))` @@ -11,7 +11,7 @@ error[E0053]: method `call_mut` has an incompatible type for trait --> $DIR/issue-20225.rs:22:3 | LL | extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found `T` parameter | = note: expected type `extern "rust-call" fn(&mut Foo, (&'a T,))` found type `extern "rust-call" fn(&mut Foo, (T,))` @@ -20,7 +20,7 @@ error[E0053]: method `call_once` has an incompatible type for trait --> $DIR/issue-20225.rs:30:3 | LL | extern "rust-call" fn call_once(self, (_,): (T,)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found `T` parameter | = note: expected type `extern "rust-call" fn(Foo, (&'a T,))` found type `extern "rust-call" fn(Foo, (T,))` diff --git a/src/test/ui/issues/issue-24204.stderr b/src/test/ui/issues/issue-24204.stderr index 809db28403208..fa766198e66bf 100644 --- a/src/test/ui/issues/issue-24204.stderr +++ b/src/test/ui/issues/issue-24204.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<::A as MultiDispatch>:: --> $DIR/issue-24204.rs:24:1 | LL | fn test>(b: i32) -> T where T::A: MultiDispatch { T::new(b) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `T` parameter | = note: expected type `<::A as MultiDispatch>::O` found type `T` diff --git a/src/test/ui/issues/issue-2951.rs b/src/test/ui/issues/issue-2951.rs index 11ff7ab2476b9..9dddb2c6e2f22 100644 --- a/src/test/ui/issues/issue-2951.rs +++ b/src/test/ui/issues/issue-2951.rs @@ -14,7 +14,7 @@ fn foo(x: T, y: U) { //~^ ERROR mismatched types //~| expected type `T` //~| found type `U` - //~| expected type parameter, found a different type parameter + //~| expected `T` parameter, found `U` parameter } fn main() { diff --git a/src/test/ui/issues/issue-2951.stderr b/src/test/ui/issues/issue-2951.stderr index 8c166807c46ad..562937a771cd0 100644 --- a/src/test/ui/issues/issue-2951.stderr +++ b/src/test/ui/issues/issue-2951.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-2951.rs:13:10 | LL | xx = y; - | ^ expected type parameter, found a different type parameter + | ^ expected `T` parameter, found `U` parameter | = note: expected type `T` found type `U` diff --git a/src/test/ui/mismatched_types/issue-35030.stderr b/src/test/ui/mismatched_types/issue-35030.stderr index 062bda4468a39..a085f8f672d93 100644 --- a/src/test/ui/mismatched_types/issue-35030.stderr +++ b/src/test/ui/mismatched_types/issue-35030.stderr @@ -2,9 +2,9 @@ error[E0308]: mismatched types --> $DIR/issue-35030.rs:19:14 | LL | Some(true) //~ ERROR mismatched types - | ^^^^ expected type parameter, found bool + | ^^^^ expected `bool` parameter, found bool | - = note: expected type `bool` (type parameter) + = note: expected type `bool` (`bool` parameter) found type `bool` (bool) error: aborting due to previous error diff --git a/src/test/ui/structs/struct-path-self-type-mismatch.stderr b/src/test/ui/structs/struct-path-self-type-mismatch.stderr index cfba3be613060..347d924ff265d 100644 --- a/src/test/ui/structs/struct-path-self-type-mismatch.stderr +++ b/src/test/ui/structs/struct-path-self-type-mismatch.stderr @@ -8,7 +8,7 @@ error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:25:20 | LL | inner: u - | ^ expected type parameter, found a different type parameter + | ^ expected `T` parameter, found `U` parameter | = note: expected type `T` found type `U` @@ -23,7 +23,7 @@ LL | | //~^ ERROR mismatched types LL | | inner: u LL | | //~^ ERROR mismatched types LL | | } - | |_________^ expected type parameter, found a different type parameter + | |_________^ expected `U` parameter, found `T` parameter | = note: expected type `Foo` found type `Foo` diff --git a/src/test/ui/structs/struct-path-self.rs b/src/test/ui/structs/struct-path-self.rs index 067d6ac22dc6f..59659db0d03ef 100644 --- a/src/test/ui/structs/struct-path-self.rs +++ b/src/test/ui/structs/struct-path-self.rs @@ -13,13 +13,13 @@ struct S; trait Tr { fn f() { let s = Self {}; - //~^ ERROR expected struct, variant or union type, found Self + //~^ ERROR expected struct, variant or union type, found `Self` parameter let z = Self:: {}; - //~^ ERROR expected struct, variant or union type, found Self + //~^ ERROR expected struct, variant or union type, found `Self` parameter //~| ERROR type parameters are not allowed on this type match s { Self { .. } => {} - //~^ ERROR expected struct, variant or union type, found Self + //~^ ERROR expected struct, variant or union type, found `Self` parameter } } } diff --git a/src/test/ui/structs/struct-path-self.stderr b/src/test/ui/structs/struct-path-self.stderr index 1b5506072e81c..37652621cbd6c 100644 --- a/src/test/ui/structs/struct-path-self.stderr +++ b/src/test/ui/structs/struct-path-self.stderr @@ -1,4 +1,4 @@ -error[E0071]: expected struct, variant or union type, found Self +error[E0071]: expected struct, variant or union type, found `Self` parameter --> $DIR/struct-path-self.rs:15:17 | LL | let s = Self {}; @@ -10,13 +10,13 @@ error[E0109]: type parameters are not allowed on this type LL | let z = Self:: {}; | ^^ type parameter not allowed -error[E0071]: expected struct, variant or union type, found Self +error[E0071]: expected struct, variant or union type, found `Self` parameter --> $DIR/struct-path-self.rs:17:17 | LL | let z = Self:: {}; | ^^^^^^^^^^ not a struct -error[E0071]: expected struct, variant or union type, found Self +error[E0071]: expected struct, variant or union type, found `Self` parameter --> $DIR/struct-path-self.rs:21:13 | LL | Self { .. } => {} diff --git a/src/test/ui/type/type-parameter-names.rs b/src/test/ui/type/type-parameter-names.rs index 11a2fc2665ca4..389fdb190dbc9 100644 --- a/src/test/ui/type/type-parameter-names.rs +++ b/src/test/ui/type/type-parameter-names.rs @@ -16,7 +16,7 @@ fn foo(x: Foo) -> Bar { //~^ ERROR mismatched types //~| expected type `Bar` //~| found type `Foo` -//~| expected type parameter, found a different type parameter +//~| expected `Bar` parameter, found `Foo` parameter } fn main() {} diff --git a/src/test/ui/type/type-parameter-names.stderr b/src/test/ui/type/type-parameter-names.stderr index 8e3d39357ed0f..c6d4398c70edb 100644 --- a/src/test/ui/type/type-parameter-names.stderr +++ b/src/test/ui/type/type-parameter-names.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo(x: Foo) -> Bar { | --- expected `Bar` because of return type LL | x - | ^ expected type parameter, found a different type parameter + | ^ expected `Bar` parameter, found `Foo` parameter | = note: expected type `Bar` found type `Foo` diff --git a/src/test/ui/type/type-params-in-different-spaces-1.rs b/src/test/ui/type/type-params-in-different-spaces-1.rs index 26eac6adde221..c6385ff733163 100644 --- a/src/test/ui/type/type-params-in-different-spaces-1.rs +++ b/src/test/ui/type/type-params-in-different-spaces-1.rs @@ -15,7 +15,7 @@ trait BrokenAdd: Copy + Add { *self + rhs //~ ERROR mismatched types //~| expected type `Self` //~| found type `T` - //~| expected Self, found type parameter + //~| expected `Self` parameter, found `T` parameter } } diff --git a/src/test/ui/type/type-params-in-different-spaces-1.stderr b/src/test/ui/type/type-params-in-different-spaces-1.stderr index 31f332f609596..1eabf9e8a4975 100644 --- a/src/test/ui/type/type-params-in-different-spaces-1.stderr +++ b/src/test/ui/type/type-params-in-different-spaces-1.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/type-params-in-different-spaces-1.rs:15:17 | LL | *self + rhs //~ ERROR mismatched types - | ^^^ expected Self, found type parameter + | ^^^ expected `Self` parameter, found `T` parameter | = note: expected type `Self` found type `T` diff --git a/src/test/ui/type/type-params-in-different-spaces-3.stderr b/src/test/ui/type/type-params-in-different-spaces-3.stderr index e1b4cbb2ab3f4..ca2366d5865a2 100644 --- a/src/test/ui/type/type-params-in-different-spaces-3.stderr +++ b/src/test/ui/type/type-params-in-different-spaces-3.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn test(u: X) -> Self { | ---- expected `Self` because of return type LL | u //~ ERROR mismatched types - | ^ expected Self, found type parameter + | ^ expected `Self` parameter, found `X` parameter | = note: expected type `Self` found type `X` From 79068b74bd4d4e905d024037c394093c5a6928d6 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 20 Aug 2018 20:12:37 +0300 Subject: [PATCH 02/10] rustc: keep the DefId of type parameters in types (ParamTy). --- src/librustc/ich/impls_ty.rs | 1 + src/librustc/infer/error_reporting/mod.rs | 52 ++++++++----------- src/librustc/traits/object_safety.rs | 16 +++--- src/librustc/traits/util.rs | 2 +- src/librustc/ty/context.rs | 16 +++--- src/librustc/ty/sty.rs | 17 +++--- src/librustc/ty/subst.rs | 4 +- src/librustc_driver/test.rs | 3 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_typeck/astconv.rs | 10 ++-- src/librustc_typeck/check/compare_method.rs | 2 +- src/librustc_typeck/check/intrinsic.rs | 15 +++--- src/librustc_typeck/check/wfcheck.rs | 4 +- src/librustc_typeck/check/writeback.rs | 4 +- src/librustc_typeck/collect.rs | 9 ++-- .../outlives/implicit_infer.rs | 16 +++--- src/librustdoc/clean/mod.rs | 6 +-- src/librustdoc/clean/simplify.rs | 2 +- ...t_outlive_least_region_or_bound.nll.stderr | 5 +- .../type_parameters_captured.nll.stderr | 5 +- .../propagate-from-trait-match.stderr | 5 +- .../ty-outlives/impl-trait-outlives.stderr | 10 ++-- .../projection-implied-bounds.stderr | 4 +- .../projection-one-region-closure.stderr | 14 +++-- ...ram-closure-approximate-lower-bound.stderr | 4 +- ...m-closure-outlives-from-return-type.stderr | 10 ++-- ...-closure-outlives-from-where-clause.stderr | 8 ++- .../ty-param-fn-body-nll-feature.stderr | 4 +- .../nll/ty-outlives/ty-param-fn-body.stderr | 4 +- .../ui/nll/ty-outlives/ty-param-fn.stderr | 10 ++-- ...ions-close-object-into-object-4.nll.stderr | 8 +-- ...ions-close-object-into-object-5.nll.stderr | 10 ++-- ...ons-close-over-type-parameter-1.nll.stderr | 8 +-- ...se-over-type-parameter-multiple.nll.stderr | 5 +- ...regions-close-param-into-object.nll.stderr | 20 ++++--- .../regions-infer-bound-from-trait.nll.stderr | 8 +-- 36 files changed, 169 insertions(+), 154 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index f4c46b6ce09e1..b4798f51fce93 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -940,6 +940,7 @@ for ty::FloatVid impl_stable_hash_for!(struct ty::ParamTy { idx, + def_id, name }); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 4688d270e0833..c9e3e0b968b10 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1112,36 +1112,30 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { { // Attempt to obtain the span of the parameter so we can // suggest adding an explicit lifetime bound to it. - let type_param_span = match (self.in_progress_tables, bound_kind) { - (Some(ref table), GenericKind::Param(ref param)) => { - let table = table.borrow(); - table.local_id_root.and_then(|did| { - let generics = self.tcx.generics_of(did); - let type_param = generics.type_param(param, self.tcx); - let hir = &self.tcx.hir; - hir.as_local_node_id(type_param.def_id).and_then(|id| { - // Get the `hir::Param` to verify whether it already has any bounds. - // We do this to avoid suggesting code that ends up as `T: 'a'b`, - // instead we suggest `T: 'a + 'b` in that case. - // Also, `Self` isn't in the HIR so we rule it out here. - if let hir_map::NodeGenericParam(ref hir_param) = hir.get(id) { - let has_bounds = !hir_param.bounds.is_empty(); - let sp = hir.span(id); - // `sp` only covers `T`, change it so that it covers - // `T:` when appropriate - let sp = if has_bounds { - sp.to(self.tcx - .sess - .source_map() - .next_point(self.tcx.sess.source_map().next_point(sp))) - } else { - sp - }; - Some((sp, has_bounds)) + let type_param_span = match bound_kind { + GenericKind::Param(ref param) => { + self.tcx.hir.as_local_node_id(param.def_id).and_then(|id| { + // Get the `hir::Param` to verify whether it already has any bounds. + // We do this to avoid suggesting code that ends up as `T: 'a'b`, + // instead we suggest `T: 'a + 'b` in that case. + // Also, `Self` isn't in the HIR so we rule it out here. + if let hir_map::NodeGenericParam(ref hir_param) = self.tcx.hir.get(id) { + let has_bounds = !hir_param.bounds.is_empty(); + let sp = self.tcx.hir.span(id); + // `sp` only covers `T`, change it so that it covers + // `T:` when appropriate + let sp = if has_bounds { + sp.to(self.tcx + .sess + .source_map() + .next_point(self.tcx.sess.source_map().next_point(sp))) } else { - None - } - }) + sp + }; + Some((sp, has_bounds)) + } else { + None + } }) } _ => None, diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index c9f18e30c6b85..c441cc0428cf8 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -169,7 +169,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { trait_def_id: DefId, supertraits_only: bool) -> bool { - let trait_self_ty = self.mk_self_type(); + let trait_self_ty = self.mk_self_type(trait_def_id); let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(self, trait_def_id)); let predicates = if supertraits_only { self.super_predicates_of(trait_def_id) @@ -203,11 +203,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } fn trait_has_sized_self(self, trait_def_id: DefId) -> bool { - self.generics_require_sized_self(trait_def_id) + self.generics_require_sized_self(trait_def_id, trait_def_id) } - fn generics_require_sized_self(self, def_id: DefId) -> bool { - let trait_self_ty = self.mk_self_type(); + fn generics_require_sized_self(self, trait_def_id: DefId, def_id: DefId) -> bool { + let trait_self_ty = self.mk_self_type(trait_def_id); let sized_def_id = match self.lang_items().sized_trait() { Some(def_id) => def_id, None => { return false; /* No Sized trait, can't require it! */ } @@ -245,7 +245,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { { // Any method that has a `Self : Sized` requisite is otherwise // exempt from the regulations. - if self.generics_require_sized_self(method.def_id) { + if self.generics_require_sized_self(trait_def_id, method.def_id) { return None; } @@ -262,7 +262,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { -> bool { // Any method that has a `Self : Sized` requisite can't be called. - if self.generics_require_sized_self(method.def_id) { + if self.generics_require_sized_self(trait_def_id, method.def_id) { return false; } @@ -290,7 +290,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let sig = self.fn_sig(method.def_id); - let self_ty = self.mk_self_type(); + let self_ty = self.mk_self_type(trait_def_id); let self_arg_ty = sig.skip_binder().inputs()[0]; if let ExplicitSelf::Other = ExplicitSelf::determine(self_arg_ty, |ty| ty == self_ty) { return Some(MethodViolationCode::NonStandardSelfType); @@ -371,7 +371,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // object type, and we cannot resolve `Self as SomeOtherTrait` // without knowing what `Self` is. - let trait_self_ty = self.mk_self_type(); + let trait_self_ty = self.mk_self_type(trait_def_id); let mut supertraits: Option>> = None; let mut error = false; ty.maybe_walk(|ty| { diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 40f13ac06f56f..27fe28a30835d 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -213,7 +213,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { }, Component::Param(p) => { - let ty = tcx.mk_ty_param(p.idx, p.name); + let ty = p.to_ty(tcx); Some(ty::Predicate::TypeOutlives( ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min)))) }, diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 424139e752736..8f1bb2a219e0b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -76,7 +76,7 @@ use syntax::attr; use syntax::source_map::MultiSpan; use syntax::edition::Edition; use syntax::feature_gate; -use syntax::symbol::{Symbol, keywords, InternedString}; +use syntax::symbol::Symbol; use syntax_pos::Span; use hir; @@ -2556,22 +2556,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.mk_ty(Infer(it)) } - pub fn mk_ty_param(self, - index: u32, - name: InternedString) -> Ty<'tcx> { - self.mk_ty(Param(ParamTy { idx: index, name: name })) + pub fn mk_ty_param(self, def: &ty::GenericParamDef) -> Ty<'tcx> { + ParamTy::for_def(def).to_ty(self) } - pub fn mk_self_type(self) -> Ty<'tcx> { - self.mk_ty_param(0, keywords::SelfType.name().as_interned_str()) + pub fn mk_self_type(self, trait_def_id: DefId) -> Ty<'tcx> { + ParamTy::for_self(trait_def_id).to_ty(self) } - pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> { + pub fn mk_param(self, param: &ty::GenericParamDef) -> Kind<'tcx> { match param.kind { GenericParamDefKind::Lifetime => { self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into() } - GenericParamDefKind::Type {..} => self.mk_ty_param(param.index, param.name).into(), + GenericParamDefKind::Type {..} => self.mk_ty_param(param).into(), } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 3784fa2252efb..71f573db33c4b 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -963,24 +963,25 @@ impl<'tcx> PolyFnSig<'tcx> { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] pub struct ParamTy { pub idx: u32, + pub def_id: DefId, pub name: InternedString, } -impl<'a, 'gcx, 'tcx> ParamTy { - pub fn new(index: u32, name: InternedString) -> ParamTy { - ParamTy { idx: index, name: name } +impl ParamTy { + pub fn new(idx: u32, def_id: DefId, name: ast::Name) -> ParamTy { + ParamTy { idx, def_id, name: name.as_interned_str() } } - pub fn for_self() -> ParamTy { - ParamTy::new(0, keywords::SelfType.name().as_interned_str()) + pub fn for_self(trait_def_id: DefId) -> ParamTy { + ParamTy::new(0, trait_def_id, keywords::SelfType.name()) } pub fn for_def(def: &ty::GenericParamDef) -> ParamTy { - ParamTy::new(def.index, def.name) + ParamTy { idx: def.index, def_id: def.def_id, name: def.name } } - pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { - tcx.mk_ty_param(self.idx, self.name) + pub fn to_ty(self, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { + tcx.mk_ty(ty::Param(self)) } } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 6dadc5070368b..783e211aadeed 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -185,9 +185,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { /// Creates a Substs that maps each generic parameter to itself. pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> &'tcx Substs<'tcx> { - Substs::for_item(tcx, def_id, |param, _| { - tcx.mk_param_from_def(param) - }) + Substs::for_item(tcx, def_id, |param, _| tcx.mk_param(param)) } /// Creates a Substs for generic parameter definitions, diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 175422975e006..09cdf47da7a1e 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -312,8 +312,9 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { } pub fn t_param(&self, index: u32) -> Ty<'tcx> { + let def_id = self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID); let name = format!("T{}", index); - self.infcx.tcx.mk_ty_param(index, Symbol::intern(&name).as_interned_str()) + ty::ParamTy::new(index, def_id, Symbol::intern(&name)).to_ty(self.infcx.tcx) } pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 0d9994ec65371..0a051e5758428 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1076,7 +1076,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion { // A trait method, from any number of possible sources. // Attempt to select a concrete impl before checking. ty::TraitContainer(trait_def_id) => { - let trait_self_ty = tcx.mk_self_type(); + let trait_self_ty = tcx.mk_self_type(trait_def_id); let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, callee_substs); let trait_ref = ty::Binder::bind(trait_ref); let span = tcx.hir.span(expr_id); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 1230d1ca3400e..f2e4e5296a0f9 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -597,7 +597,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { let default_needs_object_self = |param: &ty::GenericParamDef| { if let GenericParamDefKind::Type { has_default, .. } = param.kind { if is_object && has_default { - let trait_self_ty = tcx.mk_self_type(); + let trait_self_ty = tcx.mk_self_type(def_id); let default = tcx.at(span).type_of(param.def_id); if default.walk().any(|ty| ty == trait_self_ty) { // There is no suitable inference default for a type parameter @@ -1412,7 +1412,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { let item_def_id = tcx.hir.local_def_id(item_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)]; - tcx.mk_ty_param(index, tcx.hir.name(node_id).as_interned_str()) + ty::ParamTy::new(index, did, tcx.hir.name(node_id)).to_ty(tcx) } Def::SelfTy(_, Some(def_id)) => { // Self in impl (we know the concrete type). @@ -1422,11 +1422,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { tcx.at(span).type_of(def_id) } - Def::SelfTy(Some(_), None) => { + Def::SelfTy(Some(trait_def_id), None) => { // Self in trait. assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - tcx.mk_self_type() + tcx.mk_self_type(trait_def_id) } Def::AssociatedTy(def_id) => { self.prohibit_generics(&path.segments[..path.segments.len()-2]); @@ -1572,7 +1572,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { GenericParamDefKind::Lifetime => { tcx.types.re_static.into() } - _ => tcx.mk_param_from_def(param) + _ => tcx.mk_param(param) } } }); diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 9aa2ba363ed7a..d17596f4516dd 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -512,7 +512,7 @@ fn compare_self_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let self_string = |method: &ty::AssociatedItem| { let untransformed_self_ty = match method.container { ty::ImplContainer(_) => impl_trait_ref.self_ty(), - ty::TraitContainer(_) => tcx.mk_self_type() + ty::TraitContainer(def_id) => tcx.mk_self_type(def_id), }; let self_arg_ty = *tcx.fn_sig(method.def_id).input(0).skip_binder(); let param_env = ty::ParamEnv::reveal_all(); diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 23872ddf2f64b..a1057e2179982 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -19,7 +19,6 @@ use require_same_types; use rustc_target::spec::abi::Abi; use syntax::ast; -use syntax::symbol::Symbol; use syntax_pos::Span; use rustc::hir; @@ -76,7 +75,9 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// and in libcore/intrinsics.rs pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &hir::ForeignItem) { - let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n)).as_interned_str()); + let def_id = tcx.hir.local_def_id(it.id); + let generics = tcx.generics_of(def_id); + let param = |n| tcx.mk_ty_param(&generics.params[n]); let name = it.name.as_str(); let (n_tps, inputs, output) = if name.starts_with("atomic_") { let split : Vec<&str> = name.split('_').collect(); @@ -335,13 +336,11 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// Type-check `extern "platform-intrinsic" { ... }` functions. pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &hir::ForeignItem) { - let param = |n| { - let name = Symbol::intern(&format!("P{}", n)).as_interned_str(); - tcx.mk_ty_param(n, name) - }; - let def_id = tcx.hir.local_def_id(it.id); - let i_n_tps = tcx.generics_of(def_id).own_counts().types; + let generics = tcx.generics_of(def_id); + let param = |n| tcx.mk_ty_param(&generics.params[n]); + + let i_n_tps = generics.own_counts().types; let name = it.name.as_str(); let (n_tps, inputs, output) = match &*name { diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 99e0e8775b0cd..9b43221278745 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -183,7 +183,7 @@ fn check_associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let item = fcx.tcx.associated_item(fcx.tcx.hir.local_def_id(item_id)); let (mut implied_bounds, self_ty) = match item.container { - ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()), + ty::TraitContainer(def_id) => (vec![], fcx.tcx.mk_self_type(def_id)), ty::ImplContainer(def_id) => (fcx.impl_implied_bounds(def_id, span), fcx.tcx.type_of(def_id)) }; @@ -431,7 +431,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( match param.kind { GenericParamDefKind::Lifetime => { // All regions are identity. - fcx.tcx.mk_param_from_def(param) + fcx.tcx.mk_param(param) } GenericParamDefKind::Type {..} => { // If the param has a default, diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 0d8401c1c86ef..e01509bcfde50 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -433,9 +433,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { if subst == ty { // found it in the substitution list, replace with the // parameter from the existential type - return self.tcx() - .global_tcx() - .mk_ty_param(param.index, param.name); + return self.tcx().global_tcx().mk_ty_param(param); } } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8273010bef14b..7a57758a53dcd 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -249,7 +249,7 @@ fn type_param_predicates<'a, 'tcx>( let param_owner_def_id = tcx.hir.local_def_id(param_owner); let generics = tcx.generics_of(param_owner_def_id); let index = generics.param_def_id_to_index[&def_id]; - let ty = tcx.mk_ty_param(index, tcx.hir.ty_param_name(param_id).as_interned_str()); + let ty = ty::ParamTy::new(index, def_id, tcx.hir.ty_param_name(param_id)).to_ty(tcx); // Don't look for bounds where the type parameter isn't in scope. let parent = if item_def_id == param_owner_def_id { @@ -683,7 +683,7 @@ fn super_predicates_of<'a, 'tcx>( let icx = ItemCtxt::new(tcx, trait_def_id); // Convert the bounds that follow the colon, e.g. `Bar+Zed` in `trait Foo : Bar+Zed`. - let self_param_ty = tcx.mk_self_type(); + let self_param_ty = tcx.mk_self_type(trait_def_id); let superbounds1 = compute_bounds(&icx, self_param_ty, bounds, SizedByDefault::No, item.span); let superbounds1 = superbounds1.predicates(tcx, self_param_ty); @@ -1773,8 +1773,9 @@ fn explicit_predicates_of<'a, 'tcx>( for param in &ast_generics.params { match param.kind { GenericParamKind::Type { .. } => { - let name = param.name.ident().as_interned_str(); - let param_ty = ty::ParamTy::new(index, name).to_ty(tcx); + let def_id = tcx.hir.local_def_id(param.id); + let name = param.name.ident().name; + let param_ty = ty::ParamTy::new(index, def_id, name).to_ty(tcx); index += 1; let sized = SizedByDefault::Yes; diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index c7aa6fb88375e..5a4e5c070f902 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -187,7 +187,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( // let _: () = substs.region_at(0); check_explicit_predicates( tcx, - &def.did, + def.did, substs, required_predicates, explicit_map, @@ -210,7 +210,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( if let Some(ex_trait_ref) = obj.principal() { check_explicit_predicates( tcx, - &ex_trait_ref.skip_binder().def_id, + ex_trait_ref.skip_binder().def_id, ex_trait_ref.with_self_ty(tcx, ty).skip_binder().substs, required_predicates, explicit_map, @@ -225,7 +225,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( debug!("Projection"); check_explicit_predicates( tcx, - &tcx.associated_item(obj.item_def_id).container.id(), + tcx.associated_item(obj.item_def_id).container.id(), obj.substs, required_predicates, explicit_map, @@ -255,20 +255,20 @@ fn insert_required_predicates_to_be_wf<'tcx>( /// applying the substitution as above. pub fn check_explicit_predicates<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, - def_id: &DefId, + def_id: DefId, substs: &[Kind<'tcx>], required_predicates: &mut RequiredPredicates<'tcx>, explicit_map: &mut ExplicitPredicatesMap<'tcx>, ignore_self_ty: bool, ) { - debug!("def_id = {:?}", &def_id); - debug!("substs = {:?}", &substs); + debug!("def_id = {:?}", def_id); + debug!("substs = {:?}", substs); debug!("explicit_map = {:?}", explicit_map); debug!("required_predicates = {:?}", required_predicates); - let explicit_predicates = explicit_map.explicit_predicates_of(tcx, *def_id); + let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id); let ignore_self_ty = if ignore_self_ty { - Some(tcx.mk_self_type()) + Some(tcx.mk_self_type(def_id)) } else { None }; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5c23d0f6b3990..b8c4798fc3f39 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1971,10 +1971,8 @@ impl<'tcx> Clean for ty::AssociatedItem { if self.method_has_self_argument { let self_ty = match self.container { - ty::ImplContainer(def_id) => { - cx.tcx.type_of(def_id) - } - ty::TraitContainer(_) => cx.tcx.mk_self_type() + ty::ImplContainer(def_id) => cx.tcx.type_of(def_id), + ty::TraitContainer(def_id) => cx.tcx.mk_self_type(def_id), }; let self_arg_ty = *sig.input(0).skip_binder(); if self_arg_ty == self_ty { diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 61b4c347c86fe..8f882fef8af32 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -156,7 +156,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId, if child == trait_ { return true } - let trait_self_ty = cx.tcx.mk_self_type(); + let trait_self_ty = cx.tcx.mk_self_type(child); let predicates = cx.tcx.super_predicates_of(child).predicates; predicates.iter().filter_map(|pred| { if let ty::Predicate::Trait(ref pred) = *pred { diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index 97cb2cc16e45e..6bed7317d8bf4 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -62,10 +62,11 @@ LL | move |_| println!("{}", y) error[E0310]: the parameter type `T` may not live long enough --> $DIR/must_outlive_least_region_or_bound.rs:34:5 | +LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { + | -- help: consider adding an explicit lifetime bound `T: 'static`... +LL | //~^ ERROR the parameter type `T` may not live long enough LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error: aborting due to 5 previous errors diff --git a/src/test/ui/impl-trait/type_parameters_captured.nll.stderr b/src/test/ui/impl-trait/type_parameters_captured.nll.stderr index 823ee4467299e..922c8b831520c 100644 --- a/src/test/ui/impl-trait/type_parameters_captured.nll.stderr +++ b/src/test/ui/impl-trait/type_parameters_captured.nll.stderr @@ -7,10 +7,11 @@ LL | fn foo(x: T) -> impl Any + 'static { error[E0310]: the parameter type `T` may not live long enough --> $DIR/type_parameters_captured.rs:19:5 | +LL | fn foo(x: T) -> impl Any + 'static { + | - help: consider adding an explicit lifetime bound `T: 'static`... +LL | //~^ ERROR the parameter type `T` may not live long enough LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr index 8f8a99df5f052..15fca6f6882eb 100644 --- a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr @@ -46,6 +46,9 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/propagate-from-trait-match.rs:42:36 | +LL | fn supply<'a, T>(value: T) + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | establish_relationships(value, |value| { | ____________________________________^ LL | | //~^ ERROR the parameter type `T` may not live long enough @@ -55,8 +58,6 @@ LL | | // This function call requires that LL | | //~^ WARNING not reporting region error due to nll LL | | }); | |_____^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr index 50b80282e6241..5c5837f709913 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr @@ -13,18 +13,20 @@ LL | fn wrong_region<'a, 'b, T>(x: Box) -> impl Debug + 'a error[E0309]: the parameter type `T` may not live long enough --> $DIR/impl-trait-outlives.rs:22:5 | +LL | fn no_region<'a, T>(x: Box) -> impl Debug + 'a + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... error[E0309]: the parameter type `T` may not live long enough --> $DIR/impl-trait-outlives.rs:38:5 | +LL | fn wrong_region<'a, 'b, T>(x: Box) -> impl Debug + 'a + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr b/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr index 0a2bd3247655a..4fa3953de4765 100644 --- a/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr +++ b/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr @@ -7,10 +7,10 @@ LL | twice(value, |value_ref, item| invoke2(value_ref, item)); error[E0310]: the parameter type `T` may not live long enough --> $DIR/projection-implied-bounds.rs:45:18 | +LL | fn generic2(value: T) { + | -- help: consider adding an explicit lifetime bound `T: 'static`... LL | twice(value, |value_ref, item| invoke2(value_ref, item)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index 2b0e682f85161..f75da792dd380 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -65,8 +65,10 @@ error[E0309]: the parameter type `T` may not live long enough | LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:8 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:16), 'a))`... | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:8 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:16), 'a))`... +LL | fn no_relationships_late<'a, 'b, T: ReFree(DefId(0/0:8 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:16), 'a))>(cell: Cell<&'a ()>, t: T) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements --> $DIR/projection-one-region-closure.rs:67:29 @@ -117,10 +119,11 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-one-region-closure.rs:67:29 | +LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T) + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... note: External requirements --> $DIR/projection-one-region-closure.rs:89:29 @@ -171,10 +174,11 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-one-region-closure.rs:89:29 | +LL | fn projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T) + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... note: External requirements --> $DIR/projection-one-region-closure.rs:102:29 diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index 87f55b4e14d96..ab7ecfff012ae 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -80,8 +80,10 @@ error[E0309]: the parameter type `T` may not live long enough | LL | twice(cell, value, |a, b| invoke(a, b)); | ^^^^^^^^^^^^^^^^^^^ +help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:6 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(crate0:DefIndex(1:15), 'a))`... | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:6 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(crate0:DefIndex(1:15), 'a))`... +LL | fn generic_fail<'a, T: ReFree(DefId(0/0:6 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(crate0:DefIndex(1:15), 'a))>(cell: Cell<&'a ()>, value: T) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr index aec0d98c79aa4..c03c75e3ee573 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr @@ -45,18 +45,20 @@ LL | | } error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-return-type.rs:36:23 | +LL | fn no_region<'a, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | with_signature(x, |y| y) | ^^^^^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-return-type.rs:52:5 | +LL | fn wrong_region<'a, 'b, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... +... LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr index 67a158860d64c..ea58608cb0fff 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr @@ -59,8 +59,10 @@ LL | | // See `correct_region`, which explains the point of this LL | | //~^ WARNING not reporting region error due to nll LL | | }) | |_____^ +help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:6 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(crate0:DefIndex(1:14), 'a))`... | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:6 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(crate0:DefIndex(1:14), 'a))`... +LL | fn no_region<'a, T: ReFree(DefId(0/0:6 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(crate0:DefIndex(1:14), 'a))>(a: Cell<&'a ()>, b: T) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:54:26 @@ -150,8 +152,10 @@ LL | | require(&x, &y) LL | | //~^ WARNING not reporting region error due to nll LL | | }) | |_____^ +help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:8 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(crate0:DefIndex(1:20), 'a))`... | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:8 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(crate0:DefIndex(1:20), 'a))`... +LL | fn wrong_region<'a, 'b, T: ReFree(DefId(0/0:8 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(crate0:DefIndex(1:20), 'a))>(a: Cell<&'a ()>, b: T) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:89:26 diff --git a/src/test/ui/nll/ty-outlives/ty-param-fn-body-nll-feature.stderr b/src/test/ui/nll/ty-outlives/ty-param-fn-body-nll-feature.stderr index dec15f47a0301..addcae4f19066 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-fn-body-nll-feature.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-fn-body-nll-feature.stderr @@ -1,10 +1,10 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn-body-nll-feature.rs:30:5 | +LL | fn region_static<'a, T>(cell: Cell<&'a usize>, t: T) { + | - help: consider adding an explicit lifetime bound `T: 'a`... LL | outlives(cell, t) | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr b/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr index 537f12234708e..900231d38fcbf 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr @@ -7,10 +7,10 @@ LL | outlives(cell, t) error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn-body.rs:29:5 | +LL | fn region_static<'a, T>(cell: Cell<&'a usize>, t: T) { + | - help: consider adding an explicit lifetime bound `T: 'a`... LL | outlives(cell, t) | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-fn.stderr b/src/test/ui/nll/ty-outlives/ty-param-fn.stderr index 5ce50d8118578..982821918c706 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-fn.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-fn.stderr @@ -13,18 +13,20 @@ LL | x error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn.rs:21:5 | +LL | fn no_region<'a, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound `T: 'a`... +... LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-fn.rs:37:5 | +LL | fn wrong_region<'a, 'b, T>(x: Box) -> Box + | - help: consider adding an explicit lifetime bound `T: 'a`... +... LL | x | ^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... error: aborting due to 2 previous errors diff --git a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr index e01ae145e90d9..b9bd078d1bcff 100644 --- a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr @@ -42,18 +42,18 @@ LL | | } error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:20:5 | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | - help: consider adding an explicit lifetime bound `U: 'static`... LL | box B(&*v) as Box //~ ERROR cannot infer | ^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `U: 'static`... error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:20:9 | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | - help: consider adding an explicit lifetime bound `U: 'static`... LL | box B(&*v) as Box //~ ERROR cannot infer | ^^^^^^ - | - = help: consider adding an explicit lifetime bound `U: 'static`... error[E0597]: `*v` does not live long enough --> $DIR/regions-close-object-into-object-4.rs:20:11 diff --git a/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr index d7f9253d0b4d2..8228b77b1def0 100644 --- a/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-5.nll.stderr @@ -31,18 +31,20 @@ LL | box B(&*v) as Box error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:27:5 | +LL | fn f<'a, T, U>(v: Box+'static>) -> Box { + | - help: consider adding an explicit lifetime bound `T: 'static`... +LL | // oh dear! LL | box B(&*v) as Box | ^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:27:9 | +LL | fn f<'a, T, U>(v: Box+'static>) -> Box { + | - help: consider adding an explicit lifetime bound `T: 'static`... +LL | // oh dear! LL | box B(&*v) as Box | ^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error[E0597]: `*v` does not live long enough --> $DIR/regions-close-object-into-object-5.rs:27:11 diff --git a/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr b/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr index ff74d46b011ff..67074143ae6f4 100644 --- a/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr +++ b/src/test/ui/regions/regions-close-over-type-parameter-1.nll.stderr @@ -25,18 +25,18 @@ LL | box v as Box error[E0310]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:20:5 | +LL | fn make_object1(v: A) -> Box { + | -- help: consider adding an explicit lifetime bound `A: 'static`... LL | box v as Box | ^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'static`... error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:30:5 | +LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box { + | -- help: consider adding an explicit lifetime bound `A: 'b`... LL | box v as Box | ^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'b`... error: aborting due to 2 previous errors diff --git a/src/test/ui/regions/regions-close-over-type-parameter-multiple.nll.stderr b/src/test/ui/regions/regions-close-over-type-parameter-multiple.nll.stderr index 9e0dd9da0e4bf..420b73cfa1949 100644 --- a/src/test/ui/regions/regions-close-over-type-parameter-multiple.nll.stderr +++ b/src/test/ui/regions/regions-close-over-type-parameter-multiple.nll.stderr @@ -7,10 +7,11 @@ LL | box v as Box //~ ERROR cannot infer an appropriate lifeti error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-multiple.rs:30:5 | +LL | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box { + | -- help: consider adding an explicit lifetime bound `A: 'c`... +LL | // A outlives 'a AND 'b...but not 'c. LL | box v as Box //~ ERROR cannot infer an appropriate lifetime | ^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'c`... error: aborting due to previous error diff --git a/src/test/ui/regions/regions-close-param-into-object.nll.stderr b/src/test/ui/regions/regions-close-param-into-object.nll.stderr index 260a4067e100d..c15dd6084e228 100644 --- a/src/test/ui/regions/regions-close-param-into-object.nll.stderr +++ b/src/test/ui/regions/regions-close-param-into-object.nll.stderr @@ -25,34 +25,38 @@ LL | Box::new(v) //~ ERROR parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:16:5 | +LL | fn p1(v: T) -> Box + | - help: consider adding an explicit lifetime bound `T: 'static`... +... LL | Box::new(v) //~ ERROR parameter type `T` may not live long enough | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:22:5 | +LL | fn p2(v: Box) -> Box + | - help: consider adding an explicit lifetime bound `T: 'static`... +... LL | Box::new(v) //~ ERROR parameter type `T` may not live long enough | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:28:5 | +LL | fn p3<'a,T>(v: T) -> Box + | - help: consider adding an explicit lifetime bound `T: 'a`... +... LL | Box::new(v) //~ ERROR parameter type `T` may not live long enough | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:34:5 | +LL | fn p4<'a,T>(v: Box) -> Box + | - help: consider adding an explicit lifetime bound `T: 'a`... +... LL | Box::new(v) //~ ERROR parameter type `T` may not live long enough | ^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'a`... error: aborting due to 4 previous errors diff --git a/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr b/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr index 25f69031507ec..33de36053c7c9 100644 --- a/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr +++ b/src/test/ui/regions/regions-infer-bound-from-trait.nll.stderr @@ -13,18 +13,18 @@ LL | check_bound(x, a) //~ ERROR parameter type `A` may not live long enough error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-infer-bound-from-trait.rs:43:5 | +LL | fn bar1<'a,A>(x: Inv<'a>, a: A) { + | - help: consider adding an explicit lifetime bound `A: 'a`... LL | check_bound(x, a) //~ ERROR parameter type `A` may not live long enough | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'a`... error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-infer-bound-from-trait.rs:47:5 | +LL | fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) { + | -- help: consider adding an explicit lifetime bound `A: 'a`... LL | check_bound(x, a) //~ ERROR parameter type `A` may not live long enough | ^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `A: 'a`... error: aborting due to 2 previous errors From b3e001baf4421dcaf8d9aa007dc7473ac02d387b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 20 Aug 2018 20:18:29 +0300 Subject: [PATCH 03/10] rustc: unify Generics::{region,type}_param. --- src/librustc/ty/mod.rs | 33 ++++----------------------------- src/librustc/ty/util.rs | 16 +++++++--------- 2 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index a8bb206a00828..525225b9bc5f5 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -939,37 +939,12 @@ impl<'a, 'gcx, 'tcx> Generics { } } - pub fn region_param(&'tcx self, - param: &EarlyBoundRegion, - tcx: TyCtxt<'a, 'gcx, 'tcx>) - -> &'tcx GenericParamDef - { - if let Some(index) = param.index.checked_sub(self.parent_count as u32) { - let param = &self.params[index as usize]; - match param.kind { - ty::GenericParamDefKind::Lifetime => param, - _ => bug!("expected lifetime parameter, but found another generic parameter") - } - } else { - tcx.generics_of(self.parent.expect("parent_count>0 but no parent?")) - .region_param(param, tcx) - } - } - - /// Returns the `GenericParamDef` associated with this `ParamTy`. - pub fn type_param(&'tcx self, - param: &ParamTy, - tcx: TyCtxt<'a, 'gcx, 'tcx>) - -> &'tcx GenericParamDef { - if let Some(index) = param.idx.checked_sub(self.parent_count as u32) { - let param = &self.params[index as usize]; - match param.kind { - ty::GenericParamDefKind::Type {..} => param, - _ => bug!("expected type parameter, but found another generic parameter") - } + pub fn param_at(&'tcx self, index: u32, tcx: TyCtxt<'_, '_, 'tcx>) -> &'tcx GenericParamDef { + if let Some(index) = index.checked_sub(self.parent_count as u32) { + &self.params[index as usize] } else { tcx.generics_of(self.parent.expect("parent_count>0 but no parent?")) - .type_param(param, tcx) + .param_at(index, tcx) } } } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 938cdf3048b1c..09b2ee6a983cb 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -498,21 +498,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let result = item_substs.iter().zip(impl_substs.iter()) .filter(|&(_, &k)| { - match k.unpack() { - UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => { - !impl_generics.region_param(ebr, self).pure_wrt_drop - } + let index = match k.unpack() { + UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => + ebr.index, UnpackedKind::Type(&ty::TyS { sty: ty::Param(ref pt), .. - }) => { - !impl_generics.type_param(pt, self).pure_wrt_drop - } + }) => pt.idx, UnpackedKind::Lifetime(_) | UnpackedKind::Type(_) => { // not a type or region param - this should be reported // as an error. - false + return false; } - } + }; + !impl_generics.param_at(index, self).pure_wrt_drop }).map(|(&item_param, _)| item_param).collect(); debug!("destructor_constraint({:?}) = {:?}", def.did, result); result From 0d5122acacf0e76020edbb82b47b00523686d1d7 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 21 Aug 2018 00:20:47 +0300 Subject: [PATCH 04/10] rustc: support cross-crate DefId's in ty_param_{name,owner}. --- src/librustc/hir/map/mod.rs | 21 -------- src/librustc/infer/region_constraints/mod.rs | 4 +- src/librustc/traits/util.rs | 2 +- src/librustc/ty/context.rs | 16 ++++-- src/librustc/ty/mod.rs | 23 +++++++++ src/librustc/ty/query/config.rs | 3 +- src/librustc/ty/sty.rs | 20 +------- src/librustc_driver/test.rs | 6 ++- src/librustc_typeck/astconv.rs | 5 +- src/librustc_typeck/check/mod.rs | 4 +- src/librustc_typeck/collect.rs | 13 ++--- src/librustc_typeck/impl_wf_check.rs | 52 +++++++------------- src/librustc_typeck/outlives/utils.rs | 2 +- 13 files changed, 72 insertions(+), 99 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index c3112da4f8c3a..2438c2f49747f 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -602,27 +602,6 @@ impl<'hir> Map<'hir> { } } - pub fn ty_param_owner(&self, id: NodeId) -> NodeId { - match self.get(id) { - NodeItem(&Item { node: ItemKind::Trait(..), .. }) => id, - NodeGenericParam(_) => self.get_parent_node(id), - _ => { - bug!("ty_param_owner: {} not a type parameter", - self.node_to_string(id)) - } - } - } - - pub fn ty_param_name(&self, id: NodeId) -> Name { - match self.get(id) { - NodeItem(&Item { node: ItemKind::Trait(..), .. }) => { - keywords::SelfType.name() - } - NodeGenericParam(param) => param.name.ident().name, - _ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)), - } - } - pub fn trait_impls(&self, trait_did: DefId) -> &'hir [NodeId] { self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls)); diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index 296808cea2bd7..cbafa47f774fd 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -875,8 +875,8 @@ impl<'tcx> fmt::Display for GenericKind<'tcx> { impl<'a, 'gcx, 'tcx> GenericKind<'tcx> { pub fn to_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match *self { - GenericKind::Param(ref p) => p.to_ty(tcx), - GenericKind::Projection(ref p) => tcx.mk_projection(p.item_def_id, p.substs), + GenericKind::Param(p) => tcx.mk_ty(ty::Param(p)), + GenericKind::Projection(p) => tcx.mk_projection(p.item_def_id, p.substs), } } } diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 27fe28a30835d..640161372a580 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -213,7 +213,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> { }, Component::Param(p) => { - let ty = p.to_ty(tcx); + let ty = tcx.mk_ty(ty::Param(p)); Some(ty::Predicate::TypeOutlives( ty::Binder::dummy(ty::OutlivesPredicate(ty, r_min)))) }, diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 8f1bb2a219e0b..617134177480b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -40,7 +40,7 @@ use traits::{Clause, Clauses, Goal, Goals}; use ty::{self, Ty, TypeAndMut}; use ty::{TyS, TyKind, List}; use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const}; -use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate}; +use ty::{PolyFnSig, InferTy, ProjectionTy, ExistentialPredicate, Predicate}; use ty::RegionKind; use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid}; use ty::TyKind::*; @@ -76,7 +76,7 @@ use syntax::attr; use syntax::source_map::MultiSpan; use syntax::edition::Edition; use syntax::feature_gate; -use syntax::symbol::Symbol; +use syntax::symbol::{keywords, Symbol}; use syntax_pos::Span; use hir; @@ -2557,11 +2557,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn mk_ty_param(self, def: &ty::GenericParamDef) -> Ty<'tcx> { - ParamTy::for_def(def).to_ty(self) + self.mk_ty(ty::Param(ty::ParamTy { + idx: def.index, + def_id: def.def_id, + name: def.name, + })) } pub fn mk_self_type(self, trait_def_id: DefId) -> Ty<'tcx> { - ParamTy::for_self(trait_def_id).to_ty(self) + self.mk_ty(ty::Param(ty::ParamTy { + idx: 0, + def_id: trait_def_id, + name: keywords::SelfType.name().as_interned_str(), + })) } pub fn mk_param(self, param: &ty::GenericParamDef) -> Kind<'tcx> { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 525225b9bc5f5..e87c7595586b2 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2637,6 +2637,29 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } + pub fn ty_param_name(&self, id: DefId) -> InternedString { + let def_key = self.def_key(id); + match def_key.disambiguated_data.data { + DefPathData::Trait(_) => { + keywords::SelfType.name().as_interned_str() + } + DefPathData::TypeParam(name) => name, + _ => bug!("ty_param_name: {:?} not a type parameter", id), + } + } + + pub fn ty_param_owner(&self, id: DefId) -> DefId { + let def_key = self.def_key(id); + match def_key.disambiguated_data.data { + DefPathData::Trait(_) => id, + DefPathData::TypeParam(_) => DefId { + krate: id.krate, + index: def_key.parent.unwrap() + }, + _ => bug!("ty_param_owner: {:?} not a type parameter", id), + } + } + /// Return the possibly-auto-generated MIR of a (DefId, Subst) pair. pub fn instance_mir(self, instance: ty::InstanceDef<'gcx>) -> &'gcx Mir<'gcx> diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index b5093d0a1fc95..8659071616d6d 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -212,9 +212,8 @@ impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> { fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String { - let id = tcx.hir.as_local_node_id(def_id).unwrap(); format!("computing the bounds for type parameter `{}`", - tcx.hir.ty_param_name(id)) + tcx.ty_param_name(def_id)) } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 71f573db33c4b..93e0669c82750 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -26,7 +26,7 @@ use std::iter; use std::cmp::Ordering; use rustc_target::spec::abi; use syntax::ast::{self, Ident}; -use syntax::symbol::{keywords, InternedString}; +use syntax::symbol::InternedString; use serialize; @@ -967,24 +967,6 @@ pub struct ParamTy { pub name: InternedString, } -impl ParamTy { - pub fn new(idx: u32, def_id: DefId, name: ast::Name) -> ParamTy { - ParamTy { idx, def_id, name: name.as_interned_str() } - } - - pub fn for_self(trait_def_id: DefId) -> ParamTy { - ParamTy::new(0, trait_def_id, keywords::SelfType.name()) - } - - pub fn for_def(def: &ty::GenericParamDef) -> ParamTy { - ParamTy { idx: def.index, def_id: def.def_id, name: def.name } - } - - pub fn to_ty(self, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { - tcx.mk_ty(ty::Param(self)) - } -} - /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In /// particular, imagine a type like this: diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 09cdf47da7a1e..7ce5c8dedfac7 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -314,7 +314,11 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { pub fn t_param(&self, index: u32) -> Ty<'tcx> { let def_id = self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID); let name = format!("T{}", index); - ty::ParamTy::new(index, def_id, Symbol::intern(&name)).to_ty(self.infcx.tcx) + self.infcx.tcx.mk_ty(ty::TyParam(ty::ParamTy { + idx: index, + def_id, + name: Symbol::intern(&name).as_interned_str() + })) } pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f2e4e5296a0f9..b62a051be89e3 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1132,8 +1132,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { traits::transitive_bounds(tcx, &bounds) .filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name)); - let param_node_id = tcx.hir.as_local_node_id(ty_param_def_id).unwrap(); - let param_name = tcx.hir.ty_param_name(param_node_id); + let param_name = tcx.ty_param_name(ty_param_def_id); self.one_bound_for_assoc_type(suitable_bounds, ¶m_name.as_str(), assoc_name, @@ -1412,7 +1411,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { let item_def_id = tcx.hir.local_def_id(item_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)]; - ty::ParamTy::new(index, did, tcx.hir.name(node_id)).to_ty(tcx) + tcx.mk_ty_param(generics.param_at(index, tcx)) } Def::SelfTy(_, Some(def_id)) => { // Self in impl (we know the concrete type). diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 819827abd05a1..b68e467beae74 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1825,9 +1825,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { -> ty::GenericPredicates<'tcx> { let tcx = self.tcx; - let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let item_id = tcx.hir.ty_param_owner(node_id); - let item_def_id = tcx.hir.local_def_id(item_id); + let item_def_id = tcx.ty_param_owner(def_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; ty::GenericPredicates { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 7a57758a53dcd..f462f385808f3 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -244,12 +244,10 @@ fn type_param_predicates<'a, 'tcx>( // written inline like `` or in a where clause like // `where T:Foo`. - let param_id = tcx.hir.as_local_node_id(def_id).unwrap(); - let param_owner = tcx.hir.ty_param_owner(param_id); - let param_owner_def_id = tcx.hir.local_def_id(param_owner); + let param_owner_def_id = tcx.ty_param_owner(def_id); let generics = tcx.generics_of(param_owner_def_id); let index = generics.param_def_id_to_index[&def_id]; - let ty = ty::ParamTy::new(index, def_id, tcx.hir.ty_param_name(param_id)).to_ty(tcx); + let ty = tcx.mk_ty_param(generics.param_at(index, tcx)); // Don't look for bounds where the type parameter isn't in scope. let parent = if item_def_id == param_owner_def_id { @@ -290,7 +288,7 @@ fn type_param_predicates<'a, 'tcx>( | ItemKind::Union(_, ref generics) => generics, ItemKind::Trait(_, _, ref generics, ..) => { // Implied `Self: Trait` and supertrait bounds. - if param_id == item_node_id { + if def_id == item_def_id { result .predicates .push(ty::TraitRef::identity(tcx, item_def_id).to_predicate()); @@ -310,6 +308,7 @@ fn type_param_predicates<'a, 'tcx>( }; let icx = ItemCtxt::new(tcx, item_def_id); + let param_id = tcx.hir.as_local_node_id(def_id).unwrap(); result .predicates .extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty)); @@ -1773,9 +1772,7 @@ fn explicit_predicates_of<'a, 'tcx>( for param in &ast_generics.params { match param.kind { GenericParamKind::Type { .. } => { - let def_id = tcx.hir.local_def_id(param.id); - let name = param.name.ident().name; - let param_ty = ty::ParamTy::new(index, def_id, name).to_ty(tcx); + let param_ty = tcx.mk_ty_param(generics.param_at(index, tcx)); index += 1; let sized = SizedByDefault::Yes; diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 11260b8f11e12..363fd4decddd4 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -26,8 +26,6 @@ use rustc::ty::{self, TyCtxt}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use std::collections::hash_map::Entry::{Occupied, Vacant}; -use syntax_pos::Span; - /// Checks that all the type/lifetime parameters on an impl also /// appear in the trait ref or self-type (or are constrained by a /// where-clause). These rules are needed to ensure that, given a @@ -114,28 +112,28 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }).collect(); for param in &impl_generics.params { - match param.kind { + let ctp_param = ctp::Parameter(param.index); + if input_parameters.contains(&ctp_param) { + continue; + } + let kind = match param.kind { // Disallow ANY unconstrained type parameters. - ty::GenericParamDefKind::Type {..} => { - let param_ty = ty::ParamTy::for_def(param); - if !input_parameters.contains(&ctp::Parameter::from(param_ty)) { - report_unused_parameter(tcx, - tcx.def_span(param.def_id), - "type", - ¶m_ty.to_string()); - } - } + ty::GenericParamDefKind::Type {..} => "type", ty::GenericParamDefKind::Lifetime => { - let param_lt = ctp::Parameter::from(param.to_early_bound_region_data()); - if lifetimes_in_associated_types.contains(¶m_lt) && // (*) - !input_parameters.contains(¶m_lt) { - report_unused_parameter(tcx, - tcx.def_span(param.def_id), - "lifetime", - ¶m.name.to_string()); + if !lifetimes_in_associated_types.contains(&ctp_param) { // (*) + continue; } + "lifetime" } - } + }; + let span = tcx.def_span(param.def_id); + struct_span_err!( + tcx.sess, span, E0207, + "the {} parameter `{}` is not constrained by the \ + impl trait, self type, or predicates", + kind, param.name) + .span_label(span, format!("unconstrained {} parameter", kind)) + .emit(); } // (*) This is a horrible concession to reality. I think it'd be @@ -158,20 +156,6 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // used elsewhere are not projected back out. } -fn report_unused_parameter(tcx: TyCtxt, - span: Span, - kind: &str, - name: &str) -{ - struct_span_err!( - tcx.sess, span, E0207, - "the {} parameter `{}` is not constrained by the \ - impl trait, self type, or predicates", - kind, name) - .span_label(span, format!("unconstrained {} parameter", kind)) - .emit(); -} - /// Enforce that we do not have two items in an impl with the same name. fn enforce_impl_items_are_distinct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_refs: &[hir::ImplItemRef]) diff --git a/src/librustc_typeck/outlives/utils.rs b/src/librustc_typeck/outlives/utils.rs index 0d833c50d7e3b..9f7dd6b729638 100644 --- a/src/librustc_typeck/outlives/utils.rs +++ b/src/librustc_typeck/outlives/utils.rs @@ -77,7 +77,7 @@ pub fn insert_outlives_predicate<'tcx>( // Vec`. Decomposing `Vec` into // components would yield `U`, and we add the // where clause that `U: 'a`. - let ty: Ty<'tcx> = param_ty.to_ty(tcx); + let ty = tcx.mk_ty(ty::Param(param_ty)); required_predicates .insert(ty::OutlivesPredicate(ty.into(), outlived_region)); } From bb163c6988efff97f66d40c76f50c39c8fdff818 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 21 Aug 2018 01:37:52 +0300 Subject: [PATCH 05/10] rustc: remove the name field from ParamTy. --- src/librustc/hir/map/def_collector.rs | 57 ++++++++++++------- src/librustc/ich/impls_ty.rs | 3 +- .../infer/error_reporting/need_type_info.rs | 4 +- src/librustc/infer/mod.rs | 11 ++-- src/librustc/infer/type_variable.rs | 4 +- src/librustc/traits/error_reporting.rs | 4 +- src/librustc/ty/context.rs | 4 +- src/librustc/ty/mod.rs | 22 +++++-- src/librustc/ty/sty.rs | 1 - src/librustc/util/ppaux.rs | 4 +- src/librustc_driver/test.rs | 2 - src/librustc_typeck/astconv.rs | 8 +-- src/librustdoc/clean/mod.rs | 2 +- 13 files changed, 74 insertions(+), 52 deletions(-) diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index cab620aeec548..cf832aee534d4 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -76,23 +76,38 @@ impl<'a> DefCollector<'a> { fn visit_async_fn( &mut self, id: NodeId, - async_node_id: NodeId, - return_impl_trait_id: NodeId, name: Name, span: Span, - visit_fn: impl FnOnce(&mut DefCollector<'a>) + header: &FnHeader, + generics: &'a Generics, + decl: &'a FnDecl, + body: &'a Block, ) { + let (closure_id, return_impl_trait_id) = match header.asyncness { + IsAsync::Async { + closure_id, + return_impl_trait_id, + } => (closure_id, return_impl_trait_id), + _ => unreachable!(), + }; + // For async functions, we need to create their inner defs inside of a // closure to match their desugared representation. let fn_def_data = DefPathData::ValueNs(name.as_interned_str()); let fn_def = self.create_def(id, fn_def_data, ITEM_LIKE_SPACE, span); return self.with_parent(fn_def, |this| { this.create_def(return_impl_trait_id, DefPathData::ImplTrait, REGULAR_SPACE, span); - let closure_def = this.create_def(async_node_id, + + visit::walk_generics(this, generics); + visit::walk_fn_decl(this, decl); + + let closure_def = this.create_def(closure_id, DefPathData::ClosureExpr, REGULAR_SPACE, span); - this.with_parent(closure_def, visit_fn) + this.with_parent(closure_def, |this| { + visit::walk_block(this, body); + }) }) } @@ -122,17 +137,20 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => { return visit::walk_item(self, i); } - ItemKind::Fn(_, FnHeader { asyncness: IsAsync::Async { - closure_id, - return_impl_trait_id, - }, .. }, ..) => { + ItemKind::Fn( + ref decl, + ref header @ FnHeader { asyncness: IsAsync::Async { .. }, .. }, + ref generics, + ref body, + ) => { return self.visit_async_fn( i.id, - closure_id, - return_impl_trait_id, i.ident.name, i.span, - |this| visit::walk_item(this, i) + header, + generics, + decl, + body, ) } ItemKind::Mod(..) => DefPathData::Module(i.ident.as_interned_str()), @@ -233,18 +251,17 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { fn visit_impl_item(&mut self, ii: &'a ImplItem) { let def_data = match ii.node { ImplItemKind::Method(MethodSig { - header: FnHeader { asyncness: IsAsync::Async { - closure_id, - return_impl_trait_id, - }, .. }, .. - }, ..) => { + header: ref header @ FnHeader { asyncness: IsAsync::Async { .. }, .. }, + ref decl, + }, ref body) => { return self.visit_async_fn( ii.id, - closure_id, - return_impl_trait_id, ii.ident.name, ii.span, - |this| visit::walk_impl_item(this, ii) + header, + &ii.generics, + decl, + body, ) } ImplItemKind::Method(..) | ImplItemKind::Const(..) => diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index b4798f51fce93..4983c1f3bb56c 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -940,8 +940,7 @@ for ty::FloatVid impl_stable_hash_for!(struct ty::ParamTy { idx, - def_id, - name + def_id }); impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> { diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 505b1bc032d20..7429e2e19b5aa 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -77,9 +77,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub fn extract_type_name(&self, ty: &'a Ty<'tcx>) -> String { if let ty::Infer(ty::TyVar(ty_vid)) = (*ty).sty { let ty_vars = self.type_variables.borrow(); - if let TypeVariableOrigin::TypeParameterDefinition(_, name) = + if let TypeVariableOrigin::TypeParameterDefinition(_, def_id) = *ty_vars.var_origin(ty_vid) { - name.to_string() + self.tcx.ty_param_name(def_id).to_string() } else { ty.to_string() } diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index a3c9d14eef295..71d3f36a7f74c 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -942,12 +942,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // used in a path such as `Foo::::new()` will // use an inference variable for `C` with `[T, U]` // as the substitutions for the default, `(T, U)`. - let ty_var_id = - self.type_variables - .borrow_mut() - .new_var(self.universe(), - false, - TypeVariableOrigin::TypeParameterDefinition(span, param.name)); + let ty_var_id = self.type_variables.borrow_mut().new_var( + self.universe(), + false, + TypeVariableOrigin::TypeParameterDefinition(span, param.def_id), + ); self.tcx.mk_var(ty_var_id).into() } diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index b1e4fc7c7fc7b..7cf99cffcf397 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use syntax::symbol::InternedString; use syntax_pos::Span; +use hir::def_id::DefId; use ty::{self, Ty}; use std::cmp; @@ -53,7 +53,7 @@ pub enum TypeVariableOrigin { MiscVariable(Span), NormalizeProjectionType(Span), TypeInference(Span), - TypeParameterDefinition(Span, InternedString), + TypeParameterDefinition(Span, DefId), /// one of the upvars or closure kind parameters in a `ClosureSubsts` /// (before it has been determined) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 405b320f3feaf..994563346be25 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1348,11 +1348,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Param(ty::ParamTy {name, ..}) = ty.sty { + if let ty::Param(ty::ParamTy {def_id, ..}) = ty.sty { let infcx = self.infcx; self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var( - TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP, name))) + TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP, def_id))) } else { ty.super_fold_with(self) } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 617134177480b..3a08d259e9a59 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -76,7 +76,7 @@ use syntax::attr; use syntax::source_map::MultiSpan; use syntax::edition::Edition; use syntax::feature_gate; -use syntax::symbol::{keywords, Symbol}; +use syntax::symbol::Symbol; use syntax_pos::Span; use hir; @@ -2560,7 +2560,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.mk_ty(ty::Param(ty::ParamTy { idx: def.index, def_id: def.def_id, - name: def.name, })) } @@ -2568,7 +2567,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.mk_ty(ty::Param(ty::ParamTy { idx: 0, def_id: trait_def_id, - name: keywords::SelfType.name().as_interned_str(), })) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index e87c7595586b2..8d3aff06a1efb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2637,25 +2637,39 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn ty_param_name(&self, id: DefId) -> InternedString { + pub fn ty_param_name(self, id: DefId) -> InternedString { let def_key = self.def_key(id); match def_key.disambiguated_data.data { + DefPathData::TypeParam(name) => name, + DefPathData::ImplTrait => { + let param_owner_def_id = DefId { + krate: id.krate, + index: def_key.parent.unwrap() + }; + let generics = self.generics_of(param_owner_def_id); + let index = generics.param_def_id_to_index[&id]; + generics.param_at(index, self).name + } DefPathData::Trait(_) => { keywords::SelfType.name().as_interned_str() } - DefPathData::TypeParam(name) => name, + DefPathData::ClosureExpr => { + Symbol::intern("").as_interned_str() + } _ => bug!("ty_param_name: {:?} not a type parameter", id), } } - pub fn ty_param_owner(&self, id: DefId) -> DefId { + pub fn ty_param_owner(self, id: DefId) -> DefId { let def_key = self.def_key(id); match def_key.disambiguated_data.data { - DefPathData::Trait(_) => id, + DefPathData::ImplTrait | DefPathData::TypeParam(_) => DefId { krate: id.krate, index: def_key.parent.unwrap() }, + DefPathData::Trait(_) | + DefPathData::ClosureExpr => id, _ => bug!("ty_param_owner: {:?} not a type parameter", id), } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 93e0669c82750..e9157c540521a 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -964,7 +964,6 @@ impl<'tcx> PolyFnSig<'tcx> { pub struct ParamTy { pub idx: u32, pub def_id: DefId, - pub name: InternedString, } /// A [De Bruijn index][dbi] is a standard means of representing diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 0f15c75c2fb36..41ac3cd840204 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -1267,10 +1267,10 @@ define_print! { define_print! { () ty::ParamTy, (self, f, cx) { display { - write!(f, "{}", self.name) + write!(f, "{}", ty::tls::with(|tcx| tcx.ty_param_name(self.def_id))) } debug { - write!(f, "{}/#{}", self.name, self.idx) + write!(f, "{}/#{}", ty::tls::with(|tcx| tcx.ty_param_name(self.def_id)), self.idx) } } } diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 7ce5c8dedfac7..8e4b37848aea1 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -313,11 +313,9 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { pub fn t_param(&self, index: u32) -> Ty<'tcx> { let def_id = self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID); - let name = format!("T{}", index); self.infcx.tcx.mk_ty(ty::TyParam(ty::ParamTy { idx: index, def_id, - name: Symbol::intern(&name).as_interned_str() })) } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index b62a051be89e3..e8450ce98bf3a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1406,11 +1406,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - let node_id = tcx.hir.as_local_node_id(did).unwrap(); - let item_id = tcx.hir.get_parent_node(node_id); - let item_def_id = tcx.hir.local_def_id(item_id); - let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)]; + let param_owner_def_id = tcx.ty_param_owner(did); + let generics = tcx.generics_of(param_owner_def_id); + let index = generics.param_def_id_to_index[&did]; tcx.mk_ty_param(generics.param_at(index, tcx)) } Def::SelfTy(_, Some(def_id)) => { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b8c4798fc3f39..d81bfa1b9df6e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2668,7 +2668,7 @@ impl<'tcx> Clean for Ty<'tcx> { ty::Projection(ref data) => data.clean(cx), - ty::Param(ref p) => Generic(p.name.to_string()), + ty::Param(ref p) => Generic(p.to_string()), ty::Anon(def_id, substs) => { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, From 785ccda1a7174dd015b90aa310f452b8f2bc21c0 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 22 Aug 2018 15:13:20 +0300 Subject: [PATCH 06/10] rustc: pretty-print `impl Trait` on-demand in ty_param_name. --- src/librustc/ty/mod.rs | 52 ++++++++++++++----- src/librustc/util/ppaux.rs | 2 +- .../impl-generic-mismatch-ab.stderr | 6 +-- .../universal-mismatched-type.stderr | 4 +- .../universal-two-impl-traits.stderr | 6 +-- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 8d3aff06a1efb..91b76385c1081 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -42,7 +42,7 @@ use session::DataTypeKind; use serialize::{self, Encodable, Encoder}; use std::cell::RefCell; use std::cmp::{self, Ordering}; -use std::fmt; +use std::fmt::{self, Write}; use std::hash::{Hash, Hasher}; use std::ops::Deref; use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter}; @@ -2640,15 +2640,43 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn ty_param_name(self, id: DefId) -> InternedString { let def_key = self.def_key(id); match def_key.disambiguated_data.data { - DefPathData::TypeParam(name) => name, DefPathData::ImplTrait => { - let param_owner_def_id = DefId { + // HACK(eddyb) on-demand pretty-printing of `impl Trait` + // parameters - hopefully this is not used too often. + + // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, by + // looking up the predicates associated with the owner's def_id. + let predicates_of_owner = self.predicates_of(DefId { krate: id.krate, index: def_key.parent.unwrap() - }; - let generics = self.generics_of(param_owner_def_id); - let index = generics.param_def_id_to_index[&id]; - generics.param_at(index, self).name + }); + + let mut first = true; + let mut is_sized = false; + let mut s = String::from("impl"); + for predicate in predicates_of_owner.predicates { + if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() { + // Ignore bounds other than those on this parameter. + match trait_ref.self_ty().sty { + ty::TyParam(p) if p.def_id == id => {} + _ => continue, + } + + // Don't print +Sized, but rather +?Sized if absent. + if Some(trait_ref.def_id()) == self.lang_items().sized_trait() { + is_sized = true; + continue; + } + + let _ = write!(s, "{}{}", if first { " " } else { "+" }, trait_ref); + first = false; + } + } + if !is_sized { + let _ = write!(s, "{}?Sized", if first { " " } else { "+" }); + } + + Symbol::intern(&s).as_interned_str() } DefPathData::Trait(_) => { keywords::SelfType.name().as_interned_str() @@ -2656,21 +2684,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { DefPathData::ClosureExpr => { Symbol::intern("").as_interned_str() } - _ => bug!("ty_param_name: {:?} not a type parameter", id), + data => data.as_interned_str() } } pub fn ty_param_owner(self, id: DefId) -> DefId { let def_key = self.def_key(id); match def_key.disambiguated_data.data { - DefPathData::ImplTrait | - DefPathData::TypeParam(_) => DefId { + DefPathData::Trait(_) | + DefPathData::ClosureExpr => id, + _ => DefId { krate: id.krate, index: def_key.parent.unwrap() }, - DefPathData::Trait(_) | - DefPathData::ClosureExpr => id, - _ => bug!("ty_param_owner: {:?} not a type parameter", id), } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 41ac3cd840204..a34f58cca2ae5 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -1124,7 +1124,7 @@ define_print! { return Ok(()); } // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, - // by looking up the projections associated with the def_id. + // by looking up the predicates associated with the def_id. let predicates_of = tcx.predicates_of(def_id); let substs = tcx.lift(&substs).unwrap_or_else(|| { tcx.intern_substs(&[]) diff --git a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr index 3c25a15142c02..03b2a38cbb362 100644 --- a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr +++ b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr @@ -5,10 +5,10 @@ LL | fn foo(&self, a: &A, b: &impl Debug); | -- type in trait ... LL | fn foo(&self, a: &impl Debug, b: &B) { } - | ^^^^^^^^^^^ expected `B` parameter, found `impl Debug` parameter + | ^^^^^^^^^^^ expected `B` parameter, found `impl std::fmt::Debug` parameter | - = note: expected type `fn(&(), &B, &impl Debug)` - found type `fn(&(), &impl Debug, &B)` + = note: expected type `fn(&(), &B, &impl std::fmt::Debug)` + found type `fn(&(), &impl std::fmt::Debug, &B)` error: aborting due to previous error diff --git a/src/test/ui/impl-trait/universal-mismatched-type.stderr b/src/test/ui/impl-trait/universal-mismatched-type.stderr index 9a85e1b9d7706..72c2568df5921 100644 --- a/src/test/ui/impl-trait/universal-mismatched-type.stderr +++ b/src/test/ui/impl-trait/universal-mismatched-type.stderr @@ -4,10 +4,10 @@ error[E0308]: mismatched types LL | fn foo(x: impl Debug) -> String { | ------ expected `std::string::String` because of return type LL | x //~ ERROR mismatched types - | ^ expected struct `std::string::String`, found `impl Debug` parameter + | ^ expected struct `std::string::String`, found `impl std::fmt::Debug` parameter | = note: expected type `std::string::String` - found type `impl Debug` + found type `impl std::fmt::Debug` error: aborting due to previous error diff --git a/src/test/ui/impl-trait/universal-two-impl-traits.stderr b/src/test/ui/impl-trait/universal-two-impl-traits.stderr index ada72b7c802bf..33eaf224bed6e 100644 --- a/src/test/ui/impl-trait/universal-two-impl-traits.stderr +++ b/src/test/ui/impl-trait/universal-two-impl-traits.stderr @@ -2,10 +2,10 @@ error[E0308]: mismatched types --> $DIR/universal-two-impl-traits.rs:15:9 | LL | a = y; //~ ERROR mismatched - | ^ expected `impl Debug` parameter, found a different `impl Debug` parameter + | ^ expected `impl std::fmt::Debug` parameter, found a different `impl std::fmt::Debug` parameter | - = note: expected type `impl Debug` (`impl Debug` parameter) - found type `impl Debug` (`impl Debug` parameter) + = note: expected type `impl std::fmt::Debug` (`impl std::fmt::Debug` parameter) + found type `impl std::fmt::Debug` (`impl std::fmt::Debug` parameter) error: aborting due to previous error From 29f7292b7950abf6e68b45e8fa3a292159d19993 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 22 Aug 2018 15:15:29 +0300 Subject: [PATCH 07/10] rustc: rename ty_param_{name,owner} to generic_param_*. --- src/librustc/infer/error_reporting/need_type_info.rs | 2 +- src/librustc/ty/mod.rs | 4 ++-- src/librustc/ty/query/config.rs | 2 +- src/librustc/util/ppaux.rs | 4 ++-- src/librustc_typeck/astconv.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 7429e2e19b5aa..213e8ba8baaf2 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -79,7 +79,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let ty_vars = self.type_variables.borrow(); if let TypeVariableOrigin::TypeParameterDefinition(_, def_id) = *ty_vars.var_origin(ty_vid) { - self.tcx.ty_param_name(def_id).to_string() + self.tcx.generic_param_name(def_id).to_string() } else { ty.to_string() } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 91b76385c1081..af0cc4d003b40 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2637,7 +2637,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn ty_param_name(self, id: DefId) -> InternedString { + pub fn generic_param_name(self, id: DefId) -> InternedString { let def_key = self.def_key(id); match def_key.disambiguated_data.data { DefPathData::ImplTrait => { @@ -2688,7 +2688,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn ty_param_owner(self, id: DefId) -> DefId { + pub fn generic_param_owner(self, id: DefId) -> DefId { let def_key = self.def_key(id); match def_key.disambiguated_data.data { DefPathData::Trait(_) | diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 8659071616d6d..90de5cd863d9b 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -213,7 +213,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> { impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> { fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String { format!("computing the bounds for type parameter `{}`", - tcx.ty_param_name(def_id)) + tcx.generic_param_name(def_id)) } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index a34f58cca2ae5..55f47c65b549b 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -1267,10 +1267,10 @@ define_print! { define_print! { () ty::ParamTy, (self, f, cx) { display { - write!(f, "{}", ty::tls::with(|tcx| tcx.ty_param_name(self.def_id))) + write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(self.def_id))) } debug { - write!(f, "{}/#{}", ty::tls::with(|tcx| tcx.ty_param_name(self.def_id)), self.idx) + write!(f, "{}/#{}", ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)), self.idx) } } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index e8450ce98bf3a..d08f0acd5d1ec 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1132,7 +1132,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { traits::transitive_bounds(tcx, &bounds) .filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name)); - let param_name = tcx.ty_param_name(ty_param_def_id); + let param_name = tcx.generic_param_name(ty_param_def_id); self.one_bound_for_assoc_type(suitable_bounds, ¶m_name.as_str(), assoc_name, @@ -1406,7 +1406,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - let param_owner_def_id = tcx.ty_param_owner(did); + let param_owner_def_id = tcx.generic_param_owner(did); let generics = tcx.generics_of(param_owner_def_id); let index = generics.param_def_id_to_index[&did]; tcx.mk_ty_param(generics.param_at(index, tcx)) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b68e467beae74..d6f609f729569 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1825,7 +1825,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { -> ty::GenericPredicates<'tcx> { let tcx = self.tcx; - let item_def_id = tcx.ty_param_owner(def_id); + let item_def_id = tcx.generic_param_owner(def_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; ty::GenericPredicates { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index f462f385808f3..ec66ebfc126b8 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -244,7 +244,7 @@ fn type_param_predicates<'a, 'tcx>( // written inline like `` or in a where clause like // `where T:Foo`. - let param_owner_def_id = tcx.ty_param_owner(def_id); + let param_owner_def_id = tcx.generic_param_owner(def_id); let generics = tcx.generics_of(param_owner_def_id); let index = generics.param_def_id_to_index[&def_id]; let ty = tcx.mk_ty_param(generics.param_at(index, tcx)); From 22397bf4eda218f49f73a1d3f3b6f0f7774838b5 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 22 Aug 2018 21:36:32 +0300 Subject: [PATCH 08/10] rustc: remove the name field from EarlyBoundRegion and BrNamed. --- src/librustc/ich/impls_ty.rs | 8 +- src/librustc/infer/error_reporting/mod.rs | 8 +- .../nice_region_error/find_anon_type.rs | 8 +- .../nice_region_error/named_anon_conflict.rs | 2 +- .../nice_region_error/static_impl_trait.rs | 4 +- .../error_reporting/nice_region_error/util.rs | 4 +- src/librustc/middle/region.rs | 4 +- src/librustc/traits/auto_trait.rs | 2 +- src/librustc/ty/mod.rs | 8 +- src/librustc/ty/sty.rs | 4 +- src/librustc/ty/subst.rs | 2 +- src/librustc/util/ppaux.rs | 120 ++++++++++++------ .../error_reporting/region_name.rs | 10 +- .../borrow_check/nll/universal_regions.rs | 3 +- src/librustc_typeck/astconv.rs | 18 +-- src/librustc_typeck/check/writeback.rs | 1 - src/librustc_typeck/collect.rs | 1 - src/librustdoc/clean/auto_trait.rs | 6 +- src/librustdoc/clean/mod.rs | 6 +- .../escape-argument-callee.stderr | 2 +- .../escape-argument.stderr | 2 +- ...pagate-approximated-fail-no-postdom.stderr | 2 +- .../propagate-approximated-ref.stderr | 2 +- ...er-to-static-comparing-against-free.stderr | 4 +- ...oximated-shorter-to-static-no-bound.stderr | 2 +- ...mated-shorter-to-static-wrong-bound.stderr | 2 +- .../propagate-approximated-val.stderr | 2 +- .../propagate-despite-same-free-region.stderr | 2 +- ...ail-to-approximate-longer-no-bounds.stderr | 2 +- ...-to-approximate-longer-wrong-bounds.stderr | 2 +- .../return-wrong-bound-region.stderr | 2 +- ...ram-closure-approximate-lower-bound.stderr | 4 +- 32 files changed, 142 insertions(+), 107 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 4983c1f3bb56c..e1bd0fe3fa12c 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -107,18 +107,16 @@ for ty::RegionKind { db.hash_stable(hcx, hasher); i.hash_stable(hcx, hasher); } - ty::ReLateBound(db, ty::BrNamed(def_id, name)) => { + ty::ReLateBound(db, ty::BrNamed(def_id)) => { db.hash_stable(hcx, hasher); def_id.hash_stable(hcx, hasher); - name.hash_stable(hcx, hasher); } ty::ReLateBound(db, ty::BrEnv) => { db.hash_stable(hcx, hasher); } - ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => { + ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index }) => { def_id.hash_stable(hcx, hasher); index.hash_stable(hcx, hasher); - name.hash_stable(hcx, hasher); } ty::ReScope(scope) => { scope.hash_stable(hcx, hasher); @@ -796,7 +794,7 @@ impl_stable_hash_for!(struct ty::FreeRegion { impl_stable_hash_for!(enum ty::BoundRegion { BrAnon(index), - BrNamed(def_id, name), + BrNamed(def_id), BrFresh(index), BrEnv }); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c9e3e0b968b10..838cec8fac7f0 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -202,17 +202,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { }; let (prefix, span) = match *region { ty::ReEarlyBound(ref br) => { + let name = self.generic_param_name(br.def_id); let mut sp = cm.def_span(self.hir.span(node)); if let Some(param) = self.hir.get_generics(scope).and_then(|generics| { - generics.get_named(&br.name) + generics.get_named(&name) }) { sp = param.span; } - (format!("the lifetime {} as defined on", br.name), sp) + (format!("the lifetime {} as defined on", name), sp) } ty::ReFree(ty::FreeRegion { - bound_region: ty::BoundRegion::BrNamed(_, ref name), .. + bound_region: ty::BoundRegion::BrNamed(def_id), .. }) => { + let name = self.generic_param_name(def_id); let mut sp = cm.def_span(self.hir.span(node)); if let Some(param) = self.hir.get_generics(scope).and_then(|generics| { generics.get_named(&name) diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index 21be09b0ba193..ad777774be2fb 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -148,7 +148,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { // Find the index of the named region that was part of the // error. We will then search the function parameters for a bound // region at the right depth with the same index - (Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => { + (Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id)) => { debug!( "EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \ def_id={:?}", @@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { // region at the right depth with the same index ( Some(rl::Region::LateBound(debruijn_index, id, _)), - ty::BrNamed(def_id, _), + ty::BrNamed(def_id), ) => { debug!( "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", @@ -241,7 +241,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> { } } - (Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => { + (Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id)) => { debug!( "EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \ def_id={:?}", @@ -254,7 +254,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> { } } - (Some(rl::Region::LateBound(debruijn_index, id, _)), ty::BrNamed(def_id, _)) => { + (Some(rl::Region::LateBound(debruijn_index, id, _)), ty::BrNamed(def_id)) => { debug!( "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index, diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 4e26a4178b95d..7752ce0bbe52a 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { ty::BrNamed(..) => true, _ => false, }, - ty::ReEarlyBound(ebr) => ebr.has_name(), + ty::ReEarlyBound(ebr) => ebr.has_name(self.tcx), _ => false, } } diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index d25dcd5b045ca..316e0444edda1 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -56,8 +56,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { let lifetime_name = match sup_r { RegionKind::ReFree(FreeRegion { - bound_region: BoundRegion::BrNamed(_, ref name), .. - }) => name.to_string(), + bound_region: BoundRegion::BrNamed(def_id), .. + }) => self.tcx.generic_param_name(*def_id).to_string(), _ => "'_".to_owned(), }; if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) { diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 8cb0df18bc8ff..88a2612602ba4 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region), ty::ReEarlyBound(ref ebr) => ( self.tcx.parent_def_id(ebr.def_id).unwrap(), - ty::BoundRegion::BrNamed(ebr.def_id, ebr.name), + ty::BoundRegion::BrNamed(ebr.def_id), ), _ => return None, // not a free region }; @@ -127,7 +127,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region), ty::ReEarlyBound(ref ebr) => ( self.tcx.parent_def_id(ebr.def_id).unwrap(), - ty::BoundRegion::BrNamed(ebr.def_id, ebr.name), + ty::BoundRegion::BrNamed(ebr.def_id), ), _ => return None, // not a free region }; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index be1d93dbad1b8..eacf0ea20ceac 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -750,9 +750,7 @@ impl<'tcx> ScopeTree { pub fn free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeRegion) -> Scope { let param_owner = match fr.bound_region { - ty::BoundRegion::BrNamed(def_id, _) => { - tcx.parent_def_id(def_id).unwrap() - } + ty::BoundRegion::BrNamed(def_id) => tcx.generic_param_owner(def_id), _ => fr.scope }; diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index ed95aa73078a9..953ecf28f3b1a 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -482,7 +482,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { pub fn region_name(&self, region: Region) -> Option { match region { - &ty::ReEarlyBound(r) => Some(r.name.to_string()), + &ty::ReEarlyBound(r) => Some(self.tcx.generic_param_name(r.def_id).to_string()), _ => None, } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index af0cc4d003b40..e85b4aeaba792 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -821,13 +821,14 @@ pub struct FloatVarValue(pub ast::FloatTy); impl ty::EarlyBoundRegion { pub fn to_bound_region(&self) -> ty::BoundRegion { - ty::BoundRegion::BrNamed(self.def_id, self.name) + ty::BoundRegion::BrNamed(self.def_id) } /// Does this early bound region have a name? Early bound regions normally /// always have names except when using anonymous lifetimes (`'_`). - pub fn has_name(&self) -> bool { - self.name != keywords::UnderscoreLifetime.name().as_interned_str() + pub fn has_name(&self, tcx: TyCtxt) -> bool { + let name = tcx.generic_param_name(self.def_id); + name != keywords::UnderscoreLifetime.name().as_interned_str() } } @@ -862,7 +863,6 @@ impl GenericParamDef { ty::EarlyBoundRegion { def_id: self.def_id, index: self.index, - name: self.name, } } _ => bug!("cannot convert a non-lifetime parameter def to an early bound region") diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index e9157c540521a..f9933f9bd5859 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -26,7 +26,6 @@ use std::iter; use std::cmp::Ordering; use rustc_target::spec::abi; use syntax::ast::{self, Ident}; -use syntax::symbol::InternedString; use serialize; @@ -60,7 +59,7 @@ pub enum BoundRegion { /// /// The def-id is needed to distinguish free regions in /// the event of shadowing. - BrNamed(DefId, InternedString), + BrNamed(DefId), /// Fresh bound identifiers created during GLB computations. BrFresh(u32), @@ -1129,7 +1128,6 @@ impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {} pub struct EarlyBoundRegion { pub def_id: DefId, pub index: u32, - pub name: InternedString, } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 783e211aadeed..8bcaea8cac8ea 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -453,7 +453,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> { "Region parameter out of range \ when substituting in region {} (root type={:?}) \ (index={})", - data.name, + self.tcx().generic_param_name(data.def_id), self.root_ty, data.index); } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 55f47c65b549b..719ef77b89e55 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -28,7 +28,6 @@ use std::usize; use rustc_data_structures::indexed_vec::Idx; use rustc_target::spec::abi::Abi; -use syntax::ast::CRATE_NODE_ID; use syntax::symbol::{Symbol, InternedString}; use hir; @@ -139,8 +138,12 @@ struct LateBoundRegionNameCollector(FxHashSet); impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector { fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool { match *r { - ty::ReLateBound(_, ty::BrNamed(_, name)) => { - self.0.insert(name); + ty::ReLateBound(_, ty::BrAnon(n)) | + ty::ReLateBound(_, ty::BrFresh(n)) => { + assert!(n < PrintContext::ARTIFICIAL_REGION_BASE); + } + ty::ReLateBound(_, ty::BrNamed(def_id)) => { + self.0.insert(ty::tls::with(|tcx| tcx.generic_param_name(def_id))); }, _ => {}, } @@ -154,7 +157,7 @@ pub struct PrintContext { is_verbose: bool, identify_regions: bool, used_region_names: Option>, - region_index: usize, + region_index: u32, binder_depth: usize, } impl PrintContext { @@ -465,6 +468,11 @@ impl PrintContext { Ok(()) } + // HACK(eddyb) Because we can't store names inside regions, we have + // to resort to encoding the regions we want to print in integers. + // Specifically, we use `Br{Anon,Fresh}((1 << 31) + region_index)`. + const ARTIFICIAL_REGION_BASE: u32 = 1 << 31; + fn in_binder<'a, 'gcx, 'tcx, T, U, F>(&mut self, f: &mut F, tcx: TyCtxt<'a, 'gcx, 'tcx>, @@ -472,19 +480,11 @@ impl PrintContext { lifted: Option>) -> fmt::Result where T: Print, U: Print + TypeFoldable<'tcx>, F: fmt::Write { - fn name_by_region_index(index: usize) -> InternedString { - match index { - 0 => Symbol::intern("'r"), - 1 => Symbol::intern("'s"), - i => Symbol::intern(&format!("'t{}", i-2)), - }.as_interned_str() - } - - // Replace any anonymous late-bound regions with named - // variants, using gensym'd identifiers, so that we can - // clearly differentiate between named and unnamed regions in - // the output. We'll probably want to tweak this over time to - // decide just how much information to give. + // Replace any anonymous late-bound regions with artificially named ones + // (see `ARTIFICIAL_REGION_BASE` above), so that we can clearly + // differentiate between named and unnamed regions in the output. + // We'll probably want to tweak this over time to decide just how much + // information to give. let value = if let Some(v) = lifted { v } else { @@ -510,22 +510,34 @@ impl PrintContext { let new_value = tcx.replace_late_bound_regions(&value, |br| { let _ = start_or_continue(f, "for<", ", "); let br = match br { - ty::BrNamed(_, name) => { - let _ = write!(f, "{}", name); + ty::BrNamed(_) => { + let _ = write!(f, "{}", br); br } ty::BrAnon(_) | ty::BrFresh(_) | - ty::BrEnv => { - let name = loop { - let name = name_by_region_index(region_index); - region_index += 1; - if !self.is_name_used(&name) { - break name; + ty::BrEnv => loop { + match br { + ty::BrAnon(n) | ty::BrFresh(n) => { + assert!(n < PrintContext::ARTIFICIAL_REGION_BASE); } + _ => {} + } + + let n = Self::ARTIFICIAL_REGION_BASE + region_index; + let br = match br { + ty::BrFresh(_) => ty::BrFresh(n), + _ => ty::BrAnon(n), }; - let _ = write!(f, "{}", name); - ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), name) + + let mut name = String::new(); + let _ = print_maybe_artificial_region(&mut name, n, false); + + region_index += 1; + if !self.is_name_used(&Symbol::intern(&name).as_interned_str()) { + let _ = write!(f, "{}", name); + break br; + } } }; tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)) @@ -720,6 +732,26 @@ define_print! { } } +fn print_maybe_artificial_region( + f: &mut impl fmt::Write, + n: u32, + print_number: bool, +) -> fmt::Result { + // See ARTIFICIAL_REGION_BASE for more details on this hack. + match n.checked_sub(PrintContext::ARTIFICIAL_REGION_BASE) { + Some(index) => match index { + 0 => write!(f, "'r"), + 1 => write!(f, "'s"), + i => write!(f, "'t{}", i-2), + }, + None => if print_number { + write!(f, "{}", n) + } else { + Ok(()) + }, + } +} + define_print! { () ty::BoundRegion, (self, f, cx) { display { @@ -728,20 +760,34 @@ define_print! { } match *self { - BrNamed(_, name) => write!(f, "{}", name), - BrAnon(_) | BrFresh(_) | BrEnv => Ok(()) + BrNamed(def_id) => { + write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(def_id))) + } + BrAnon(n) | BrFresh(n) => { + print_maybe_artificial_region(f, n, false) + } + BrEnv => Ok(()) } } debug { - return match *self { - BrAnon(n) => write!(f, "BrAnon({:?})", n), - BrFresh(n) => write!(f, "BrFresh({:?})", n), - BrNamed(did, name) => { + match *self { + BrAnon(n) => { + write!(f, "BrAnon(")?; + print_maybe_artificial_region(f, n, true)?; + write!(f, ")") + } + BrFresh(n) => { + write!(f, "BrFresh(")?; + print_maybe_artificial_region(f, n, true)?; + write!(f, ")") + } + BrNamed(did) => { write!(f, "BrNamed({:?}:{:?}, {})", - did.krate, did.index, name) + did.krate, did.index, + ty::tls::with(|tcx| tcx.generic_param_name(did))) } BrEnv => write!(f, "BrEnv"), - }; + } } } } @@ -759,7 +805,7 @@ define_print! { // `explain_region()` or `note_and_explain_region()`. match *self { ty::ReEarlyBound(ref data) => { - write!(f, "{}", data.name) + write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(data.def_id))) } ty::ReCanonical(_) => { write!(f, "'_") @@ -802,7 +848,7 @@ define_print! { ty::ReEarlyBound(ref data) => { write!(f, "ReEarlyBound({}, {})", data.index, - data.name) + ty::tls::with(|tcx| tcx.generic_param_name(data.def_id))) } ty::ReClosureBound(ref vid) => { diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 6177194ab914d..2e85d4ee94577 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -95,9 +95,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("give_region_a_name: error_region = {:?}", error_region); match error_region { ty::ReEarlyBound(ebr) => { - if ebr.has_name() { - self.highlight_named_span(tcx, error_region, &ebr.name, diag); - Some(ebr.name) + if ebr.has_name(tcx) { + let name = tcx.generic_param_name(ebr.def_id); + self.highlight_named_span(tcx, error_region, &name, diag); + Some(name) } else { None } @@ -106,7 +107,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { ty::ReStatic => Some(keywords::StaticLifetime.name().as_interned_str()), ty::ReFree(free_region) => match free_region.bound_region { - ty::BoundRegion::BrNamed(_, name) => { + ty::BoundRegion::BrNamed(def_id) => { + let name = tcx.generic_param_name(def_id); self.highlight_named_span(tcx, error_region, &name, diag); Some(name) }, diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 8112b71b12752..98f0705b5c7a0 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -709,11 +709,10 @@ fn for_each_late_bound_region_defined_on<'tcx>( for late_bound in late_bounds.iter() { let hir_id = HirId{ owner: fn_def_id.index, local_id: *late_bound }; let region_node_id = tcx.hir.hir_to_node_id(hir_id); - let name = tcx.hir.name(region_node_id).as_interned_str(); let region_def_id = tcx.hir.local_def_id(region_node_id); let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion { scope: fn_def_id, - bound_region: ty::BoundRegion::BrNamed(region_def_id, name), + bound_region: ty::BoundRegion::BrNamed(region_def_id), })); f(liberated_region); } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d08f0acd5d1ec..b8b3394dd86a1 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -117,9 +117,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { -> ty::Region<'tcx> { let tcx = self.tcx(); - let lifetime_name = |def_id| { - tcx.hir.name(tcx.hir.as_local_node_id(def_id).unwrap()).as_interned_str() - }; let hir_id = tcx.hir.node_to_hir_id(lifetime.id); let r = match tcx.named_region(hir_id) { @@ -128,9 +125,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { } Some(rl::Region::LateBound(debruijn, id, _)) => { - let name = lifetime_name(id); - tcx.mk_region(ty::ReLateBound(debruijn, - ty::BrNamed(id, name))) + tcx.mk_region(ty::ReLateBound(debruijn, ty::BrNamed(id))) } Some(rl::Region::LateBoundAnon(debruijn, index)) => { @@ -138,19 +133,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { } Some(rl::Region::EarlyBound(index, id, _)) => { - let name = lifetime_name(id); tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: id, index, - name, })) } Some(rl::Region::Free(scope, id)) => { - let name = lifetime_name(id); tcx.mk_region(ty::ReFree(ty::FreeRegion { scope, - bound_region: ty::BrNamed(id, name) + bound_region: ty::BrNamed(id) })) // (*) -- not late-bound, won't change @@ -875,7 +867,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { debug!("late_bound_in_ty = {:?}", late_bound_in_ty); for br in late_bound_in_ty.difference(&late_bound_in_trait_ref) { let br_name = match *br { - ty::BrNamed(_, name) => name, + ty::BrNamed(def_id) => tcx.generic_param_name(def_id), _ => { span_bug!( binding.span, @@ -1633,7 +1625,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output); for br in late_bound_in_ret.difference(&late_bound_in_args) { let lifetime_name = match *br { - ty::BrNamed(_, name) => format!("lifetime `{}`,", name), + ty::BrNamed(def_id) => { + format!("lifetime `{}`,", tcx.generic_param_name(def_id)) + } ty::BrAnon(_) | ty::BrFresh(_) | ty::BrEnv => "an anonymous lifetime".to_string(), }; let mut err = struct_span_err!(tcx.sess, diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index e01509bcfde50..1794513c8f852 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -466,7 +466,6 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { let reg = ty::EarlyBoundRegion { def_id: p.def_id, index: p.index, - name: p.name, }; trace!("replace {:?} with {:?}", region, reg); return self.tcx() diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index ec66ebfc126b8..7ad56d87f1756 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1748,7 +1748,6 @@ fn explicit_predicates_of<'a, 'tcx>( let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: tcx.hir.local_def_id(param.id), index, - name: param.name.ident().as_interned_str(), })); index += 1; diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index de5a680ccf9d1..5959c36dbc500 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -243,7 +243,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { fn region_name(&self, region: Region) -> Option { match region { - &ty::ReEarlyBound(r) => Some(r.name.to_string()), + &ty::ReEarlyBound(_) => Some(region.to_string()), _ => None, } } @@ -414,9 +414,9 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { match r { // We only care about late bound regions, as we need to add them // to the 'for<>' section - &ty::ReLateBound(_, ty::BoundRegion::BrNamed(_, name)) => { + &ty::ReLateBound(_, ty::BoundRegion::BrNamed(_)) => { Some(GenericParamDef { - name: name.to_string(), + name: r.to_string(), kind: GenericParamDefKind::Lifetime, }) }, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d81bfa1b9df6e..ed4fd48212b6e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1249,11 +1249,11 @@ impl<'tcx> Clean for ty::GenericParamDef { } impl Clean> for ty::RegionKind { - fn clean(&self, cx: &DocContext) -> Option { + fn clean(&self, _cx: &DocContext) -> Option { match *self { ty::ReStatic => Some(Lifetime::statik()), - ty::ReLateBound(_, ty::BrNamed(_, name)) => Some(Lifetime(name.to_string())), - ty::ReEarlyBound(ref data) => Some(Lifetime(data.name.clean(cx))), + ty::ReLateBound(_, ty::BrNamed(_)) | + ty::ReEarlyBound(_) => Some(Lifetime(self.to_string())), ty::ReLateBound(..) | ty::ReFree(..) | diff --git a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr index 862d1f0b179c0..0d136e3842e2f 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr @@ -12,7 +12,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y); | = note: defining type: DefId(0/1:9 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) i32)) + for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) mut &ReLateBound(DebruijnIndex(0), BrAnon('s)) i32, &ReLateBound(DebruijnIndex(0), BrAnon('t0)) i32)) ] error: unsatisfied lifetime constraints diff --git a/src/test/ui/nll/closure-requirements/escape-argument.stderr b/src/test/ui/nll/closure-requirements/escape-argument.stderr index a830768b36e1c..773f76811ea03 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument.stderr @@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y); | = note: defining type: DefId(0/1:9 ~ escape_argument[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32)) + for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) mut &ReLateBound(DebruijnIndex(0), BrAnon('s)) i32, &ReLateBound(DebruijnIndex(0), BrAnon('s)) i32)) ] note: No external requirements diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr index 72b7104b99dd3..20a04d8a87279 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr @@ -17,7 +17,7 @@ LL | | }, | = note: defining type: DefId(0/1:20 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>)) + for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>)) ] error: unsatisfied lifetime constraints diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr index fe67ca0293e06..55bfeaea6465e 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr @@ -18,7 +18,7 @@ LL | | }); | = note: defining type: DefId(0/1:18 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>)) + for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t1)) u32>)) ] = note: number of external vids: 5 = note: where '_#1r: '_#2r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 43c39dee2448a..1c543e899fe11 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -17,7 +17,7 @@ LL | | }) | = note: defining type: DefId(0/1:12 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]) with closure substs [ i32, - for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>)) + for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>)) ] error: borrowed data escapes outside of closure @@ -56,7 +56,7 @@ LL | | }) | = note: defining type: DefId(0/1:13 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [ i32, - for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>)) + for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>)) ] = note: number of external vids: 2 = note: where '_#1r: '_#0r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index c3bbf1035dbc5..a33aa381bf298 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -18,7 +18,7 @@ LL | | }); | = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) u32>)) + for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t2)) u32>)) ] = note: number of external vids: 4 = note: where '_#1r: '_#0r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 9f259e2dee590..b95aef2d70cf7 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -18,7 +18,7 @@ LL | | }); | = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>)) + for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrAnon('t1)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t1)) u32>)) ] = note: number of external vids: 5 = note: where '_#1r: '_#0r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr index ed1fc6e1a712f..191799f737c83 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr @@ -18,7 +18,7 @@ LL | | }); | = note: defining type: DefId(0/1:18 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>)) + for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>)) ] = note: number of external vids: 5 = note: where '_#1r: '_#2r diff --git a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr index 0888b1380e69e..558d23cdbf63f 100644 --- a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr @@ -16,7 +16,7 @@ LL | | }, | = note: defining type: DefId(0/1:16 ~ propagate_despite_same_free_region[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>)) + for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>)) ] = note: number of external vids: 4 = note: where '_#1r: '_#2r diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr index cd5e6f29f5f48..0ba1dbc7dd116 100644 --- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr @@ -18,7 +18,7 @@ LL | | }); | = note: defining type: DefId(0/1:18 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>)) + for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t1)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>)) ] error: unsatisfied lifetime constraints diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr index 2176575e0aa12..613391caff2a0 100644 --- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr @@ -18,7 +18,7 @@ LL | | }); | = note: defining type: DefId(0/1:18 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>)) + for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('s)) u32>, &ReLateBound(DebruijnIndex(0), BrAnon('t3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrAnon('t1)) u32>)) ] error: unsatisfied lifetime constraints diff --git a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr index 8dc10de702f7a..859daf04952d4 100644 --- a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr +++ b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr @@ -12,7 +12,7 @@ LL | expect_sig(|a, b| b); // ought to return `a` | = note: defining type: DefId(0/1:9 ~ return_wrong_bound_region[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32)) -> &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) i32 + for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrAnon('r)) i32, &ReLateBound(DebruijnIndex(0), BrAnon('s)) i32)) -> &ReLateBound(DebruijnIndex(0), BrAnon('r)) i32 ] error: unsatisfied lifetime constraints diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index ab7ecfff012ae..a85dcc1c4652c 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -25,7 +25,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); = note: defining type: DefId(0/1:14 ~ ty_param_closure_approximate_lower_bound[317d]::generic[0]::{{closure}}[0]) with closure substs [ T, i16, - for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) T)) + for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrAnon('s)) T)) ] = note: number of external vids: 3 = note: where T: '_#1r @@ -55,7 +55,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); = note: defining type: DefId(0/1:17 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]::{{closure}}[0]) with closure substs [ T, i16, - for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) T)) + for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrAnon('s)) T)) ] = note: number of external vids: 4 = note: where T: '_#1r From d337a3b8891fa3110c01d97fbb66f312ee23585a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 22 Aug 2018 15:15:35 +0300 Subject: [PATCH 09/10] rustc: remove the name field from `ty::GenericParamDef`. --- src/librustc/ich/impls_ty.rs | 1 - src/librustc/infer/error_reporting/mod.rs | 5 ++++- src/librustc/infer/mod.rs | 5 ++--- src/librustc/traits/auto_trait.rs | 4 +++- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/on_unimplemented.rs | 4 ++-- src/librustc/ty/mod.rs | 1 - src/librustc/util/ppaux.rs | 2 +- src/librustc_codegen_llvm/debuginfo/mod.rs | 4 +++- src/librustc_typeck/astconv.rs | 5 +++-- src/librustc_typeck/check/mod.rs | 8 ++++---- src/librustc_typeck/check/wfcheck.rs | 11 +++++++---- src/librustc_typeck/collect.rs | 9 ++------- src/librustc_typeck/impl_wf_check.rs | 2 +- src/librustdoc/clean/mod.rs | 14 +++++++------- src/librustdoc/core.rs | 8 +++++--- 16 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index e1bd0fe3fa12c..d7863d996909c 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -690,7 +690,6 @@ impl_stable_hash_for!(struct ty::Generics { }); impl_stable_hash_for!(struct ty::GenericParamDef { - name, def_id, index, pure_wrt_drop, diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 838cec8fac7f0..b26e29a2a833c 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1338,7 +1338,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { br_string(br), self.tcx.associated_item(def_id).ident ), - infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name), + infer::EarlyBoundRegion(_, def_id) => format!( + " for lifetime parameter `{}`", + self.tcx.generic_param_name(def_id), + ), infer::BoundRegionInCoherence(name) => { format!(" for lifetime parameter `{}` in coherence check", name) } diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 71d3f36a7f74c..1826572c3efc0 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -35,7 +35,6 @@ use std::fmt; use syntax::ast; use errors::DiagnosticBuilder; use syntax_pos::{self, Span}; -use syntax_pos::symbol::InternedString; use util::nodemap::FxHashMap; use arena::SyncDroplessArena; @@ -355,7 +354,7 @@ pub enum RegionVariableOrigin { Coercion(Span), // Region variables created as the values for early-bound regions - EarlyBoundRegion(Span, InternedString), + EarlyBoundRegion(Span, DefId), // Region variables created for bound regions // in a function or method that is called @@ -931,7 +930,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { GenericParamDefKind::Lifetime => { // Create a region inference variable for the given // region parameter definition. - self.next_region_var(EarlyBoundRegion(span, param.name)).into() + self.next_region_var(EarlyBoundRegion(span, param.def_id)).into() } GenericParamDefKind::Type {..} => { // Create a type inference variable for the given diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index 953ecf28f3b1a..9ef09476621a5 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -225,7 +225,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .params .iter() .filter_map(|param| match param.kind { - ty::GenericParamDefKind::Lifetime => Some(param.name.to_string()), + ty::GenericParamDefKind::Lifetime => { + Some(tcx.generic_param_name(param.def_id).to_string()) + } _ => None }) .collect(); diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 994563346be25..333364a4871c5 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -387,7 +387,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }, GenericParamDefKind::Lifetime => continue, }; - let name = param.name.to_string(); + let name = self.tcx.generic_param_name(param.def_id).to_string(); flags.push((name, Some(value))); } diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 280ce75720bcf..47f15b03cc10d 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -260,7 +260,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString { Position::ArgumentNamed(s) if s == "from_desugaring" => (), // So is `{A}` if A is a type parameter Position::ArgumentNamed(s) => match generics.params.iter().find(|param| { - param.name == s + tcx.generic_param_name(param.def_id) == s }) { Some(_) => (), None => { @@ -298,7 +298,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString { }, GenericParamDefKind::Lifetime => return None }; - let name = param.name.to_string(); + let name = tcx.generic_param_name(param.def_id).to_string(); Some((name, value)) }).collect::>(); let empty_string = String::new(); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index e85b4aeaba792..a2fb2ebe8f55d 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -844,7 +844,6 @@ pub enum GenericParamDefKind { #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct GenericParamDef { - pub name: InternedString, pub def_id: DefId, pub index: u32, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 719ef77b89e55..485e139b55a62 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -637,7 +637,7 @@ impl fmt::Debug for ty::GenericParamDef { }; write!(f, "{}({}, {:?}, {})", type_name, - self.name, + ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)), self.def_id, self.index) } diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 99919a940b405..fd84452368e2c 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -437,7 +437,9 @@ pub fn create_function_debug_context( let mut names = generics.parent.map_or(vec![], |def_id| { get_parameter_names(cx, cx.tcx.generics_of(def_id)) }); - names.extend(generics.params.iter().map(|param| param.name)); + names.extend(generics.params.iter().map(|param| { + cx.tcx.generic_param_name(param.def_id) + })); names } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index b8b3394dd86a1..f68147fa494cd 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -636,12 +636,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { // defaults. This will lead to an ICE if we are not // careful! if default_needs_object_self(param) { + let param_name = tcx.generic_param_name(param.def_id); struct_span_err!(tcx.sess, span, E0393, "the type parameter `{}` must be explicitly \ specified", - param.name) + param_name) .span_label(span, - format!("missing reference to `{}`", param.name)) + format!("missing reference to `{}`", param_name)) .note(&format!("because of the default `Self` reference, \ type parameters must be specified on object \ types")) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d6f609f729569..dc6cb73f121c9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1844,7 +1844,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { fn re_infer(&self, span: Span, def: Option<&ty::GenericParamDef>) -> Option> { let v = match def { - Some(def) => infer::EarlyBoundRegion(span, def.name), + Some(def) => infer::EarlyBoundRegion(span, def.def_id), None => infer::MiscVariable(span) }; Some(self.next_region_var(v)) @@ -5259,9 +5259,9 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }); for (&used, param) in types_used.iter().zip(types) { if !used { - let id = tcx.hir.as_local_node_id(param.def_id).unwrap(); - let span = tcx.hir.span(id); - struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name) + let span = tcx.def_span(param.def_id); + let param_name = tcx.generic_param_name(param.def_id); + struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param_name) .span_label(span, "unused type parameter") .emit(); } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 9b43221278745..df131477b0c30 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -838,7 +838,9 @@ fn reject_shadowing_parameters(tcx: TyCtxt, def_id: DefId) { let parent = tcx.generics_of(generics.parent.unwrap()); let impl_params: FxHashMap<_, _> = parent.params.iter().flat_map(|param| match param.kind { GenericParamDefKind::Lifetime => None, - GenericParamDefKind::Type {..} => Some((param.name, param.def_id)), + GenericParamDefKind::Type {..} => { + Some((tcx.generic_param_name(param.def_id), param.def_id)) + } }).collect(); for method_param in &generics.params { @@ -847,15 +849,16 @@ fn reject_shadowing_parameters(tcx: TyCtxt, def_id: DefId) { GenericParamDefKind::Lifetime => continue, _ => {}, }; - if impl_params.contains_key(&method_param.name) { + let method_param_name = tcx.generic_param_name(method_param.def_id); + if impl_params.contains_key(&method_param_name) { // Tighten up the span to focus on only the shadowing type let type_span = tcx.def_span(method_param.def_id); // The expectation here is that the original trait declaration is // local so it should be okay to just unwrap everything. - let trait_def_id = impl_params[&method_param.name]; + let trait_def_id = impl_params[&method_param_name]; let trait_decl_span = tcx.def_span(trait_def_id); - error_194(tcx, type_span, trait_decl_span, &method_param.name.as_str()[..]); + error_194(tcx, type_span, trait_decl_span, &method_param_name.as_str()[..]); } } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 7ad56d87f1756..e4cfe72d0c929 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -45,7 +45,7 @@ use syntax::ast::MetaItemKind; use syntax::attr::{InlineAttr, list_contains_name, mark_used}; use syntax::source_map::Spanned; use syntax::feature_gate; -use syntax::symbol::{keywords, Symbol}; +use syntax::symbol::Symbol; use syntax_pos::{Span, DUMMY_SP}; use rustc::hir::def::{CtorKind, Def}; @@ -909,7 +909,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty opt_self = Some(ty::GenericParamDef { index: 0, - name: keywords::SelfType.name().as_interned_str(), def_id: tcx.hir.local_def_id(param_id), pure_wrt_drop: false, kind: ty::GenericParamDefKind::Type { @@ -954,7 +953,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty early_lifetimes .enumerate() .map(|(i, param)| ty::GenericParamDef { - name: param.name.ident().as_interned_str(), index: own_start + i as u32, def_id: tcx.hir.local_def_id(param.id), pure_wrt_drop: param.pure_wrt_drop, @@ -994,7 +992,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty let ty_param = ty::GenericParamDef { index: type_start + i as u32, - name: param.name.ident().as_interned_str(), def_id: tcx.hir.local_def_id(param.id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Type { @@ -1030,9 +1027,8 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty dummy_args .iter() .enumerate() - .map(|(i, &arg)| ty::GenericParamDef { + .map(|(i, &_arg)| ty::GenericParamDef { index: type_start + i as u32, - name: Symbol::intern(arg).as_interned_str(), def_id, pure_wrt_drop: false, kind: ty::GenericParamDefKind::Type { @@ -1047,7 +1043,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty params.extend(fv.iter().zip((dummy_args.len() as u32)..).map(|(_, i)| { ty::GenericParamDef { index: type_start + i, - name: Symbol::intern("").as_interned_str(), def_id, pure_wrt_drop: false, kind: ty::GenericParamDefKind::Type { diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 363fd4decddd4..47cb49fcdfd0d 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -131,7 +131,7 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.sess, span, E0207, "the {} parameter `{}` is not constrained by the \ impl trait, self type, or predicates", - kind, param.name) + kind, tcx.generic_param_name(param.def_id)) .span_label(span, format!("unconstrained {} parameter", kind)) .emit(); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ed4fd48212b6e..e93daf5b3d88c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1243,8 +1243,8 @@ impl Clean for hir::GenericParam { } impl<'tcx> Clean for ty::GenericParamDef { - fn clean(&self, _cx: &DocContext) -> Lifetime { - Lifetime(self.name.to_string()) + fn clean(&self, cx: &DocContext) -> Lifetime { + Lifetime(cx.tcx.generic_param_name(self.def_id).to_string()) } } @@ -1409,19 +1409,20 @@ impl GenericParamDef { impl<'tcx> Clean for ty::GenericParamDef { fn clean(&self, cx: &DocContext) -> GenericParamDef { + let name = cx.tcx.generic_param_name(self.def_id); let (name, kind) = match self.kind { ty::GenericParamDefKind::Lifetime => { - (self.name.to_string(), GenericParamDefKind::Lifetime) + (name.to_string(), GenericParamDefKind::Lifetime) } ty::GenericParamDefKind::Type { has_default, .. } => { cx.renderinfo.borrow_mut().external_typarams - .insert(self.def_id, self.name.clean(cx)); + .insert(self.def_id, name.clean(cx)); let default = if has_default { Some(cx.tcx.type_of(self.def_id).clean(cx)) } else { None }; - (self.name.clean(cx), GenericParamDefKind::Type { + (name.clean(cx), GenericParamDefKind::Type { did: self.def_id, bounds: vec![], // These are filled in from the where-clauses. default, @@ -1561,8 +1562,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind { ty::GenericParamDefKind::Lifetime => None, ty::GenericParamDefKind::Type { .. } => { - if param.name == keywords::SelfType.name().as_str() { - assert_eq!(param.index, 0); + if gens.has_self && param.index == 0 { return None; } Some(param.clean(cx)) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index a312913a69c17..e1cc937b93504 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -201,10 +201,11 @@ impl<'a, 'tcx, 'rcx, 'cstore> DocContext<'a, 'tcx, 'rcx, 'cstore> { for param in generics.params.iter() { match param.kind { ty::GenericParamDefKind::Lifetime => { - let name = if param.name == "" { + let param_name = self.tcx.generic_param_name(param.def_id); + let name = if param_name == "" { hir::ParamName::Plain(keywords::StaticLifetime.ident()) } else { - hir::ParamName::Plain(ast::Ident::from_interned_str(param.name)) + hir::ParamName::Plain(ast::Ident::from_interned_str(param_name)) }; args.push(hir::GenericArg::Lifetime(hir::Lifetime { @@ -228,6 +229,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> DocContext<'a, 'tcx, 'rcx, 'cstore> { pub fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); + let param_name = self.tcx.generic_param_name(param.def_id); hir::Ty { id: ast::DUMMY_NODE_ID, node: hir::TyKind::Path(hir::QPath::Resolved( @@ -236,7 +238,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> DocContext<'a, 'tcx, 'rcx, 'cstore> { span: DUMMY_SP, def: Def::TyParam(param.def_id), segments: HirVec::from_vec(vec![ - hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) + hir::PathSegment::from_ident(Ident::from_interned_str(param_name)) ]), }), )), From 299a72295d338c971bb1eb4555e417a6c154f578 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 24 Aug 2018 07:10:58 +0300 Subject: [PATCH 10/10] rustc: combine ty::{ParamTy, EarlyBoundRegion} into GenericParam. --- src/librustc/ich/impls_ty.rs | 6 +++--- src/librustc/infer/outlives/obligations.rs | 4 ++-- src/librustc/infer/region_constraints/mod.rs | 2 +- src/librustc/middle/region.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/query/outlives_bounds.rs | 2 +- src/librustc/traits/select.rs | 2 +- src/librustc/ty/context.rs | 8 ++++---- src/librustc/ty/mod.rs | 12 ++++++------ src/librustc/ty/outlives.rs | 2 +- src/librustc/ty/relate.rs | 2 +- src/librustc/ty/structural_impls.rs | 2 +- src/librustc/ty/sty.rs | 16 +++++----------- src/librustc/ty/subst.rs | 6 +++--- src/librustc/ty/util.rs | 9 ++++----- src/librustc/util/ppaux.rs | 11 +++++------ src/librustc_driver/test.rs | 4 ++-- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/check/mod.rs | 6 +++--- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/check/writeback.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- src/librustc_typeck/constrained_type_params.rs | 8 ++------ src/librustc_typeck/outlives/utils.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- .../propagate-from-trait-match.stderr | 2 +- .../nll/ty-outlives/impl-trait-captures.stderr | 8 +++----- .../nll/ty-outlives/impl-trait-outlives.stderr | 4 ++-- .../projection-no-regions-closure.stderr | 4 ++-- .../ty-outlives/projection-no-regions-fn.stderr | 4 ++-- .../projection-one-region-closure.stderr | 4 ++-- ...jection-two-region-trait-bound-closure.stderr | 4 ++-- ...aram-closure-outlives-from-return-type.stderr | 4 ++-- 35 files changed, 71 insertions(+), 85 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index d7863d996909c..3150794551f10 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -114,7 +114,7 @@ for ty::RegionKind { ty::ReLateBound(db, ty::BrEnv) => { db.hash_stable(hcx, hasher); } - ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index }) => { + ty::ReEarlyBound(ty::GenericParam { def_id, index }) => { def_id.hash_stable(hcx, hasher); index.hash_stable(hcx, hasher); } @@ -935,8 +935,8 @@ for ty::FloatVid } } -impl_stable_hash_for!(struct ty::ParamTy { - idx, +impl_stable_hash_for!(struct ty::GenericParam { + index, def_id }); diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index 817280b97e031..176c9ecc89545 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -330,7 +330,7 @@ where &mut self, origin: infer::SubregionOrigin<'tcx>, region: ty::Region<'tcx>, - param_ty: ty::ParamTy, + param_ty: ty::GenericParam, ) { debug!( "param_ty_must_outlive(region={:?}, param_ty={:?}, origin={:?})", @@ -459,7 +459,7 @@ where } } - fn param_bound(&self, param_ty: ty::ParamTy) -> VerifyBound<'tcx> { + fn param_bound(&self, param_ty: ty::GenericParam) -> VerifyBound<'tcx> { debug!("param_bound(param_ty={:?})", param_ty); let mut param_bounds = self.declared_generic_bounds_from_env(GenericKind::Param(param_ty)); diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index cbafa47f774fd..e1c6a6428eeb7 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -151,7 +151,7 @@ pub struct Verify<'tcx> { #[derive(Copy, Clone, PartialEq, Eq)] pub enum GenericKind<'tcx> { - Param(ty::ParamTy), + Param(ty::GenericParam), Projection(ty::ProjectionTy<'tcx>), } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index eacf0ea20ceac..98f97595850f1 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -720,7 +720,7 @@ impl<'tcx> ScopeTree { /// Assuming that the provided region was defined within this `ScopeTree`, /// returns the outermost `Scope` that the region outlives. pub fn early_free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - br: &ty::EarlyBoundRegion) + br: &ty::GenericParam) -> Scope { let param_owner = tcx.parent_def_id(br.def_id).unwrap(); diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 333364a4871c5..0bd58d93faf89 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1348,7 +1348,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Param(ty::ParamTy {def_id, ..}) = ty.sty { + if let ty::Param(ty::GenericParam {def_id, ..}) = ty.sty { let infcx = self.infcx; self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var( diff --git a/src/librustc/traits/query/outlives_bounds.rs b/src/librustc/traits/query/outlives_bounds.rs index 47c8ee357fbe8..078f217e35707 100644 --- a/src/librustc/traits/query/outlives_bounds.rs +++ b/src/librustc/traits/query/outlives_bounds.rs @@ -31,7 +31,7 @@ use std::mem; #[derive(Clone, Debug)] pub enum OutlivesBound<'tcx> { RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>), - RegionSubParam(ty::Region<'tcx>, ty::ParamTy), + RegionSubParam(ty::Region<'tcx>, ty::GenericParam), RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>), } diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 69bdeec6eea23..2e2448477ab46 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -3073,7 +3073,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { let mut found = false; for ty in field.walk() { if let ty::Param(p) = ty.sty { - ty_params.insert(p.idx as usize); + ty_params.insert(p.index as usize); found = true; } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 3a08d259e9a59..c8c6829ddbc4a 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2557,15 +2557,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn mk_ty_param(self, def: &ty::GenericParamDef) -> Ty<'tcx> { - self.mk_ty(ty::Param(ty::ParamTy { - idx: def.index, + self.mk_ty(ty::Param(ty::GenericParam { + index: def.index, def_id: def.def_id, })) } pub fn mk_self_type(self, trait_def_id: DefId) -> Ty<'tcx> { - self.mk_ty(ty::Param(ty::ParamTy { - idx: 0, + self.mk_ty(ty::Param(ty::GenericParam { + index: 0, def_id: trait_def_id, })) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index a2fb2ebe8f55d..3a737027a58e3 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -63,12 +63,12 @@ use hir; pub use self::sty::{Binder, CanonicalVar, DebruijnIndex, INNERMOST}; pub use self::sty::{FnSig, GenSig, PolyFnSig, PolyGenSig}; -pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate}; +pub use self::sty::{InferTy, GenericParam, ProjectionTy, ExistentialPredicate}; pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut}; pub use self::sty::{TraitRef, TyKind, PolyTraitRef}; pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef}; pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const}; -pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region}; +pub use self::sty::{BoundRegion, FreeRegion, Region}; pub use self::sty::RegionKind; pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid}; pub use self::sty::BoundRegion::*; @@ -819,7 +819,7 @@ pub enum IntVarValue { #[derive(Clone, Copy, PartialEq, Eq)] pub struct FloatVarValue(pub ast::FloatTy); -impl ty::EarlyBoundRegion { +impl ty::GenericParam { pub fn to_bound_region(&self) -> ty::BoundRegion { ty::BoundRegion::BrNamed(self.def_id) } @@ -856,10 +856,10 @@ pub struct GenericParamDef { } impl GenericParamDef { - pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion { + pub fn to_early_bound_region_data(&self) -> ty::GenericParam { match self.kind { GenericParamDefKind::Lifetime => { - ty::EarlyBoundRegion { + ty::GenericParam { def_id: self.def_id, index: self.index, } @@ -2657,7 +2657,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() { // Ignore bounds other than those on this parameter. match trait_ref.self_ty().sty { - ty::TyParam(p) if p.def_id == id => {} + ty::Param(p) if p.def_id == id => {} _ => continue, } diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs index 5171bfb7e0608..db5ba08d0ae0f 100644 --- a/src/librustc/ty/outlives.rs +++ b/src/librustc/ty/outlives.rs @@ -17,7 +17,7 @@ use ty::{self, Ty, TyCtxt, TypeFoldable}; #[derive(Debug)] pub enum Component<'tcx> { Region(ty::Region<'tcx>), - Param(ty::ParamTy), + Param(ty::GenericParam), UnresolvedInferenceVariable(ty::InferTy), // Projections like `T::Foo` are tricky because a constraint like diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index d72e48c04fed4..432fcd08c987a 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -388,7 +388,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, } (&ty::Param(ref a_p), &ty::Param(ref b_p)) - if a_p.idx == b_p.idx => + if a_p.index == b_p.index => { Ok(a) } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index e6c10358279b3..8122ee38d2064 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -56,7 +56,7 @@ CloneTypeFoldableAndLiftImpls! { ::ty::BoundRegion, ::ty::ClosureKind, ::ty::IntVarValue, - ::ty::ParamTy, + ::ty::GenericParam, ::syntax_pos::Span, } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index f9933f9bd5859..8879dcbaedea8 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -165,7 +165,7 @@ pub enum TyKind<'tcx> { Anon(DefId, &'tcx Substs<'tcx>), /// A type parameter; for example, `T` in `fn f(x: T) {} - Param(ParamTy), + Param(GenericParam), /// A type variable used during type-checking. Infer(InferTy), @@ -959,12 +959,6 @@ impl<'tcx> PolyFnSig<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] -pub struct ParamTy { - pub idx: u32, - pub def_id: DefId, -} - /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In /// particular, imagine a type like this: @@ -1074,7 +1068,7 @@ pub enum RegionKind { // Region bound in a type or fn declaration which will be // substituted 'early' -- that is, at the same time when type // parameters are substituted. - ReEarlyBound(EarlyBoundRegion), + ReEarlyBound(GenericParam), // Region bound in a function scope, which will be substituted when the // function is called. @@ -1124,8 +1118,8 @@ pub enum RegionKind { impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {} -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, PartialOrd, Ord)] -pub struct EarlyBoundRegion { +#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)] +pub struct GenericParam { pub def_id: DefId, pub index: u32, } @@ -1483,7 +1477,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { pub fn is_param(&self, index: u32) -> bool { match self.sty { - ty::Param(ref data) => data.idx == index, + ty::Param(ref data) => data.index == index, _ => false, } } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 8bcaea8cac8ea..53a76bb42f8ad 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -495,9 +495,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> { } impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> { - fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> { + fn ty_for_param(&self, p: ty::GenericParam, source_ty: Ty<'tcx>) -> Ty<'tcx> { // Look up the type in the substitutions. It really should be in there. - let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack()); + let opt_ty = self.substs.get(p.index as usize).map(|k| k.unpack()); let ty = match opt_ty { Some(UnpackedKind::Type(ty)) => ty, _ => { @@ -508,7 +508,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> { when substituting (root type={:?}) substs={:?}", p, source_ty, - p.idx, + p.index, self.root_ty, self.substs); } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 09b2ee6a983cb..3117b5f7b6074 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -498,19 +498,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let result = item_substs.iter().zip(impl_substs.iter()) .filter(|&(_, &k)| { - let index = match k.unpack() { - UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => - ebr.index, + let param = match k.unpack() { + UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => ebr, UnpackedKind::Type(&ty::TyS { sty: ty::Param(ref pt), .. - }) => pt.idx, + }) => pt, UnpackedKind::Lifetime(_) | UnpackedKind::Type(_) => { // not a type or region param - this should be reported // as an error. return false; } }; - !impl_generics.param_at(index, self).pure_wrt_drop + !impl_generics.param_at(param.index, self).pure_wrt_drop }).map(|(&item_param, _)| item_param).collect(); debug!("destructor_constraint({:?}) = {:?}", def.did, result); result diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 485e139b55a62..c8e0a7ac7f3c8 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -805,7 +805,7 @@ define_print! { // `explain_region()` or `note_and_explain_region()`. match *self { ty::ReEarlyBound(ref data) => { - write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(data.def_id))) + print!(f, cx, print_display(data)) } ty::ReCanonical(_) => { write!(f, "'_") @@ -846,9 +846,7 @@ define_print! { debug { match *self { ty::ReEarlyBound(ref data) => { - write!(f, "ReEarlyBound({}, {})", - data.index, - ty::tls::with(|tcx| tcx.generic_param_name(data.def_id))) + print!(f, cx, print_debug(data)) } ty::ReClosureBound(ref vid) => { @@ -1311,12 +1309,13 @@ define_print! { } define_print! { - () ty::ParamTy, (self, f, cx) { + () ty::GenericParam, (self, f, cx) { display { write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(self.def_id))) } debug { - write!(f, "{}/#{}", ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)), self.idx) + write!(f, "{}/#{}", + ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)), self.index) } } } diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 8e4b37848aea1..39247babaa728 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -313,7 +313,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { pub fn t_param(&self, index: u32) -> Ty<'tcx> { let def_id = self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID); - self.infcx.tcx.mk_ty(ty::TyParam(ty::ParamTy { + self.infcx.tcx.mk_ty(ty::TyParam(ty::GenericParam { idx: index, def_id, })) @@ -321,7 +321,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> { let name = Symbol::intern(name).as_interned_str(); - self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { + self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::GenericParam { def_id: self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID), index, name, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f68147fa494cd..2c093d565ccac 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -133,7 +133,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { } Some(rl::Region::EarlyBound(index, id, _)) => { - tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { + tcx.mk_region(ty::ReEarlyBound(ty::GenericParam { def_id: id, index, })) diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 52e5e57f74759..31d1327a6d183 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -81,7 +81,7 @@ enum PointerKind<'tcx> { /// The unsize info of this anon ty OfAnon(DefId, &'tcx Substs<'tcx>), /// The unsize info of this parameter - OfParam(&'tcx ty::ParamTy), + OfParam(&'tcx ty::GenericParam), } impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 85a437283fa68..1d0487c09156e 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -642,7 +642,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { fn assemble_inherent_candidates_from_param(&mut self, _rcvr_ty: Ty<'tcx>, - param_ty: ty::ParamTy) { + param_ty: ty::GenericParam) { // FIXME -- Do we want to commit to this behavior for param bounds? let bounds: Vec<_> = self.param_env diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index dc6cb73f121c9..459f940a5d577 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5242,9 +5242,9 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut types_used = vec![false; own_counts.types]; for leaf_ty in ty.walk() { - if let ty::Param(ty::ParamTy { idx, .. }) = leaf_ty.sty { - debug!("Found use of ty param num {}", idx); - types_used[idx as usize - own_counts.lifetimes] = true; + if let ty::Param(ref p) = leaf_ty.sty { + debug!("Found use of ty param num {}", p.index); + types_used[p.index as usize - own_counts.lifetimes] = true; } else if let ty::Error = leaf_ty.sty { // If there is already another error, do not emit // an error for not using a type Parameter. diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index df131477b0c30..d25dc53d3379b 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -455,7 +455,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( fn visit_ty(&mut self, t: Ty<'tcx>) -> bool { match t.sty { ty::Param(p) => { - self.params.insert(p.idx); + self.params.insert(p.index); t.super_visit_with(self) } _ => t.super_visit_with(self) diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 1794513c8f852..c703deacdc346 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -463,7 +463,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { if subst == region { // found it in the substitution list, replace with the // parameter from the existential type - let reg = ty::EarlyBoundRegion { + let reg = ty::GenericParam { def_id: p.def_id, index: p.index, }; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e4cfe72d0c929..63d76a36439be 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1740,7 +1740,7 @@ fn explicit_predicates_of<'a, 'tcx>( // have to be careful to only iterate over early-bound regions. let mut index = parent_count + has_own_self as u32; for param in early_bound_lifetimes_from_generics(tcx, ast_generics) { - let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { + let region = tcx.mk_region(ty::ReEarlyBound(ty::GenericParam { def_id: tcx.hir.local_def_id(param.id), index, })); diff --git a/src/librustc_typeck/constrained_type_params.rs b/src/librustc_typeck/constrained_type_params.rs index 37b0b83ccd088..4214d272081a7 100644 --- a/src/librustc_typeck/constrained_type_params.rs +++ b/src/librustc_typeck/constrained_type_params.rs @@ -15,12 +15,8 @@ use rustc::util::nodemap::FxHashSet; #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub struct Parameter(pub u32); -impl From for Parameter { - fn from(param: ty::ParamTy) -> Self { Parameter(param.idx) } -} - -impl From for Parameter { - fn from(param: ty::EarlyBoundRegion) -> Self { Parameter(param.index) } +impl From for Parameter { + fn from(param: ty::GenericParam) -> Self { Parameter(param.index) } } /// Return the set of parameters constrained by the impl header. diff --git a/src/librustc_typeck/outlives/utils.rs b/src/librustc_typeck/outlives/utils.rs index 9f7dd6b729638..9445d71985c51 100644 --- a/src/librustc_typeck/outlives/utils.rs +++ b/src/librustc_typeck/outlives/utils.rs @@ -64,7 +64,7 @@ pub fn insert_outlives_predicate<'tcx>( } Component::Param(param_ty) => { - // param_ty: ty::ParamTy + // param_ty: ty::GenericParam // This would arise from something like: // // ``` diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index a79215497182e..0198ddb8c6b37 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -324,7 +324,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } ty::Param(ref data) => { - self.add_constraint(current, data.idx, variance); + self.add_constraint(current, data.index, variance); } ty::FnPtr(sig) => { diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr index 15fca6f6882eb..044c32674970b 100644 --- a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr @@ -47,7 +47,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/propagate-from-trait-match.rs:42:36 | LL | fn supply<'a, T>(value: T) - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | establish_relationships(value, |value| { | ____________________________________^ diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr index a4f0e53386f9f..b40f063ae420c 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -7,12 +7,10 @@ LL | x error[E0621]: explicit lifetime required in the type of `x` --> $DIR/impl-trait-captures.rs:21:5 | +LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { + | -- help: add explicit lifetime `'a/#0` to the type of `x`: `&'a/#0 T` LL | x - | ^ lifetime `ReEarlyBound(0, 'a)` required -help: add explicit lifetime `ReEarlyBound(0, 'a)` to the type of `x` - | -LL | fn foo<'a, T>(x: &ReEarlyBound(0, 'a) T) -> impl Foo<'a> { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^ lifetime `'a/#0` required error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr index 5c5837f709913..46a72c52334ee 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr @@ -14,7 +14,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/impl-trait-outlives.rs:22:5 | LL | fn no_region<'a, T>(x: Box) -> impl Debug + 'a - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | x | ^ @@ -23,7 +23,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/impl-trait-outlives.rs:38:5 | LL | fn wrong_region<'a, 'b, T>(x: Box) -> impl Debug + 'a - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | x | ^ diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr index 6d2170729ffb9..a20c3e042d6b0 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr @@ -48,7 +48,7 @@ error[E0309]: the associated type `::Item` may not liv LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a/#0`... note: External requirements --> $DIR/projection-no-regions-closure.rs:45:23 @@ -121,7 +121,7 @@ error[E0309]: the associated type `::Item` may not liv LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a/#0`... note: External requirements --> $DIR/projection-no-regions-closure.rs:64:23 diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr index 3199ec151335d..2acd2ff9ba573 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr @@ -16,7 +16,7 @@ error[E0309]: the associated type `::Item` may not liv LL | Box::new(x.next()) | ^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a/#0`... error[E0309]: the associated type `::Item` may not live long enough --> $DIR/projection-no-regions-fn.rs:39:5 @@ -24,7 +24,7 @@ error[E0309]: the associated type `::Item` may not liv LL | Box::new(x.next()) | ^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a/#0`... error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index f75da792dd380..82140491258b2 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -120,7 +120,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-one-region-closure.rs:67:29 | LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T) - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -175,7 +175,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/projection-one-region-closure.rs:89:29 | LL | fn projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T) - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr index 6838e0f3b3d01..bc4e5ecbe0a68 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr @@ -106,7 +106,7 @@ error[E0309]: the associated type `>::AssocType` may LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `>::AssocType: 'a/#0`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:80:29 @@ -150,7 +150,7 @@ error[E0309]: the associated type `>::AssocType` may LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `>::AssocType: 'a/#0`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:91:29 diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr index c03c75e3ee573..cd8a759b002b0 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr @@ -46,7 +46,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-return-type.rs:36:23 | LL | fn no_region<'a, T>(x: Box) -> Box - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | with_signature(x, |y| y) | ^^^^^ @@ -55,7 +55,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/ty-param-closure-outlives-from-return-type.rs:52:5 | LL | fn wrong_region<'a, 'b, T>(x: Box) -> Box - | - help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`... + | - help: consider adding an explicit lifetime bound `T: 'a/#0`... ... LL | x | ^