Skip to content

Commit 2ef8493

Browse files
committed
Stop duplicating where clauses from impl's.
1 parent 7e50039 commit 2ef8493

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/librustc_traits/lowering.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,15 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
247247
// Rule Normalize-From-Impl (see rustc guide)
248248
//
249249
// ```impl<P0..Pn> Trait<A1..An> for A0
250-
// where WC
251250
// {
252-
// type AssocType<Pn+1..Pm> where WC1 = T;
251+
// type AssocType<Pn+1..Pm> where WC = T;
253252
// }```
254253
//
255254
// ```
256255
// forall<P0..Pm> {
257256
// forall<Pn+1..Pm> {
258257
// Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T) :-
259-
// WC && WC1
258+
// Implemented(A0: Trait<A1..An>) && WC
260259
// }
261260
// }
262261
// ```
@@ -272,19 +271,18 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
272271
let trait_ref = tcx.impl_trait_ref(impl_id).unwrap();
273272
// `T`
274273
let ty = tcx.type_of(item_id);
274+
// `Implemented(A0: Trait<A1..An>)`
275+
let trait_implemented = ty::Binder::dummy(ty::TraitPredicate { trait_ref }.lower());
275276
// `WC`
276-
let impl_where_clauses = tcx.predicates_of(impl_id).predicates.lower();
277-
// `WC1`
278277
let item_where_clauses = tcx.predicates_of(item_id).predicates.lower();
279-
// `WC && WC1`
280-
let mut where_clauses = vec![];
281-
where_clauses.extend(impl_where_clauses);
278+
// `Implemented(A0: Trait<A1..An>) && WC`
279+
let mut where_clauses = vec![trait_implemented];
282280
where_clauses.extend(item_where_clauses);
283281
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
284282
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name);
285283
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
286284
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });
287-
// `Normalize(... -> T) :- WC && WC1`
285+
// `Normalize(... -> T) :- ...`
288286
let clause = ProgramClause {
289287
goal: normalize_goal,
290288
hypotheses: where_clauses.into_iter().map(|wc| wc.into()).collect(),

src/test/ui/chalkify/lower_impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i
44
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(T: Foo) :-
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
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).
7+
error: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- Implemented(T: Bar).
88
--> $DIR/lower_impl.rs:23:5
99
|
1010
LL | #[rustc_dump_program_clauses] //~ ERROR Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :-

0 commit comments

Comments
 (0)