Stop duplicating where clauses from impl's.

This commit is contained in:
Fabian Zaiser 2018-04-11 21:20:25 +02:00
parent ecd41976fc
commit de475582c4
2 changed files with 8 additions and 10 deletions

View file

@ -251,16 +251,15 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
// Rule Normalize-From-Impl (see rustc guide)
//
// ```impl<P0..Pn> Trait<A1..An> for A0
// where WC
// {
// type AssocType<Pn+1..Pm> where WC1 = T;
// type AssocType<Pn+1..Pm> where WC = T;
// }```
//
// ```
// forall<P0..Pm> {
// forall<Pn+1..Pm> {
// Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T) :-
// WC && WC1
// Implemented(A0: Trait<A1..An>) && WC
// }
// }
// ```
@ -276,19 +275,18 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
let trait_ref = tcx.impl_trait_ref(impl_id).unwrap();
// `T`
let ty = tcx.type_of(item_id);
// `Implemented(A0: Trait<A1..An>)`
let trait_implemented = ty::Binder::dummy(ty::TraitPredicate { trait_ref }.lower());
// `WC`
let impl_where_clauses = tcx.predicates_of(impl_id).predicates.lower();
// `WC1`
let item_where_clauses = tcx.predicates_of(item_id).predicates.lower();
// `WC && WC1`
let mut where_clauses = vec![];
where_clauses.extend(impl_where_clauses);
// `Implemented(A0: Trait<A1..An>) && WC`
let mut where_clauses = vec![trait_implemented];
where_clauses.extend(item_where_clauses);
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name);
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });
// `Normalize(... -> T) :- WC && WC1`
// `Normalize(... -> T) :- ...`
let clause = ProgramClause {
goal: normalize_goal,
hypotheses: where_clauses.into_iter().map(|wc| wc.into()).collect(),

View file

@ -4,7 +4,7 @@ error: Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(T: Foo) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized).
error: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- Implemented(T: Bar).
--> $DIR/lower_impl.rs:23:5
|
LL | #[rustc_dump_program_clauses] //~ ERROR Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :-