Skip to content

Commit b914418

Browse files
committed
WIP: Remove Self:Trait from predicates_of
1 parent 7d8f0e2 commit b914418

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

src/librustc/infer/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
750750
-> UnitResult<'tcx>
751751
where T: at::ToTrace<'tcx>
752752
{
753+
debug!("can_sub({:?}, {:?})", a, b);
753754
let origin = &ObligationCause::dummy();
754-
self.probe(|_| {
755+
let result = self.probe(|_| {
755756
self.at(origin, param_env).sub(a, b).map(|InferOk { obligations: _, .. }| {
756757
// Ignore obligations, since we are unrolling
757758
// everything anyway.
758759
})
759-
})
760+
});
761+
debug!("can_sub({:?}, {:?}) returning {:?}", a, b, result);
762+
result
760763
}
761764

762765
pub fn can_eq<T>(&self,
@@ -766,13 +769,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
766769
-> UnitResult<'tcx>
767770
where T: at::ToTrace<'tcx>
768771
{
772+
debug!("can_eq({:?}, {:?})", a, b);
769773
let origin = &ObligationCause::dummy();
770-
self.probe(|_| {
774+
let result = self.probe(|_| {
771775
self.at(origin, param_env).eq(a, b).map(|InferOk { obligations: _, .. }| {
772776
// Ignore obligations, since we are unrolling
773777
// everything anyway.
774778
})
775-
})
779+
});
780+
debug!("can_eq({:?}, {:?}) returning {:?}", a, b, result);
781+
result
776782
}
777783

778784
pub fn sub_regions(&self,

src/librustc/traits/select.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,9 +1934,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19341934
// attempt to evaluate recursive bounds to see if they are
19351935
// satisfied.
19361936

1937-
/// Returns true if `candidate_i` should be dropped in favor of
1938-
/// `candidate_j`. Generally speaking we will drop duplicate
1939-
/// candidates and prefer where-clause candidates.
19401937
/// Returns true if `victim` should be dropped in favor of
19411938
/// `other`. Generally speaking we will drop duplicate
19421939
/// candidates and prefer where-clause candidates.

src/librustc/ty/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27182718
// Compute the bounds on Self and the type parameters.
27192719

27202720
let bounds = tcx.predicates_of(def_id).instantiate_identity(tcx);
2721-
let predicates = bounds.predicates;
2721+
let mut predicates = bounds.predicates;
27222722

27232723
// Finally, we have to normalize the bounds in the environment, in
27242724
// case they contain any associated type projections. This process
@@ -2732,6 +2732,22 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27322732
// are any errors at that point, so after type checking you can be
27332733
// sure that this will succeed without errors anyway.
27342734

2735+
let id = tcx.hir.as_local_node_id(def_id).unwrap();
2736+
debug!("param_env: handling def_id={:?}, id={:?}", def_id, id);
2737+
2738+
if let Some(hir::map::NodeItem(item)) = tcx.hir.find(id) {
2739+
debug!(" param_env: self node: {:?}", item.node);
2740+
if let hir::ItemTrait(..) = item.node {
2741+
debug!(" param_env: self is trait!");
2742+
let trait_ref = ty::TraitRef {
2743+
def_id: def_id,
2744+
substs: Substs::identity_for_item(tcx, def_id)
2745+
};
2746+
predicates.push(trait_ref.to_poly_trait_ref().to_predicate());
2747+
}
2748+
}
2749+
debug!(" param_env predicates: {:?}", predicates);
2750+
27352751
let unnormalized_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates),
27362752
traits::Reveal::UserFacing);
27372753

src/librustc_typeck/check/compare_method.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use super::{Inherited, FnCtxt};
3030
/// - impl_m_span: span to use for reporting errors
3131
/// - trait_m: the method in the trait
3232
/// - impl_trait_ref: the TraitRef corresponding to the trait implementation
33-
3433
pub fn compare_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
3534
impl_m: &ty::AssociatedItem,
3635
impl_m_span: Span,

src/librustc_typeck/collect.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,17 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13211321
let node = tcx.hir.get(node_id);
13221322

13231323
let mut is_trait = None;
1324+
let mut is_trait_item = None;
13241325
let mut is_default_impl_trait = None;
13251326

13261327
let icx = ItemCtxt::new(tcx, def_id);
13271328
let no_generics = hir::Generics::empty();
13281329
let ast_generics = match node {
1329-
NodeTraitItem(item) => &item.generics,
1330+
NodeTraitItem(item) => {
1331+
is_trait_item = Some(());
1332+
&item.generics
1333+
}
1334+
13301335
NodeImplItem(item) => &item.generics,
13311336

13321337
NodeItem(item) => {
@@ -1401,13 +1406,37 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
14011406
// and the explicit where-clauses, but to get the full set of predicates
14021407
// on a trait we need to add in the supertrait bounds and bounds found on
14031408
// associated types.
1404-
if let Some((trait_ref, _)) = is_trait {
1409+
if let Some((_trait_ref, _)) = is_trait {
14051410
predicates = tcx.super_predicates_of(def_id).predicates;
14061411

14071412
// Add in a predicate that `Self:Trait` (where `Trait` is the
14081413
// current trait). This is needed for builtin bounds.
1409-
predicates.push(trait_ref.to_poly_trait_ref().to_predicate());
1414+
//predicates.push(trait_ref.to_poly_trait_ref().to_predicate());
1415+
}
1416+
1417+
if let Some(()) = is_trait_item {
1418+
let id = tcx.hir.as_local_node_id(def_id).unwrap();
1419+
debug!("explicit_predicates_of: handling def_id={:?}, id={:?}", def_id, id);
1420+
1421+
let parent_id = tcx.hir.get_parent(id);
1422+
let parent_def_id = tcx.hir.local_def_id(parent_id);
1423+
if let Some(hir::map::NodeItem(parent_item)) = tcx.hir.find(parent_id) {
1424+
debug!(" explicit_predicates_of: has parent, node: {:?}", parent_item.node);
1425+
if let hir::ItemTrait(..) = parent_item.node {
1426+
debug!(" explicit_predicates_of: parent is trait!");
1427+
let trait_ref = ty::TraitRef {
1428+
def_id: parent_def_id,
1429+
substs: Substs::identity_for_item(tcx, parent_def_id)
1430+
};
1431+
predicates.push(trait_ref.to_poly_trait_ref().to_predicate());
1432+
} else {
1433+
debug!(" explicit_predicates_of: parent is not trait :((");
1434+
}
1435+
} else {
1436+
debug!(" explicit_predicates_of: no parent :(");
1437+
}
14101438
}
1439+
debug!("explicit_predicates_of: predicates={:?}", predicates);
14111440

14121441
// In default impls, we can assume that the self type implements
14131442
// the trait. So in:

0 commit comments

Comments
 (0)