From 034c25f33e496f602edebd845ddb4f940ac176cf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 7 May 2020 10:12:19 +0000 Subject: [PATCH] make `to_predicate` take a `tcx` argument --- src/librustc_infer/traits/engine.rs | 2 +- src/librustc_infer/traits/util.rs | 4 +- src/librustc_middle/ty/mod.rs | 18 ++--- src/librustc_middle/ty/sty.rs | 4 +- .../traits/error_reporting/mod.rs | 14 ++-- .../traits/error_reporting/suggestions.rs | 73 ++++++++++--------- src/librustc_trait_selection/traits/mod.rs | 4 +- .../traits/object_safety.rs | 6 +- .../traits/project.rs | 11 +-- src/librustc_trait_selection/traits/select.rs | 6 +- src/librustc_trait_selection/traits/util.rs | 9 ++- src/librustc_trait_selection/traits/wf.rs | 6 +- src/librustc_ty/ty.rs | 2 +- src/librustc_typeck/astconv.rs | 8 +- src/librustc_typeck/check/autoderef.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 7 +- src/librustc_typeck/collect.rs | 8 +- src/librustdoc/clean/blanket_impl.rs | 2 +- 22 files changed, 102 insertions(+), 92 deletions(-) diff --git a/src/librustc_infer/traits/engine.rs b/src/librustc_infer/traits/engine.rs index a95257ba682..2710debea94 100644 --- a/src/librustc_infer/traits/engine.rs +++ b/src/librustc_infer/traits/engine.rs @@ -33,7 +33,7 @@ fn register_bound( cause, recursion_depth: 0, param_env, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(infcx.tcx), }, ); } diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index 400fe4d1321..b9cafc530cd 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -99,14 +99,14 @@ pub fn elaborate_trait_ref<'tcx>( tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, ) -> Elaborator<'tcx> { - elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate())) + elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate(tcx))) } pub fn elaborate_trait_refs<'tcx>( tcx: TyCtxt<'tcx>, trait_refs: impl Iterator>, ) -> Elaborator<'tcx> { - let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate()); + let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate(tcx)); elaborate_predicates(tcx, predicates) } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index e3aeb242dc0..16a44328b82 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1295,11 +1295,11 @@ fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx> { } pub trait ToPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx>; + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>; } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }), self.constness, @@ -1308,7 +1308,7 @@ fn to_predicate(&self) -> Predicate<'tcx> { } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }), self.constness, @@ -1317,31 +1317,31 @@ fn to_predicate(&self) -> Predicate<'tcx> { } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { PredicateKind::RegionOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { PredicateKind::TypeOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { PredicateKind::Projection(*self) } } @@ -1619,7 +1619,7 @@ pub struct ConstnessAnd { pub value: T, } -// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate()` to ensure that +// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate(tcx)` to ensure that // the constness of trait bounds is being propagated correctly. pub trait WithConstness: Sized { #[inline] diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 8962b243911..1e4aaa60545 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -612,7 +612,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicat use crate::ty::ToPredicate; match *self.skip_binder() { ExistentialPredicate::Trait(tr) => { - Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate() + Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx) } ExistentialPredicate::Projection(p) => { ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty))) @@ -620,7 +620,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicat ExistentialPredicate::AutoTrait(did) => { let trait_ref = Binder(ty::TraitRef { def_id: did, substs: tcx.mk_substs_trait(self_ty, &[]) }); - trait_ref.without_const().to_predicate() + trait_ref.without_const().to_predicate(tcx) } } } diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index ac119a0c3d8..f997fbadd89 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -308,7 +308,7 @@ fn report_selection_error( "{}", message.unwrap_or_else(|| format!( "the trait bound `{}` is not satisfied{}", - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(tcx), post_message, )) ); @@ -1021,13 +1021,13 @@ fn predicate_can_apply( fn note_obligation_cause( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ); fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ); @@ -1390,7 +1390,7 @@ fn mk_obligation_for_def_id( ) -> PredicateObligation<'tcx> { let new_trait_ref = ty::TraitRef { def_id, substs: self.tcx.mk_substs_trait(output_ty, &[]) }; - Obligation::new(cause, param_env, new_trait_ref.without_const().to_predicate()) + Obligation::new(cause, param_env, new_trait_ref.without_const().to_predicate(self.tcx)) } fn maybe_report_ambiguity( @@ -1629,7 +1629,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let obligation = Obligation::new( ObligationCause::dummy(), param_env, - cleaned_pred.without_const().to_predicate(), + cleaned_pred.without_const().to_predicate(selcx.tcx()), ); self.predicate_may_hold(&obligation) @@ -1638,7 +1638,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { fn note_obligation_cause( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ) { // First, attempt to add note to this error with an async-await-specific @@ -1656,7 +1656,7 @@ fn note_obligation_cause( fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ) { if let ( diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index 5baaf838caa..cbc93278353 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -38,14 +38,14 @@ pub trait InferCtxtExt<'tcx> { fn suggest_restricting_param_bound( &self, err: &mut DiagnosticBuilder<'_>, - trait_ref: ty::PolyTraitRef<'_>, + trait_ref: ty::PolyTraitRef<'tcx>, body_id: hir::HirId, ); fn suggest_borrow_on_unsized_slice( &self, code: &ObligationCauseCode<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, ); fn get_closure_name( @@ -66,7 +66,7 @@ fn suggest_fn_call( fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, has_custom_message: bool, @@ -75,14 +75,14 @@ fn suggest_add_reference_to_arg( fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, ); fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, ); @@ -90,7 +90,7 @@ fn suggest_change_mut( fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, trait_ref: &ty::Binder>, ); @@ -99,7 +99,7 @@ fn suggest_semicolon_removal( fn suggest_impl_trait( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, obligation: &PredicateObligation<'tcx>, trait_ref: &ty::Binder>, @@ -107,7 +107,7 @@ fn suggest_impl_trait( fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, obligation: &PredicateObligation<'tcx>, ); @@ -138,11 +138,11 @@ fn note_obligation_cause_for_async_await( err: &mut DiagnosticBuilder<'_>, interior_or_upvar_span: GeneratorInteriorOrUpvar, interior_extra_info: Option<(Option, Span, Option, Option)>, - inner_generator_body: Option<&hir::Body<'_>>, + inner_generator_body: Option<&hir::Body<'tcx>>, outer_generator: Option, - trait_ref: ty::TraitRef<'_>, + trait_ref: ty::TraitRef<'tcx>, target_ty: Ty<'tcx>, - tables: &ty::TypeckTables<'_>, + tables: &ty::TypeckTables<'tcx>, obligation: &PredicateObligation<'tcx>, next_code: Option<&ObligationCauseCode<'tcx>>, ); @@ -183,12 +183,13 @@ fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, St /// it can also be an `impl Trait` param that needs to be decomposed to a type /// param for cleaner code. fn suggest_restriction( - generics: &hir::Generics<'_>, + tcx: TyCtxt<'tcx>, + generics: &hir::Generics<'tcx>, msg: &str, err: &mut DiagnosticBuilder<'_>, fn_sig: Option<&hir::FnSig<'_>>, projection: Option<&ty::ProjectionTy<'_>>, - trait_ref: ty::PolyTraitRef<'_>, + trait_ref: ty::PolyTraitRef<'tcx>, super_traits: Option<(&Ident, &hir::GenericBounds<'_>)>, ) { // When we are dealing with a trait, `super_traits` will be `Some`: @@ -243,7 +244,7 @@ fn suggest_restriction( // FIXME: modify the `trait_ref` instead of string shenanigans. // Turn `::Bar: Qux` into `::Bar: Qux`. - let pred = trait_ref.without_const().to_predicate().to_string(); + let pred = trait_ref.without_const().to_predicate(tcx).to_string(); let pred = pred.replace(&impl_trait_str, &type_param_name); let mut sugg = vec![ match generics @@ -285,9 +286,10 @@ fn suggest_restriction( } else { // Trivial case: `T` needs an extra bound: `T: Bound`. let (sp, suggestion) = match super_traits { - None => { - predicate_constraint(generics, trait_ref.without_const().to_predicate().to_string()) - } + None => predicate_constraint( + generics, + trait_ref.without_const().to_predicate(tcx).to_string(), + ), Some((ident, bounds)) => match bounds { [.., bound] => ( bound.span().shrink_to_hi(), @@ -313,7 +315,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_restricting_param_bound( &self, mut err: &mut DiagnosticBuilder<'_>, - trait_ref: ty::PolyTraitRef<'_>, + trait_ref: ty::PolyTraitRef<'tcx>, body_id: hir::HirId, ) { let self_ty = trait_ref.self_ty(); @@ -336,6 +338,7 @@ fn suggest_restricting_param_bound( assert!(param_ty); // Restricting `Self` for a single method. suggest_restriction( + self.tcx, &generics, "`Self`", err, @@ -355,7 +358,7 @@ fn suggest_restricting_param_bound( assert!(param_ty); // Restricting `Self` for a single method. suggest_restriction( - &generics, "`Self`", err, None, projection, trait_ref, None, + self.tcx, &generics, "`Self`", err, None, projection, trait_ref, None, ); return; } @@ -375,6 +378,7 @@ fn suggest_restricting_param_bound( }) if projection.is_some() => { // Missing restriction on associated type of type parameter (unmet projection). suggest_restriction( + self.tcx, &generics, "the associated type", err, @@ -393,6 +397,7 @@ fn suggest_restricting_param_bound( }) if projection.is_some() => { // Missing restriction on associated type of type parameter (unmet projection). suggest_restriction( + self.tcx, &generics, "the associated type", err, @@ -450,7 +455,7 @@ fn suggest_restricting_param_bound( fn suggest_borrow_on_unsized_slice( &self, code: &ObligationCauseCode<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, ) { if let &ObligationCauseCode::VariableType(hir_id) = code { let parent_node = self.tcx.hir().get_parent_node(hir_id); @@ -601,7 +606,7 @@ fn suggest_fn_call( fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, has_custom_message: bool, @@ -624,7 +629,7 @@ fn suggest_add_reference_to_arg( let new_obligation = Obligation::new( ObligationCause::dummy(), param_env, - new_trait_ref.without_const().to_predicate(), + new_trait_ref.without_const().to_predicate(self.tcx), ); if self.predicate_must_hold_modulo_regions(&new_obligation) { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { @@ -673,7 +678,7 @@ fn suggest_add_reference_to_arg( fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, ) { let trait_ref = trait_ref.skip_binder(); @@ -735,7 +740,7 @@ fn suggest_remove_reference( fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, ) { @@ -806,7 +811,7 @@ fn suggest_change_mut( fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, trait_ref: &ty::Binder>, ) { @@ -852,7 +857,7 @@ fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option, + err: &mut DiagnosticBuilder<'_>, span: Span, obligation: &PredicateObligation<'tcx>, trait_ref: &ty::Binder>, @@ -1048,7 +1053,7 @@ fn suggest_impl_trait( fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, obligation: &PredicateObligation<'tcx>, ) { match obligation.cause.code.peel_derives() { @@ -1430,11 +1435,11 @@ fn note_obligation_cause_for_async_await( err: &mut DiagnosticBuilder<'_>, interior_or_upvar_span: GeneratorInteriorOrUpvar, interior_extra_info: Option<(Option, Span, Option, Option)>, - inner_generator_body: Option<&hir::Body<'_>>, + inner_generator_body: Option<&hir::Body<'tcx>>, outer_generator: Option, - trait_ref: ty::TraitRef<'_>, + trait_ref: ty::TraitRef<'tcx>, target_ty: Ty<'tcx>, - tables: &ty::TypeckTables<'_>, + tables: &ty::TypeckTables<'tcx>, obligation: &PredicateObligation<'tcx>, next_code: Option<&ObligationCauseCode<'tcx>>, ) { @@ -1788,7 +1793,7 @@ fn note_obligation_cause_code( err.note(&format!("required because it appears within the type `{}`", ty)); obligated_types.push(ty); - let parent_predicate = parent_trait_ref.without_const().to_predicate(); + let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); if !self.is_recursive_obligation(obligated_types, &data.parent_code) { self.note_obligation_cause_code( err, @@ -1805,7 +1810,7 @@ fn note_obligation_cause_code( parent_trait_ref.print_only_trait_path(), parent_trait_ref.skip_binder().self_ty() )); - let parent_predicate = parent_trait_ref.without_const().to_predicate(); + let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); self.note_obligation_cause_code( err, &parent_predicate, @@ -1815,7 +1820,7 @@ fn note_obligation_cause_code( } ObligationCauseCode::DerivedObligation(ref data) => { let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); - let parent_predicate = parent_trait_ref.without_const().to_predicate(); + let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); self.note_obligation_cause_code( err, &parent_predicate, @@ -2061,7 +2066,7 @@ fn next_type_param_name(&self, name: Option<&str>) -> String { } fn suggest_trait_object_return_type_alternatives( - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, ret_ty: Span, trait_obj: &str, is_object_safe: bool, diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index 99d434c5c92..f67669769a1 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -143,7 +143,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>( param_env, cause: ObligationCause::misc(span, hir::CRATE_HIR_ID), recursion_depth: 0, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(infcx.tcx), }; let result = infcx.predicate_must_hold_modulo_regions(&obligation); @@ -557,7 +557,7 @@ fn type_implements_trait<'tcx>( cause: ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(tcx), }; tcx.infer_ctxt().enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation)) } diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index bb727055d03..4839a25d85f 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -636,7 +636,7 @@ fn receiver_is_dispatchable<'tcx>( substs: tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]), } .without_const() - .to_predicate(); + .to_predicate(tcx); // U: Trait let trait_predicate = { @@ -649,7 +649,7 @@ fn receiver_is_dispatchable<'tcx>( } }); - ty::TraitRef { def_id: unsize_did, substs }.without_const().to_predicate() + ty::TraitRef { def_id: unsize_did, substs }.without_const().to_predicate(tcx) }; let caller_bounds: Vec> = param_env @@ -672,7 +672,7 @@ fn receiver_is_dispatchable<'tcx>( substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]), } .without_const() - .to_predicate(); + .to_predicate(tcx); Obligation::new(ObligationCause::dummy(), param_env, predicate) }; diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index 54b064359dc..79b6ac3f7ad 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -432,7 +432,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>( }); let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var }); let obligation = - Obligation::with_depth(cause, depth + 1, param_env, projection.to_predicate()); + Obligation::with_depth(cause, depth + 1, param_env, projection.to_predicate(tcx)); obligations.push(obligation); ty_var }) @@ -722,7 +722,7 @@ fn get_paranoid_cache_value_obligation<'a, 'tcx>( cause, recursion_depth: depth, param_env, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(infcx.tcx), } } @@ -757,7 +757,7 @@ fn normalize_to_error<'a, 'tcx>( cause, recursion_depth: depth, param_env, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(selcx.tcx()), }; let tcx = selcx.infcx().tcx; let def_id = projection_ty.item_def_id; @@ -1158,8 +1158,9 @@ fn confirm_object_candidate<'cx, 'tcx>( object_ty ), }; - let env_predicates = - data.projection_bounds().map(|p| p.with_self_ty(selcx.tcx(), object_ty).to_predicate()); + let env_predicates = data + .projection_bounds() + .map(|p| p.with_self_ty(selcx.tcx(), object_ty).to_predicate(selcx.tcx())); let env_predicate = { let env_predicates = elaborate_predicates(selcx.tcx(), env_predicates); diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 02da6033a00..2aae0f27031 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -3031,7 +3031,7 @@ fn confirm_builtin_unsize_candidate( cause, obligation.recursion_depth + 1, obligation.param_env, - ty::Binder::bind(outlives).to_predicate(), + ty::Binder::bind(outlives).to_predicate(tcx), )); } @@ -3074,12 +3074,12 @@ fn confirm_builtin_unsize_candidate( tcx.require_lang_item(lang_items::SizedTraitLangItem, None), tcx.mk_substs_trait(source, &[]), ); - nested.push(predicate_to_obligation(tr.without_const().to_predicate())); + nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx))); // If the type is `Foo + 'a`, ensure that the type // being cast to `Foo + 'a` outlives `'a`: let outlives = ty::OutlivesPredicate(source, r); - nested.push(predicate_to_obligation(ty::Binder::dummy(outlives).to_predicate())); + nested.push(predicate_to_obligation(ty::Binder::dummy(outlives).to_predicate(tcx))); } // `[T; n]` -> `[T]` diff --git a/src/librustc_trait_selection/traits/util.rs b/src/librustc_trait_selection/traits/util.rs index eff73cf4a2d..f2d3f0e1116 100644 --- a/src/librustc_trait_selection/traits/util.rs +++ b/src/librustc_trait_selection/traits/util.rs @@ -97,7 +97,7 @@ impl<'tcx> TraitAliasExpander<'tcx> { fn expand(&mut self, item: &TraitAliasExpansionInfo<'tcx>) -> bool { let tcx = self.tcx; let trait_ref = item.trait_ref(); - let pred = trait_ref.without_const().to_predicate(); + let pred = trait_ref.without_const().to_predicate(tcx); debug!("expand_trait_aliases: trait_ref={:?}", trait_ref); @@ -110,7 +110,7 @@ fn expand(&mut self, item: &TraitAliasExpansionInfo<'tcx>) -> bool { // Don't recurse if this trait alias is already on the stack for the DFS search. let anon_pred = anonymize_predicate(tcx, &pred); if item.path.iter().rev().skip(1).any(|(tr, _)| { - anonymize_predicate(tcx, &tr.without_const().to_predicate()) == anon_pred + anonymize_predicate(tcx, &tr.without_const().to_predicate(tcx)) == anon_pred }) { return false; } @@ -234,6 +234,7 @@ pub fn predicates_for_generics<'tcx>( } pub fn predicate_for_trait_ref<'tcx>( + tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, trait_ref: ty::TraitRef<'tcx>, @@ -243,7 +244,7 @@ pub fn predicate_for_trait_ref<'tcx>( cause, param_env, recursion_depth, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(tcx), } } @@ -258,7 +259,7 @@ pub fn predicate_for_trait_def( ) -> PredicateObligation<'tcx> { let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(self_ty, params) }; - predicate_for_trait_ref(cause, param_env, trait_ref, recursion_depth) + predicate_for_trait_ref(tcx, cause, param_env, trait_ref, recursion_depth) } /// Casts a trait reference into a reference to one of its super diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index b1b50eb2331..a6f4819277c 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -292,7 +292,7 @@ fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) { self.compute_trait_ref(&trait_ref, Elaborate::None); if !data.has_escaping_bound_vars() { - let predicate = trait_ref.without_const().to_predicate(); + let predicate = trait_ref.without_const().to_predicate(self.infcx.tcx); let cause = self.cause(traits::ProjectionWf(data)); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); } @@ -323,7 +323,7 @@ fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode< self.out.push(traits::Obligation::new( cause, self.param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(self.infcx.tcx), )); } } @@ -610,7 +610,7 @@ fn from_object_ty( self.out.push(traits::Obligation::new( cause, self.param_env, - outlives.to_predicate(), + outlives.to_predicate(self.infcx.tcx), )); } } diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 1aa11a761c8..3da5da2d9ef 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -61,7 +61,7 @@ fn sized_constraint_for_ty<'tcx>( substs: tcx.mk_substs_trait(ty, &[]), }) .without_const() - .to_predicate(); + .to_predicate(tcx); let predicates = tcx.predicates_of(adtdef.did).predicates; if predicates.iter().any(|(p, _)| *p == sized_predicate) { vec![] } else { vec![ty] } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a697ae7cb87..f8144d4aade 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -3042,7 +3042,7 @@ pub fn predicates( def_id: sized, substs: tcx.mk_substs_trait(param_ty, &[]), }); - (trait_ref.without_const().to_predicate(), span) + (trait_ref.without_const().to_predicate(tcx), span) }) }); @@ -3057,16 +3057,16 @@ pub fn predicates( // or it's a generic associated type that deliberately has escaping bound vars. let region_bound = ty::fold::shift_region(tcx, region_bound, 1); let outlives = ty::OutlivesPredicate(param_ty, region_bound); - (ty::Binder::bind(outlives).to_predicate(), span) + (ty::Binder::bind(outlives).to_predicate(tcx), span) }) .chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| { - let predicate = bound_trait_ref.with_constness(constness).to_predicate(); + let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx); (predicate, span) })) .chain( self.projection_bounds .iter() - .map(|&(projection, span)| (projection.to_predicate(), span)), + .map(|&(projection, span)| (projection.to_predicate(tcx), span)), ), ) .collect() diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index ae6c1738da7..8ca08610906 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -125,7 +125,7 @@ fn overloaded_deref_ty(&mut self, ty: Ty<'tcx>) -> Option> { let obligation = traits::Obligation::new( cause.clone(), self.param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(tcx), ); if !self.infcx.predicate_may_hold(&obligation) { debug!("overloaded_deref_ty: cannot match obligation"); diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 135e02d6b5f..d1da0bbda54 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -324,7 +324,7 @@ pub fn lookup_method_in_trait( span, self.body_id, self.param_env, - poly_trait_ref.without_const().to_predicate(), + poly_trait_ref.without_const().to_predicate(self.tcx), ); // Now we want to know if this can be matched diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index fbe8e7b7675..f1a1c48da16 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1374,7 +1374,7 @@ fn consider_probe( } TraitCandidate(trait_ref) => { - let predicate = trait_ref.without_const().to_predicate(); + let predicate = trait_ref.without_const().to_predicate(self.tcx); let obligation = traits::Obligation::new(cause, self.param_env, predicate); if !self.predicate_may_hold(&obligation) { result = ProbeResult::NoMatch; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index e0ab25e4922..321cc7a3c4b 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -58,7 +58,7 @@ fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool { span, self.body_id, self.param_env, - poly_trait_ref.without_const().to_predicate(), + poly_trait_ref.without_const().to_predicate(tcx), ); self.predicate_may_hold(&obligation) }) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 79cb7a7fd0f..b9055722bb5 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1458,7 +1458,7 @@ fn check_fn<'a, 'tcx>( inherited.register_predicate(traits::Obligation::new( cause, param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(tcx), )); } } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index cb3ee8d1ded..aa386505939 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1174,8 +1174,11 @@ fn receiver_is_implemented( substs: fcx.tcx.mk_substs_trait(receiver_ty, &[]), }; - let obligation = - traits::Obligation::new(cause, fcx.param_env, trait_ref.without_const().to_predicate()); + let obligation = traits::Obligation::new( + cause, + fcx.param_env, + trait_ref.without_const().to_predicate(fcx.tcx), + ); if fcx.predicate_must_hold_modulo_regions(&obligation) { true diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index c39df5df977..529c9f9f505 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -528,7 +528,7 @@ fn type_param_predicates( if param_id == item_hir_id { let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id); extend = - Some((identity_trait_ref.without_const().to_predicate(), item.span)); + Some((identity_trait_ref.without_const().to_predicate(tcx), item.span)); } generics } @@ -1657,7 +1657,7 @@ fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> { let span = tcx.sess.source_map().guess_head_span(tcx.def_span(def_id)); result.predicates = tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once(( - ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(), + ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(tcx), span, )))); } @@ -1832,7 +1832,7 @@ fn extend, Span)>>(&mut self, iter: // set of defaults that can be incorporated into another impl. if let Some(trait_ref) = is_default_impl_trait { predicates.push(( - trait_ref.to_poly_trait_ref().without_const().to_predicate(), + trait_ref.to_poly_trait_ref().without_const().to_predicate(tcx), tcx.def_span(def_id), )); } @@ -1855,7 +1855,7 @@ fn extend, Span)>>(&mut self, iter: hir::GenericBound::Outlives(lt) => { let bound = AstConv::ast_region_to_region(&icx, <, None); let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound)); - predicates.push((outlives.to_predicate(), lt.span)); + predicates.push((outlives.to_predicate(tcx), lt.span)); } _ => bug!(), }); diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index d987505e427..3d2785541be 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -65,7 +65,7 @@ pub fn get_blanket_impls(&self, ty: Ty<'tcx>, param_env_def_id: DefId) -> Vec eval_result.may_apply(), Err(traits::OverflowError) => true, // overflow doesn't mean yes *or* no -- 2.44.0