make to_predicate
take a tcx
argument
This commit is contained in:
parent
cad8fe90fd
commit
034c25f33e
22 changed files with 102 additions and 92 deletions
|
@ -33,7 +33,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
|
|||
cause,
|
||||
recursion_depth: 0,
|
||||
param_env,
|
||||
predicate: trait_ref.without_const().to_predicate(),
|
||||
predicate: trait_ref.without_const().to_predicate(infcx.tcx),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<Item = ty::PolyTraitRef<'tcx>>,
|
||||
) -> 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -1295,11 +1295,11 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'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<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,
|
||||
|
@ -1308,7 +1308,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'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 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> {
|
|||
}
|
||||
|
||||
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 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<T> {
|
|||
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]
|
||||
|
|
|
@ -612,7 +612,7 @@ impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
|
|||
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 @@ impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
"{}",
|
||||
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 @@ trait InferCtxtPrivExt<'tcx> {
|
|||
|
||||
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 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
) -> 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 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, '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 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, '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 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
|
||||
fn suggest_unsized_bound_if_applicable(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) {
|
||||
if let (
|
||||
|
|
|
@ -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 @@ pub trait InferCtxtExt<'tcx> {
|
|||
fn suggest_add_reference_to_arg(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
has_custom_message: bool,
|
||||
|
@ -75,14 +75,14 @@ pub trait InferCtxtExt<'tcx> {
|
|||
fn suggest_remove_reference(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
);
|
||||
|
||||
fn suggest_change_mut(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
);
|
||||
|
@ -90,7 +90,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
fn suggest_semicolon_removal(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
);
|
||||
|
@ -99,7 +99,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
|
||||
fn suggest_impl_trait(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
|
@ -107,7 +107,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
|
||||
fn point_at_returns_when_relevant(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
);
|
||||
|
||||
|
@ -138,11 +138,11 @@ pub trait InferCtxtExt<'tcx> {
|
|||
err: &mut DiagnosticBuilder<'_>,
|
||||
interior_or_upvar_span: GeneratorInteriorOrUpvar,
|
||||
interior_extra_info: Option<(Option<Span>, Span, Option<hir::HirId>, Option<Span>)>,
|
||||
inner_generator_body: Option<&hir::Body<'_>>,
|
||||
inner_generator_body: Option<&hir::Body<'tcx>>,
|
||||
outer_generator: Option<DefId>,
|
||||
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 `<impl Trait as Foo>::Bar: Qux` into `<T as Foo>::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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
assert!(param_ty);
|
||||
// Restricting `Self` for a single method.
|
||||
suggest_restriction(
|
||||
self.tcx,
|
||||
&generics,
|
||||
"`Self`",
|
||||
err,
|
||||
|
@ -355,7 +358,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
}) 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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
}) 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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
fn suggest_add_reference_to_arg(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
has_custom_message: bool,
|
||||
|
@ -624,7 +629,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
fn suggest_remove_reference(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
) {
|
||||
let trait_ref = trait_ref.skip_binder();
|
||||
|
@ -735,7 +740,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
fn suggest_change_mut(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
) {
|
||||
|
@ -806,7 +811,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
fn suggest_semicolon_removal(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
) {
|
||||
|
@ -852,7 +857,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
/// emitted.
|
||||
fn suggest_impl_trait(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
|
@ -1048,7 +1053,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
|
||||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
err: &mut DiagnosticBuilder<'_>,
|
||||
interior_or_upvar_span: GeneratorInteriorOrUpvar,
|
||||
interior_extra_info: Option<(Option<Span>, Span, Option<hir::HirId>, Option<Span>)>,
|
||||
inner_generator_body: Option<&hir::Body<'_>>,
|
||||
inner_generator_body: Option<&hir::Body<'tcx>>,
|
||||
outer_generator: Option<DefId>,
|
||||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
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 @@ impl NextTypeParamName for &[hir::GenericParam<'_>] {
|
|||
}
|
||||
|
||||
fn suggest_trait_object_return_type_alternatives(
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
ret_ty: Span,
|
||||
trait_obj: &str,
|
||||
is_object_safe: bool,
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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<Arg1, ..., ArgN>
|
||||
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<Predicate<'tcx>> = 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)
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -3031,7 +3031,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
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]`
|
||||
|
|
|
@ -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 @@ impl<'tcx> TraitAliasExpander<'tcx> {
|
|||
// 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
|
||||
|
|
|
@ -292,7 +292,7 @@ impl<'a, 'tcx> WfPredicates<'a, '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 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
self.out.push(traits::Obligation::new(
|
||||
cause,
|
||||
self.param_env,
|
||||
outlives.to_predicate(),
|
||||
outlives.to_predicate(self.infcx.tcx),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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] }
|
||||
}
|
||||
|
|
|
@ -3042,7 +3042,7 @@ impl<'tcx> Bounds<'tcx> {
|
|||
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 @@ impl<'tcx> Bounds<'tcx> {
|
|||
// 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()
|
||||
|
|
|
@ -125,7 +125,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
|||
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");
|
||||
|
|
|
@ -324,7 +324,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
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
|
||||
|
|
|
@ -1374,7 +1374,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -58,7 +58,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
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)
|
||||
})
|
||||
|
|
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
|||
// 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 explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
|||
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!(),
|
||||
});
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||
match infcx.evaluate_obligation(&traits::Obligation::new(
|
||||
cause,
|
||||
param_env,
|
||||
trait_ref.without_const().to_predicate(),
|
||||
trait_ref.without_const().to_predicate(infcx.tcx),
|
||||
)) {
|
||||
Ok(eval_result) => eval_result.may_apply(),
|
||||
Err(traits::OverflowError) => true, // overflow doesn't mean yes *or* no
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue