Skip to content

Commit de47558

Browse files
committed
Stop duplicating where clauses from impl's.
1 parent ecd4197 commit de47558

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
@@ -251,16 +251,15 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
251251
// Rule Normalize-From-Impl (see rustc guide)
252252
//
253253
// ```impl<P0..Pn> Trait<A1..An> for A0
254-
// where WC
255254
// {
256-
// type AssocType<Pn+1..Pm> where WC1 = T;
255+
// type AssocType<Pn+1..Pm> where WC = T;
257256
// }```
258257
//
259258
// ```
260259
// forall<P0..Pm> {
261260
// forall<Pn+1..Pm> {
262261
// Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T) :-
263-
// WC && WC1
262+
// Implemented(A0: Trait<A1..An>) && WC
264263
// }
265264
// }
266265
// ```
@@ -276,19 +275,18 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
276275
let trait_ref = tcx.impl_trait_ref(impl_id).unwrap();
277276
// `T`
278277
let ty = tcx.type_of(item_id);
278+
// `Implemented(A0: Trait<A1..An>)`
279+
let trait_implemented = ty::Binder::dummy(ty::TraitPredicate { trait_ref }.lower());
279280
// `WC`
280-
let impl_where_clauses = tcx.predicates_of(impl_id).predicates.lower();
281-
// `WC1`
282281
let item_where_clauses = tcx.predicates_of(item_id).predicates.lower();
283-
// `WC && WC1`
284-
let mut where_clauses = vec![];
285-
where_clauses.extend(impl_where_clauses);
282+
// `Implemented(A0: Trait<A1..An>) && WC`
283+
let mut where_clauses = vec![trait_implemented];
286284
where_clauses.extend(item_where_clauses);
287285
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
288286
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name);
289287
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
290288
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });
291-
// `Normalize(... -> T) :- WC && WC1`
289+
// `Normalize(... -> T) :- ...`
292290
let clause = ProgramClause {
293291
goal: normalize_goal,
294292
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)