Skip to content

rustc: keep a Span for each predicate in ty::GenericPredicates. #54278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustc/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
@@ -297,12 +297,15 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
let tcx = self.tcx;
let assoc_item = tcx.associated_item(assoc_item_def_id);
let trait_def_id = assoc_item.container.assert_trait();
let trait_predicates = tcx.predicates_of(trait_def_id);
let trait_predicates = tcx.predicates_of(trait_def_id).predicates
.into_iter()
.map(|(p, _)| p)
.collect();
let identity_substs = Substs::identity_for_item(tcx, assoc_item_def_id);
let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs);
self.collect_outlives_from_predicate_list(
move |ty| ty == identity_proj,
traits::elaborate_predicates(tcx, trait_predicates.predicates),
traits::elaborate_predicates(tcx, trait_predicates),
).map(|b| b.1)
}

8 changes: 4 additions & 4 deletions src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
@@ -96,10 +96,10 @@ fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, '

let header = ty::ImplHeader {
impl_def_id,
self_ty: tcx.type_of(impl_def_id),
trait_ref: tcx.impl_trait_ref(impl_def_id),
predicates: tcx.predicates_of(impl_def_id).predicates
}.subst(tcx, impl_substs);
self_ty: tcx.type_of(impl_def_id).subst(tcx, impl_substs),
trait_ref: tcx.impl_trait_ref(impl_def_id).subst(tcx, impl_substs),
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
};

let Normalized { value: mut header, obligations } =
traits::normalize(selcx, param_env, ObligationCause::dummy(), &header);
3 changes: 1 addition & 2 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -816,11 +816,10 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
key: (DefId, &'tcx Substs<'tcx>))
-> bool
{
use ty::subst::Subst;
debug!("substitute_normalize_and_test_predicates(key={:?})",
key);

let predicates = tcx.predicates_of(key.0).predicates.subst(tcx, key.1);
let predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
let result = normalize_and_test_predicates(tcx, predicates);

debug!("substitute_normalize_and_test_predicates(key={:?}) = {:?}",
4 changes: 2 additions & 2 deletions src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
predicates
.predicates
.into_iter()
.map(|predicate| predicate.subst_supertrait(self, &trait_ref))
.map(|(predicate, _)| predicate.subst_supertrait(self, &trait_ref))
.any(|predicate| {
match predicate {
ty::Predicate::Trait(ref data) => {
@@ -311,7 +311,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
if self.predicates_of(method.def_id).predicates.into_iter()
// A trait object can't claim to live more than the concrete type,
// so outlives predicates will always hold.
.filter(|p| p.to_opt_type_outlives().is_none())
.filter(|(p, _)| p.to_opt_type_outlives().is_none())
.collect::<Vec<_>>()
// Do a shallow visit so that `contains_illegal_self_type_reference`
// may apply it's custom visiting.
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
@@ -3401,7 +3401,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
// that order.
let predicates = tcx.predicates_of(def_id);
assert_eq!(predicates.parent, None);
let mut predicates: Vec<_> = predicates.predicates.iter().flat_map(|predicate| {
let mut predicates: Vec<_> = predicates.predicates.iter().flat_map(|(predicate, _)| {
let predicate = normalize_with_depth(self, param_env, cause.clone(), recursion_depth,
&predicate.subst(tcx, substs));
predicate.obligations.into_iter().chain(
2 changes: 1 addition & 1 deletion src/librustc/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
@@ -428,7 +428,7 @@ fn to_pretty_impl_header(tcx: TyCtxt, impl_def_id: DefId) -> Option<String> {
let mut pretty_predicates = Vec::with_capacity(
predicates.len() + types_without_default_bounds.len());

for p in predicates {
for (p, _) in predicates {
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref() {
if Some(poly_trait_ref.def_id()) == sized_trait {
types_without_default_bounds.remove(poly_trait_ref.self_ty());
4 changes: 2 additions & 2 deletions src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
let mut predicates: Vec<_> =
predicates.predicates
.iter()
.map(|p| p.subst_supertrait(tcx, &data.to_poly_trait_ref()))
.map(|(p, _)| p.subst_supertrait(tcx, &data.to_poly_trait_ref()))
.collect();

debug!("super_predicates: data={:?} predicates={:?}",
@@ -311,7 +311,7 @@ impl<'cx, 'gcx, 'tcx> Iterator for SupertraitDefIds<'cx, 'gcx, 'tcx> {
self.stack.extend(
predicates.predicates
.iter()
.filter_map(|p| p.to_opt_poly_trait_ref())
.filter_map(|(p, _)| p.to_opt_poly_trait_ref())
.map(|t| t.def_id())
.filter(|&super_def_id| visited.insert(super_def_id)));
Some(def_id)
10 changes: 6 additions & 4 deletions src/librustc/ty/codec.rs
Original file line number Diff line number Diff line change
@@ -109,8 +109,9 @@ pub fn encode_predicates<'tcx, E, C>(encoder: &mut E,
{
predicates.parent.encode(encoder)?;
predicates.predicates.len().encode(encoder)?;
for predicate in &predicates.predicates {
encode_with_shorthand(encoder, predicate, &cache)?
for (predicate, span) in &predicates.predicates {
encode_with_shorthand(encoder, predicate, &cache)?;
span.encode(encoder)?;
}
Ok(())
}
@@ -178,15 +179,16 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
parent: Decodable::decode(decoder)?,
predicates: (0..decoder.read_usize()?).map(|_| {
// Handle shorthands first, if we have an usize > 0x80.
if decoder.positioned_at_shorthand() {
let predicate = if decoder.positioned_at_shorthand() {
let pos = decoder.read_usize()?;
assert!(pos >= SHORTHAND_OFFSET);
let shorthand = pos - SHORTHAND_OFFSET;

decoder.with_position(shorthand, ty::Predicate::decode)
} else {
ty::Predicate::decode(decoder)
}
}?;
Ok((predicate, Decodable::decode(decoder)?))
})
.collect::<Result<Vec<_>, _>>()?,
})
14 changes: 8 additions & 6 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -982,7 +982,7 @@ impl<'a, 'gcx, 'tcx> Generics {
#[derive(Clone, Default)]
pub struct GenericPredicates<'tcx> {
pub parent: Option<DefId>,
pub predicates: Vec<Predicate<'tcx>>,
pub predicates: Vec<(Predicate<'tcx>, Span)>,
}

impl<'tcx> serialize::UseSpecializedEncodable for GenericPredicates<'tcx> {}
@@ -998,7 +998,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>)
-> InstantiatedPredicates<'tcx> {
InstantiatedPredicates {
predicates: self.predicates.subst(tcx, substs)
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(),
}
}

@@ -1008,7 +1008,9 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
if let Some(def_id) = self.parent {
tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
}
instantiated.predicates.extend(self.predicates.iter().map(|p| p.subst(tcx, substs)))
instantiated.predicates.extend(
self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)),
);
}

pub fn instantiate_identity(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
@@ -1023,7 +1025,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
if let Some(def_id) = self.parent {
tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated);
}
instantiated.predicates.extend(&self.predicates)
instantiated.predicates.extend(self.predicates.iter().map(|&(p, _)| p))
}

pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -1032,7 +1034,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
{
assert_eq!(self.parent, None);
InstantiatedPredicates {
predicates: self.predicates.iter().map(|pred| {
predicates: self.predicates.iter().map(|(pred, _)| {
pred.subst_supertrait(tcx, poly_trait_ref)
}).collect()
}
@@ -2351,7 +2353,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
substs: tcx.mk_substs_trait(ty, &[])
}).to_predicate();
let predicates = tcx.predicates_of(self.did).predicates;
if predicates.into_iter().any(|p| p == sized_predicate) {
if predicates.into_iter().any(|(p, _)| p == sized_predicate) {
vec![]
} else {
vec![ty]
6 changes: 3 additions & 3 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -1736,8 +1736,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
if cx.tcx.features().trivial_bounds {
let def_id = cx.tcx.hir.local_def_id(item.id);
let predicates = cx.tcx.predicates_of(def_id);
for predicate in &predicates.predicates {
let predicate_kind_name = match *predicate {
for &(predicate, span) in &predicates.predicates {
let predicate_kind_name = match predicate {
Trait(..) => "Trait",
TypeOutlives(..) |
RegionOutlives(..) => "Lifetime",
@@ -1755,7 +1755,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
if predicate.is_global() {
cx.span_lint(
TRIVIAL_BOUNDS,
item.span,
span,
&format!("{} bound {} does not depend on any type \
or lifetime parameters", predicate_kind_name, predicate),
);
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ pub fn is_min_const_fn(
let mut current = def_id;
loop {
let predicates = tcx.predicates_of(current);
for predicate in &predicates.predicates {
for (predicate, _) in &predicates.predicates {
match predicate {
| Predicate::RegionOutlives(_)
| Predicate::TypeOutlives(_)
8 changes: 4 additions & 4 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {

fn predicates(&mut self) -> &mut Self {
let predicates = self.ev.tcx.predicates_of(self.item_def_id);
for predicate in &predicates.predicates {
for (predicate, _) in &predicates.predicates {
predicate.visit_with(self);
match predicate {
&ty::Predicate::Trait(poly_predicate) => {
@@ -781,7 +781,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
if self.check_trait_ref(*principal.skip_binder()) {
return;
}
for poly_predicate in projections {
for (poly_predicate, _) in projections {
let tcx = self.tcx;
if self.check_trait_ref(poly_predicate.skip_binder().projection_ty.trait_ref(tcx)) {
return;
@@ -956,7 +956,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
}
}
ty::Opaque(def_id, ..) => {
for predicate in &self.tcx.predicates_of(def_id).predicates {
for (predicate, _) in &self.tcx.predicates_of(def_id).predicates {
let trait_ref = match *predicate {
ty::Predicate::Trait(ref poly_trait_predicate) => {
Some(poly_trait_predicate.skip_binder().trait_ref)
@@ -1387,7 +1387,7 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
// for the inferred outlives rules; see
// `src/test/ui/rfc-2093-infer-outlives/privacy.rs`.
let predicates = self.tcx.explicit_predicates_of(self.item_def_id);
for predicate in &predicates.predicates {
for (predicate, _) in &predicates.predicates {
predicate.visit_with(self);
match predicate {
&ty::Predicate::Trait(poly_predicate) => {
23 changes: 16 additions & 7 deletions src/librustc_traits/lowering.rs
Original file line number Diff line number Diff line change
@@ -260,7 +260,10 @@ fn program_clauses_for_trait<'a, 'tcx>(

let clauses = iter::once(Clause::ForAll(ty::Binder::dummy(implemented_from_env)));

let where_clauses = &tcx.predicates_defined_on(def_id).predicates;
let where_clauses = &tcx.predicates_defined_on(def_id).predicates
.into_iter()
.map(|(wc, _)| wc.lower())
.collect::<Vec<_>>();

// Rule Implied-Bound-From-Trait
//
@@ -273,8 +276,8 @@ fn program_clauses_for_trait<'a, 'tcx>(

// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`, for each where clause WC
let implied_bound_clauses = where_clauses
.into_iter()
.map(|wc| wc.lower())
.iter()
.cloned()

// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`
.map(|wc| wc.map_bound(|goal| ProgramClause {
@@ -296,8 +299,8 @@ fn program_clauses_for_trait<'a, 'tcx>(
let wf_conditions = iter::once(ty::Binder::dummy(trait_pred.lower()))
.chain(
where_clauses
.into_iter()
.map(|wc| wc.lower())
.iter()
.cloned()
.map(|wc| wc.map_bound(|goal| goal.into_well_formed_goal()))
);

@@ -338,7 +341,10 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
let trait_pred = ty::TraitPredicate { trait_ref }.lower();

// `WC`
let where_clauses = tcx.predicates_of(def_id).predicates.lower();
let where_clauses = tcx.predicates_of(def_id).predicates
.into_iter()
.map(|(wc, _)| wc.lower())
.collect::<Vec<_>>();

// `Implemented(A0: Trait<A1..An>) :- WC`
let clause = ProgramClause {
@@ -370,7 +376,10 @@ pub fn program_clauses_for_type_def<'a, 'tcx>(
let ty = tcx.type_of(def_id);

// `WC`
let where_clauses = tcx.predicates_of(def_id).predicates.lower();
let where_clauses = tcx.predicates_of(def_id).predicates
.into_iter()
.map(|(wc, _)| wc.lower())
.collect::<Vec<_>>();

// `WellFormed(Ty<...>) :- WC1, ..., WCm`
let well_formed = ProgramClause {
Loading