Skip to content

Commit

Permalink
make to_predicate take a tcx argument
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis authored and lcnr committed May 20, 2020
1 parent cad8fe9 commit 034c25f
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/librustc_infer/traits/engine.rs
Expand Up @@ -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),
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/traits/util.rs
Expand Up @@ -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)
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc_middle/ty/mod.rs
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/sty.rs
Expand Up @@ -612,15 +612,15 @@ 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)))
}
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)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Expand Up @@ -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,
))
);
Expand Down Expand Up @@ -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>,
);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 (
Expand Down

0 comments on commit 034c25f

Please sign in to comment.