From a4262dd780bf6a9b02ddba661379fc25aefdfd32 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 10 Jan 2020 15:20:14 -0800 Subject: [PATCH 1/5] Add `constness` field to `hir::TraitRef` --- src/librustc_ast_lowering/lib.rs | 13 ++++++------- src/librustc_hir/hir.rs | 6 ++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 58b8e8a089ad3..0a4e77251d7b5 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -1977,13 +1977,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // ::std::future::Future let future_path = self.std_path(span, &[sym::future, sym::Future], Some(future_params), false); + let future_trait_ref = + hir::TraitRef { path: future_path, hir_ref_id: self.next_id(), constness: None }; hir::GenericBound::Trait( - hir::PolyTraitRef { - trait_ref: hir::TraitRef { path: future_path, hir_ref_id: self.next_id() }, - bound_generic_params: &[], - span, - }, + hir::PolyTraitRef { trait_ref: future_trait_ref, bound_generic_params: &[], span }, hir::TraitBoundModifier::None, ) } @@ -2149,7 +2147,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::QPath::Resolved(None, path) => path, qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath), }; - hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) } + + hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id), constness: p.constness } } fn lower_poly_trait_ref( @@ -2463,8 +2462,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { Res::Def(DefKind::Trait, _) | Res::Def(DefKind::TraitAlias, _) => { let principal = hir::PolyTraitRef { bound_generic_params: &[], - trait_ref: hir::TraitRef { path, hir_ref_id: hir_id }, span, + trait_ref: hir::TraitRef { path, hir_ref_id: hir_id, constness: None }, }; // The original ID is taken by the `PolyTraitRef`, diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 550e3654d0800..7c886b324a596 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -2233,6 +2233,8 @@ pub struct TraitRef<'hir> { // Don't hash the `ref_id`. It is tracked via the thing it is used to access. #[stable_hasher(ignore)] pub hir_ref_id: HirId, + + pub constness: Option, } impl TraitRef<'_> { @@ -2247,6 +2249,10 @@ impl TraitRef<'_> { _ => unreachable!(), } } + + pub fn is_maybe_const(&self) -> bool { + self.constness == Some(Constness::NotConst) + } } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] From 064f439994574cf05cb657f9a6edff651adfaa19 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 10 Jan 2020 15:21:31 -0800 Subject: [PATCH 2/5] Add `maybe_const` field to `ty::TraitRef` --- .../nice_region_error/placeholder_error.rs | 12 +++---- src/librustc/traits/auto_trait.rs | 7 ++-- src/librustc/traits/engine.rs | 2 +- src/librustc/traits/error_reporting.rs | 3 +- src/librustc/traits/fulfill.rs | 2 +- src/librustc/traits/mod.rs | 6 ++-- src/librustc/traits/object_safety.rs | 18 +++++------ src/librustc/traits/util.rs | 12 +++---- src/librustc/traits/wf.rs | 8 ++--- src/librustc/ty/mod.rs | 8 ++--- src/librustc/ty/print/pretty.rs | 8 ++++- src/librustc/ty/relate.rs | 2 +- src/librustc/ty/structural_impls.rs | 2 +- src/librustc/ty/sty.rs | 28 ++++++++++++---- .../borrow_check/type_check/mod.rs | 32 +++++++++---------- src/librustc_mir/monomorphize/mod.rs | 8 ++--- src/librustc_privacy/lib.rs | 2 +- .../chalk_context/program_clauses/builtin.rs | 15 ++++----- .../program_clauses/primitive.rs | 9 +++--- src/librustc_traits/lowering/mod.rs | 4 +-- src/librustc_typeck/astconv.rs | 18 ++++++++--- src/librustc_typeck/check/autoderef.rs | 6 ++-- src/librustc_typeck/check/wfcheck.rs | 6 ++-- src/librustdoc/clean/auto_trait.rs | 6 ++-- 24 files changed, 115 insertions(+), 109 deletions(-) diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 7b31fe7cd7e4d..5d7767d83f830 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -215,14 +215,10 @@ impl NiceRegionError<'me, 'tcx> { false }; - let expected_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { - def_id: trait_def_id, - substs: expected_substs, - }); - let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { - def_id: trait_def_id, - substs: actual_substs, - }); + let expected_trait_ref = + self.infcx.resolve_vars_if_possible(&ty::TraitRef::new(trait_def_id, expected_substs)); + let actual_trait_ref = + self.infcx.resolve_vars_if_possible(&ty::TraitRef::new(trait_def_id, actual_substs)); // Search the expected and actual trait references to see (a) // whether the sub/sup placeholders appear in them (sometimes diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index 89b28aeda1c5e..84579cd487b76 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -83,7 +83,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { ) -> AutoTraitResult { let tcx = self.tcx; - let trait_ref = ty::TraitRef { def_id: trait_did, substs: tcx.mk_substs_trait(ty, &[]) }; + let trait_ref = ty::TraitRef::new(trait_did, tcx.mk_substs_trait(ty, &[])); let trait_pred = ty::Binder::bind(trait_ref); @@ -271,10 +271,7 @@ impl AutoTraitFinder<'tcx> { let mut already_visited = FxHashSet::default(); let mut predicates = VecDeque::new(); predicates.push_back(ty::Binder::bind(ty::TraitPredicate { - trait_ref: ty::TraitRef { - def_id: trait_did, - substs: infcx.tcx.mk_substs_trait(ty, &[]), - }, + trait_ref: ty::TraitRef::new(trait_did, infcx.tcx.mk_substs_trait(ty, &[])), })); let mut computed_preds: FxHashSet<_> = param_env.caller_bounds.iter().cloned().collect(); diff --git a/src/librustc/traits/engine.rs b/src/librustc/traits/engine.rs index 5b804480119fe..a68060c2166cc 100644 --- a/src/librustc/traits/engine.rs +++ b/src/librustc/traits/engine.rs @@ -26,7 +26,7 @@ pub trait TraitEngine<'tcx>: 'tcx { def_id: DefId, cause: ObligationCause<'tcx>, ) { - let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }; + let trait_ref = ty::TraitRef::new(def_id, infcx.tcx.mk_substs_trait(ty, &[])); self.register_predicate_obligation( infcx, Obligation { diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 0c9a73d78a5eb..da1125adb499c 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1340,8 +1340,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> PredicateObligation<'tcx> { - let new_trait_ref = - ty::TraitRef { def_id, substs: self.tcx.mk_substs_trait(output_ty, &[]) }; + let new_trait_ref = ty::TraitRef::new(def_id, self.tcx.mk_substs_trait(output_ty, &[])); Obligation::new(cause, param_env, new_trait_ref.to_predicate()) } diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 46ece6fc40593..0265a70a196f5 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -72,7 +72,7 @@ pub struct PendingPredicateObligation<'tcx> { // `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(PendingPredicateObligation<'_>, 136); +static_assert_size!(PendingPredicateObligation<'_>, 144); impl<'a, 'tcx> FulfillmentContext<'tcx> { /// Creates a new fulfillment context. diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 2d3160dc3e51a..3e4e0addb8f49 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -137,7 +137,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>; // `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(PredicateObligation<'_>, 112); +static_assert_size!(PredicateObligation<'_>, 120); /// The reason why we incurred this obligation; used for error reporting. #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -320,7 +320,7 @@ pub struct AssocTypeBoundData { // `ObligationCauseCode` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(ObligationCauseCode<'_>, 32); +static_assert_size!(ObligationCauseCode<'_>, 40); #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct MatchExpressionArmCause<'tcx> { @@ -727,7 +727,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>( infcx.tcx.def_path_str(def_id) ); - let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }; + let trait_ref = ty::TraitRef::new(def_id, infcx.tcx.mk_substs_trait(ty, &[])); let obligation = Obligation { param_env, cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID), diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index bfbcb042e7a73..c630316cd5be8 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -579,10 +579,10 @@ fn receiver_is_dispatchable<'tcx>( let mut param_env = tcx.param_env(method.def_id); // Self: Unsize - let unsize_predicate = ty::TraitRef { - def_id: unsize_did, - substs: tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]), - } + let unsize_predicate = ty::TraitRef::new( + unsize_did, + tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]), + ) .to_predicate(); // U: Trait @@ -596,7 +596,7 @@ fn receiver_is_dispatchable<'tcx>( } }); - ty::TraitRef { def_id: unsize_did, substs }.to_predicate() + ty::TraitRef::new(unsize_did, substs).to_predicate() }; let caller_bounds: Vec> = param_env @@ -614,10 +614,10 @@ fn receiver_is_dispatchable<'tcx>( // Receiver: DispatchFromDyn U]> let obligation = { - let predicate = ty::TraitRef { - def_id: dispatch_from_dyn_did, - substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]), - } + let predicate = ty::TraitRef::new( + dispatch_from_dyn_did, + tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]), + ) .to_predicate(); Obligation::new(ObligationCause::dummy(), param_env, predicate) diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 65fd809657bd0..a6f404854c3c3 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -557,8 +557,7 @@ pub fn predicate_for_trait_def( self_ty: Ty<'tcx>, params: &[GenericArg<'tcx>], ) -> PredicateObligation<'tcx> { - let trait_ref = - ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(self_ty, params) }; + let trait_ref = ty::TraitRef::new(trait_def_id, tcx.mk_substs_trait(self_ty, params)); predicate_for_trait_ref(cause, param_env, trait_ref, recursion_depth) } @@ -629,10 +628,8 @@ pub fn closure_trait_ref_and_return_type( TupleArgumentsFlag::No => sig.skip_binder().inputs()[0], TupleArgumentsFlag::Yes => tcx.intern_tup(sig.skip_binder().inputs()), }; - let trait_ref = ty::TraitRef { - def_id: fn_trait_def_id, - substs: tcx.mk_substs_trait(self_ty, &[arguments_tuple.into()]), - }; + let trait_ref = + ty::TraitRef::new(fn_trait_def_id, tcx.mk_substs_trait(self_ty, &[arguments_tuple.into()])); ty::Binder::bind((trait_ref, sig.skip_binder().output())) } @@ -642,8 +639,7 @@ pub fn generator_trait_ref_and_outputs( self_ty: Ty<'tcx>, sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<(ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> { - let trait_ref = - ty::TraitRef { def_id: fn_trait_def_id, substs: tcx.mk_substs_trait(self_ty, &[]) }; + let trait_ref = ty::TraitRef::new(fn_trait_def_id, tcx.mk_substs_trait(self_ty, &[])); ty::Binder::bind((trait_ref, sig.skip_binder().yield_ty, sig.skip_binder().return_ty)) } diff --git a/src/librustc/traits/wf.rs b/src/librustc/traits/wf.rs index 2301395f557f1..b750d68284c28 100644 --- a/src/librustc/traits/wf.rs +++ b/src/librustc/traits/wf.rs @@ -374,10 +374,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) { if !subty.has_escaping_bound_vars() { let cause = self.cause(cause); - let trait_ref = ty::TraitRef { - def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None), - substs: self.infcx.tcx.mk_substs_trait(subty, &[]), - }; + let trait_ref = ty::TraitRef::new( + self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None), + self.infcx.tcx.mk_substs_trait(subty, &[]), + ); self.out.push(traits::Obligation::new(cause, self.param_env, trait_ref.to_predicate())); } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d1e37a4ea1151..16e46986dd839 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2467,11 +2467,9 @@ impl<'tcx> AdtDef { Some(x) => x, _ => return vec![ty], }; - let sized_predicate = Binder::dummy(TraitRef { - def_id: sized_trait, - substs: tcx.mk_substs_trait(ty, &[]), - }) - .to_predicate(); + let sized_predicate = + Binder::dummy(TraitRef::new(sized_trait, tcx.mk_substs_trait(ty, &[]))) + .to_predicate(); let predicates = tcx.predicates_of(self.did).predicates; if predicates.iter().any(|(p, _)| *p == sized_predicate) { vec![] diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 8b1b2bb586597..ce74e82c11326 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -1749,7 +1749,13 @@ define_print_and_forward_display! { } ty::TraitRef<'tcx> { - p!(write("<{} as {}>", self.self_ty(), self.print_only_trait_path())) + p!( + write("<{} as {}{}>", + self.self_ty(), + if self.maybe_const { "?const " } else { "" }, + self.print_only_trait_path() + ) + ) } TraitRefPrintOnlyTraitPath<'tcx> { diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 3b9df72266f09..ab25c117f6271 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -287,7 +287,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> { Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id))) } else { let substs = relate_substs(relation, None, a.substs, b.substs)?; - Ok(ty::TraitRef { def_id: a.def_id, substs: substs }) + Ok(ty::TraitRef::new(a.def_id, substs)) } } } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 62e895af7f355..3506d95ed086f 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -392,7 +392,7 @@ impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec { impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> { type Lifted = ty::TraitRef<'tcx>; fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option { - tcx.lift(&self.substs).map(|substs| ty::TraitRef { def_id: self.def_id, substs }) + tcx.lift(&self.substs).map(|substs| ty::TraitRef::new(self.def_id, substs)) } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 842361284823d..e04e087a29b12 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -670,8 +670,7 @@ impl<'tcx> Binder> { ty::Predicate::Projection(Binder(p.with_self_ty(tcx, self_ty))) } ExistentialPredicate::AutoTrait(did) => { - let trait_ref = - Binder(ty::TraitRef { def_id: did, substs: tcx.mk_substs_trait(self_ty, &[]) }); + let trait_ref = Binder(ty::TraitRef::new(did, tcx.mk_substs_trait(self_ty, &[]))); trait_ref.to_predicate() } } @@ -784,17 +783,32 @@ impl<'tcx> Binder<&'tcx List>> { pub struct TraitRef<'tcx> { pub def_id: DefId, pub substs: SubstsRef<'tcx>, + + /// Whether the reference to the trait is prefixed by `?const`. + // + // FIXME(ecstaticmorse): This field causes `TraitRef` to increase in size by an entire machine + // word, despite it never being used during trait solving. Try implementing the checks in + // `qualify_min_const_fn` using `hir::TraitRef` instead. + pub maybe_const: bool, } impl<'tcx> TraitRef<'tcx> { pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> { - TraitRef { def_id, substs } + TraitRef::new_maybe_const(def_id, substs, false) + } + + pub fn new_maybe_const( + def_id: DefId, + substs: SubstsRef<'tcx>, + maybe_const: bool, + ) -> TraitRef<'tcx> { + TraitRef { def_id, substs, maybe_const } } /// Returns a `TraitRef` of the form `P0: Foo` where `Pi` /// are the parameters defined on trait. pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> TraitRef<'tcx> { - TraitRef { def_id, substs: InternalSubsts::identity_for_item(tcx, def_id) } + TraitRef::new(def_id, InternalSubsts::identity_for_item(tcx, def_id)) } #[inline] @@ -817,7 +831,7 @@ impl<'tcx> TraitRef<'tcx> { ) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); - ty::TraitRef { def_id: trait_id, substs: tcx.intern_substs(&substs[..defs.params.len()]) } + ty::TraitRef::new(trait_id, tcx.intern_substs(&substs[..defs.params.len()])) } } @@ -882,7 +896,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> { // otherwise the escaping vars would be captured by the binder // debug_assert!(!self_ty.has_escaping_bound_vars()); - ty::TraitRef { def_id: self.def_id, substs: tcx.mk_substs_trait(self_ty, self.substs) } + ty::TraitRef::new(self.def_id, tcx.mk_substs_trait(self_ty, self.substs)) } } @@ -1058,7 +1072,7 @@ impl<'tcx> ProjectionTy<'tcx> { /// then this function would return a `T: Iterator` trait reference. pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { let def_id = tcx.associated_item(self.item_def_id).container.id(); - ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) } + ty::TraitRef::new(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id))) } pub fn self_ty(&self) -> Ty<'tcx> { diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 947bbef4379f5..7664ddad1f3fb 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -470,10 +470,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { if place.projection.is_empty() { if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context { let tcx = self.tcx(); - let trait_ref = ty::TraitRef { - def_id: tcx.lang_items().copy_trait().unwrap(), - substs: tcx.mk_substs_trait(place_ty.ty, &[]), - }; + let trait_ref = ty::TraitRef::new( + tcx.lang_items().copy_trait().unwrap(), + tcx.mk_substs_trait(place_ty.ty, &[]), + ); // To have a `Copy` operand, the type `T` of the // value must be `Copy`. Note that we prove that `T: Copy`, @@ -1391,10 +1391,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_rvalue(body, rv, location); if !self.tcx().features().unsized_locals { - let trait_ref = ty::TraitRef { - def_id: tcx.lang_items().sized_trait().unwrap(), - substs: tcx.mk_substs_trait(place_ty, &[]), - }; + let trait_ref = ty::TraitRef::new( + tcx.lang_items().sized_trait().unwrap(), + tcx.mk_substs_trait(place_ty, &[]), + ); self.prove_trait_ref( trait_ref, location.to_locations(), @@ -1954,10 +1954,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.ensure_place_sized(ty, span); } - let trait_ref = ty::TraitRef { - def_id: tcx.lang_items().sized_trait().unwrap(), - substs: tcx.mk_substs_trait(ty, &[]), - }; + let trait_ref = ty::TraitRef::new( + tcx.lang_items().sized_trait().unwrap(), + tcx.mk_substs_trait(ty, &[]), + ); self.prove_trait_ref( trait_ref, @@ -2054,10 +2054,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { CastKind::Pointer(PointerCast::Unsize) => { let &ty = ty; - let trait_ref = ty::TraitRef { - def_id: tcx.lang_items().coerce_unsized_trait().unwrap(), - substs: tcx.mk_substs_trait(op.ty(*body, tcx), &[ty.into()]), - }; + let trait_ref = ty::TraitRef::new( + tcx.lang_items().coerce_unsized_trait().unwrap(), + tcx.mk_substs_trait(op.ty(*body, tcx), &[ty.into()]), + ); self.prove_trait_ref( trait_ref, diff --git a/src/librustc_mir/monomorphize/mod.rs b/src/librustc_mir/monomorphize/mod.rs index 8bc63bfcfcbe3..d72e1a273a54e 100644 --- a/src/librustc_mir/monomorphize/mod.rs +++ b/src/librustc_mir/monomorphize/mod.rs @@ -12,10 +12,10 @@ pub fn custom_coerce_unsize_info<'tcx>( ) -> CustomCoerceUnsized { let def_id = tcx.lang_items().coerce_unsized_trait().unwrap(); - let trait_ref = ty::Binder::bind(ty::TraitRef { - def_id: def_id, - substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]), - }); + let trait_ref = ty::Binder::bind(ty::TraitRef::new( + def_id, + tcx.mk_substs_trait(source_ty, &[target_ty.into()]), + )); match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) { traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 70d4841ec244b..b2c522e050919 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -84,7 +84,7 @@ where V: DefIdVisitor<'tcx> + ?Sized, { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> bool { - let TraitRef { def_id, substs } = trait_ref; + let TraitRef { def_id, substs, maybe_const: _ } = trait_ref; self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref.print_only_trait_path()) || (!self.def_id_visitor.shallow() && substs.visit_with(self)) } diff --git a/src/librustc_traits/chalk_context/program_clauses/builtin.rs b/src/librustc_traits/chalk_context/program_clauses/builtin.rs index 7512cbbd88218..f63851c73e1db 100644 --- a/src/librustc_traits/chalk_context/program_clauses/builtin.rs +++ b/src/librustc_traits/chalk_context/program_clauses/builtin.rs @@ -17,16 +17,15 @@ fn builtin_impl_clause( ) -> ProgramClause<'tcx> { ProgramClause { goal: ty::TraitPredicate { - trait_ref: ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, &[]) }, + trait_ref: ty::TraitRef::new(trait_def_id, tcx.mk_substs_trait(ty, &[])), } .lower(), hypotheses: tcx.mk_goals( nested .iter() .cloned() - .map(|nested_ty| ty::TraitRef { - def_id: trait_def_id, - substs: tcx.mk_substs_trait(nested_ty.expect_ty(), &[]), + .map(|nested_ty| { + ty::TraitRef::new(trait_def_id, tcx.mk_substs_trait(nested_ty.expect_ty(), &[])) }) .map(|trait_ref| ty::TraitPredicate { trait_ref }) .map(|pred| GoalKind::DomainGoal(pred.lower())) @@ -76,10 +75,10 @@ crate fn assemble_builtin_unsize_impls<'tcx>( // `forall { Implemented([T; N]: Unsize<[T]>). }` let clause = ProgramClause { goal: ty::TraitPredicate { - trait_ref: ty::TraitRef { - def_id: unsize_def_id, - substs: tcx.mk_substs_trait(array_ty, &[slice_ty.into()]), - }, + trait_ref: ty::TraitRef::new( + unsize_def_id, + tcx.mk_substs_trait(array_ty, &[slice_ty.into()]), + ), } .lower(), hypotheses: ty::List::empty(), diff --git a/src/librustc_traits/chalk_context/program_clauses/primitive.rs b/src/librustc_traits/chalk_context/program_clauses/primitive.rs index ae4afe58436d6..1b29e15c94539 100644 --- a/src/librustc_traits/chalk_context/program_clauses/primitive.rs +++ b/src/librustc_traits/chalk_context/program_clauses/primitive.rs @@ -53,7 +53,7 @@ crate fn wf_clause_for_slice(tcx: TyCtxt<'_>) -> Clauses<'_> { None => return ty::List::empty(), }; let sized_implemented = - ty::TraitRef { def_id: sized_trait, substs: tcx.mk_substs_trait(ty, ty::List::empty()) }; + ty::TraitRef::new(sized_trait, tcx.mk_substs_trait(ty, ty::List::empty())); let sized_implemented: DomainGoal<'_> = ty::TraitPredicate { trait_ref: sized_implemented }.lower(); @@ -80,7 +80,7 @@ crate fn wf_clause_for_array<'tcx>( None => return ty::List::empty(), }; let sized_implemented = - ty::TraitRef { def_id: sized_trait, substs: tcx.mk_substs_trait(ty, ty::List::empty()) }; + ty::TraitRef::new(sized_trait, tcx.mk_substs_trait(ty, ty::List::empty())); let sized_implemented: DomainGoal<'_> = ty::TraitPredicate { trait_ref: sized_implemented }.lower(); @@ -108,9 +108,8 @@ crate fn wf_clause_for_tuple(tcx: TyCtxt<'_>, arity: usize) -> Clauses<'_> { // hypotheses is actually empty. let sized_implemented = type_list[0..std::cmp::max(arity, 1) - 1] .iter() - .map(|ty| ty::TraitRef { - def_id: sized_trait, - substs: tcx.mk_substs_trait(ty.expect_ty(), ty::List::empty()), + .map(|ty| { + ty::TraitRef::new(sized_trait, tcx.mk_substs_trait(ty.expect_ty(), ty::List::empty())) }) .map(|trait_ref| ty::TraitPredicate { trait_ref }) .map(|predicate| predicate.lower()); diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 4b4fa4b7147fc..1e6b2f241d54c 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -189,7 +189,7 @@ fn program_clauses_for_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Clauses<'_> { let bound_vars = InternalSubsts::bound_vars_for_item(tcx, def_id); // `Self: Trait` - let trait_pred = ty::TraitPredicate { trait_ref: ty::TraitRef { def_id, substs: bound_vars } }; + let trait_pred = ty::TraitPredicate { trait_ref: ty::TraitRef::new(def_id, bound_vars) }; // `Implemented(Self: Trait)` let impl_trait: DomainGoal<'_> = trait_pred.lower(); @@ -413,7 +413,7 @@ pub fn program_clauses_for_associated_type_def(tcx: TyCtxt<'_>, item_id: DefId) }; let trait_bound_vars = InternalSubsts::bound_vars_for_item(tcx, trait_id); - let trait_ref = ty::TraitRef { def_id: trait_id, substs: trait_bound_vars }; + let trait_ref = ty::TraitRef::new(trait_id, trait_bound_vars); let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.ident); let placeholder_ty = tcx.mk_ty(ty::UnnormalizedProjection(projection_ty)); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index dae394b8f4bd4..4cd91c0bf2a4c 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -902,6 +902,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { trait_ref: &hir::TraitRef<'_>, self_ty: Ty<'tcx>, ) -> ty::TraitRef<'tcx> { + debug_assert!( + trait_ref.constness.is_none(), + "`instantiate_mono_trait_ref` is only used to lower `impl Trait` for now and \ + must be modified to support `?const`" + ); + self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1); self.ast_path_to_mono_trait_ref( @@ -943,7 +949,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self_ty, trait_ref.path.segments.last().unwrap(), ); - let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new(trait_def_id, substs)); + let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new_maybe_const( + trait_def_id, + substs, + trait_ref.is_maybe_const(), + )); bounds.trait_bounds.push((poly_trait_ref, span)); @@ -2961,10 +2971,8 @@ impl<'tcx> Bounds<'tcx> { // If it could be sized, and is, add the `Sized` predicate. let sized_predicate = self.implicitly_sized.and_then(|span| { tcx.lang_items().sized_trait().map(|sized| { - let trait_ref = ty::Binder::bind(ty::TraitRef { - def_id: sized, - substs: tcx.mk_substs_trait(param_ty, &[]), - }); + let trait_ref = + ty::Binder::bind(ty::TraitRef::new(sized, tcx.mk_substs_trait(param_ty, &[]))); (trait_ref.to_predicate(), span) }) }); diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 8d6b74c3015c9..03932b645b757 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -117,10 +117,8 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { let tcx = self.infcx.tcx; // - let trait_ref = TraitRef { - def_id: tcx.lang_items().deref_trait()?, - substs: tcx.mk_substs_trait(self.cur_ty, &[]), - }; + let trait_ref = + TraitRef::new(tcx.lang_items().deref_trait()?, tcx.mk_substs_trait(self.cur_ty, &[])); let cause = traits::ObligationCause::misc(self.span, self.body_id); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index a496a6e12ce1a..6d084f1146031 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -950,10 +950,8 @@ fn receiver_is_implemented( cause: ObligationCause<'tcx>, receiver_ty: Ty<'tcx>, ) -> bool { - let trait_ref = ty::TraitRef { - def_id: receiver_trait_def_id, - substs: fcx.tcx.mk_substs_trait(receiver_ty, &[]), - }; + let trait_ref = + ty::TraitRef::new(receiver_trait_def_id, fcx.tcx.mk_substs_trait(receiver_ty, &[])); let obligation = traits::Obligation::new(cause, fcx.param_env, trait_ref.to_predicate()); diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index c8b63ed5c8096..644e7016e2113 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -40,10 +40,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { let auto_traits = self.cx.auto_traits.iter().cloned(); auto_traits .filter_map(|trait_def_id| { - let trait_ref = ty::TraitRef { - def_id: trait_def_id, - substs: self.cx.tcx.mk_substs_trait(ty, &[]), - }; + let trait_ref = + ty::TraitRef::new(trait_def_id, self.cx.tcx.mk_substs_trait(ty, &[])); if !self.cx.generated_synthetics.borrow_mut().insert((ty, trait_def_id)) { debug!("get_auto_trait_impl_for({:?}): already generated, aborting", trait_ref); return None; From 4aab6ca21aa9b9e7e69ecd1e06d2e8392fbbae3c Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 10 Jan 2020 16:11:20 -0800 Subject: [PATCH 3/5] Allow `?const Trait` to pass validation --- src/librustc_ast_lowering/lib.rs | 2 +- src/librustc_mir/transform/qualify_min_const_fn.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 0a4e77251d7b5..9d912525a2df5 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -2157,7 +2157,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { mut itctx: ImplTraitContext<'_, 'hir>, ) -> hir::PolyTraitRef<'hir> { if p.trait_ref.constness.is_some() { - self.diagnostic().span_err(p.span, "`?const` on trait bounds is not yet implemented"); + // self.diagnostic().span_err(p.span, "`?const` on trait bounds is not yet implemented"); } let bound_generic_params = self.lower_generic_params( diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 7034556740849..b36fcc80264a8 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -33,6 +33,13 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - } match pred.skip_binder().self_ty().kind { ty::Param(ref p) => { + // Allow `T: ?const Trait` + if pred.skip_binder().trait_ref.maybe_const + && feature_allowed(tcx, def_id, sym::const_trait_bound_opt_out) + { + continue; + } + let generics = tcx.generics_of(current); let def = generics.type_param(p, tcx); let span = tcx.def_span(def.def_id); From 6295aba3fb6e3962e8279cc190be6f62469036de Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 10 Jan 2020 16:12:36 -0800 Subject: [PATCH 4/5] Update tests --- .../feature-gate.gated.stderr | 8 ++--- .../const-trait-bound-opt-out/feature-gate.rs | 4 ++- .../feature-gate.stock.stderr | 10 ++---- .../in-impl-trait.rs | 4 --- .../in-impl-trait.stderr | 32 +++---------------- .../in-trait-bounds.rs | 1 - .../in-trait-bounds.stderr | 8 +---- .../in-trait-object.rs | 3 -- .../in-trait-object.stderr | 24 ++------------ .../with-maybe-sized.rs | 1 - .../with-maybe-sized.stderr | 8 +---- 11 files changed, 18 insertions(+), 85 deletions(-) diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr index 0bf337ad08dbf..e4f4d4262b64d 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr @@ -1,8 +1,8 @@ -error: `?const` on trait bounds is not yet implemented - --> $DIR/feature-gate.rs:11:29 +error: fatal error triggered by #[rustc_error] + --> $DIR/feature-gate.rs:16:1 | -LL | const fn get_assoc_const() -> i32 { ::CONST } - | ^^^^^^^^ +LL | fn main() {} + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs index cf1ed30da0fcc..f7ba8dab24cab 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs @@ -3,6 +3,7 @@ #![cfg_attr(gated, feature(const_trait_bound_opt_out))] #![allow(incomplete_features)] +#![feature(rustc_attrs)] trait T { const CONST: i32; @@ -10,6 +11,7 @@ trait T { const fn get_assoc_const() -> i32 { ::CONST } //[stock]~^ ERROR `?const` on trait bounds is experimental -//[stock,gated]~^^ ERROR `?const` on trait bounds is not yet implemented +#[rustc_error] fn main() {} +//[gated]~^ ERROR fatal error triggered by #[rustc_error] diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr index 64388004b5b72..fbd3840cb1d2b 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr @@ -1,5 +1,5 @@ error[E0658]: `?const` on trait bounds is experimental - --> $DIR/feature-gate.rs:11:29 + --> $DIR/feature-gate.rs:12:29 | LL | const fn get_assoc_const() -> i32 { ::CONST } | ^^^^^^ @@ -7,12 +7,6 @@ LL | const fn get_assoc_const() -> i32 { ::CONST } = note: for more information, see https://github.com/rust-lang/rust/issues/67794 = help: add `#![feature(const_trait_bound_opt_out)]` to the crate attributes to enable -error: `?const` on trait bounds is not yet implemented - --> $DIR/feature-gate.rs:11:29 - | -LL | const fn get_assoc_const() -> i32 { ::CONST } - | ^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs index e4e6bedd93746..f5561a922ddcd 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs @@ -8,18 +8,14 @@ impl T for S {} fn rpit() -> impl ?const T { S } //~^ ERROR `?const` is not permitted in `impl Trait` -//~| ERROR `?const` on trait bounds is not yet implemented fn apit(_: impl ?const T) {} //~^ ERROR `?const` is not permitted in `impl Trait` -//~| ERROR `?const` on trait bounds is not yet implemented fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } //~^ ERROR `?const` is not permitted in `impl Trait` -//~| ERROR `?const` on trait bounds is not yet implemented fn apit_assoc_bound(_: impl IntoIterator) {} //~^ ERROR `?const` is not permitted in `impl Trait` -//~| ERROR `?const` on trait bounds is not yet implemented fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr index f4abd4b714e8a..06cd00a956a2d 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr @@ -5,46 +5,22 @@ LL | fn rpit() -> impl ?const T { S } | ^^^^^^^^ error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:13:17 + --> $DIR/in-impl-trait.rs:12:17 | LL | fn apit(_: impl ?const T) {} | ^^^^^^^^ error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:17:50 + --> $DIR/in-impl-trait.rs:15:50 | LL | fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } | ^^^^^^^^ error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:21:48 + --> $DIR/in-impl-trait.rs:18:48 | LL | fn apit_assoc_bound(_: impl IntoIterator) {} | ^^^^^^^^ -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-impl-trait.rs:9:19 - | -LL | fn rpit() -> impl ?const T { S } - | ^^^^^^^^ - -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-impl-trait.rs:13:17 - | -LL | fn apit(_: impl ?const T) {} - | ^^^^^^^^ - -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-impl-trait.rs:17:50 - | -LL | fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } - | ^^^^^^^^ - -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-impl-trait.rs:21:48 - | -LL | fn apit_assoc_bound(_: impl IntoIterator) {} - | ^^^^^^^^ - -error: aborting due to 8 previous errors +error: aborting due to 4 previous errors diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs index 4523b46bc51f6..fc9ed5b1dc22e 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs @@ -4,6 +4,5 @@ trait Super {} trait T: ?const Super {} //~^ ERROR `?const` is not permitted in supertraits -//~| ERROR `?const` on trait bounds is not yet implemented fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr index 8003361be7d2e..a0d8f95acd2a8 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr @@ -4,11 +4,5 @@ error: `?const` is not permitted in supertraits LL | trait T: ?const Super {} | ^^^^^^^^^^^^ -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-trait-bounds.rs:5:10 - | -LL | trait T: ?const Super {} - | ^^^^^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs index 6cfca71548674..b3d1f48ace147 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs @@ -9,14 +9,11 @@ impl T for S {} // An inherent impl for the trait object `?const T`. impl ?const T {} //~^ ERROR `?const` is not permitted in trait objects -//~| ERROR `?const` on trait bounds is not yet implemented fn trait_object() -> &'static dyn ?const T { &S } //~^ ERROR `?const` is not permitted in trait objects -//~| ERROR `?const` on trait bounds is not yet implemented fn trait_object_in_apit(_: impl IntoIterator>) {} //~^ ERROR `?const` is not permitted in trait objects -//~| ERROR `?const` on trait bounds is not yet implemented fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr index c059f16902250..331fe0423fa94 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr @@ -5,34 +5,16 @@ LL | impl ?const T {} | ^^^^^^^^ error: `?const` is not permitted in trait objects - --> $DIR/in-trait-object.rs:14:35 + --> $DIR/in-trait-object.rs:13:35 | LL | fn trait_object() -> &'static dyn ?const T { &S } | ^^^^^^^^ error: `?const` is not permitted in trait objects - --> $DIR/in-trait-object.rs:18:61 + --> $DIR/in-trait-object.rs:16:61 | LL | fn trait_object_in_apit(_: impl IntoIterator>) {} | ^^^^^^^^ -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-trait-object.rs:10:6 - | -LL | impl ?const T {} - | ^^^^^^^^ - -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-trait-object.rs:14:35 - | -LL | fn trait_object() -> &'static dyn ?const T { &S } - | ^^^^^^^^ - -error: `?const` on trait bounds is not yet implemented - --> $DIR/in-trait-object.rs:18:61 - | -LL | fn trait_object_in_apit(_: impl IntoIterator>) {} - | ^^^^^^^^ - -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs index 425784f4e4326..c2c8689e2942b 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs @@ -3,6 +3,5 @@ struct S(std::marker::PhantomData); //~^ ERROR `?const` and `?` are mutually exclusive -//~| ERROR `?const` on trait bounds is not yet implemented fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr index 44f6d464ae6a8..e8e9d6c1e7621 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr @@ -4,11 +4,5 @@ error: `?const` and `?` are mutually exclusive LL | struct S(std::marker::PhantomData); | ^^^^^^^^^^^^^ -error: `?const` on trait bounds is not yet implemented - --> $DIR/with-maybe-sized.rs:4:13 - | -LL | struct S(std::marker::PhantomData); - | ^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error From c37571dfe0cd011ca90cc6116ab97cde398eca9f Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 11 Jan 2020 17:26:03 -0800 Subject: [PATCH 5/5] Placate tidy --- src/librustc_typeck/astconv.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 4cd91c0bf2a4c..6edaad0d96658 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2,6 +2,8 @@ //! The main routine here is `ast_ty_to_ty()`; each use is parameterized by an //! instance of `AstConv`. +// ignore-tidy-filelength + use crate::collect::PlaceholderHirTyCollector; use crate::lint; use crate::middle::lang_items::SizedTraitLangItem;