Skip to content

Commit d6a2b7c

Browse files
committed
Fix a bug in implied bounds
1 parent 4effdd2 commit d6a2b7c

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

src/librustc_traits/lowering/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub fn program_clauses_for_type_def<'a, 'tcx>(
337337
//
338338
// ```
339339
// forall<P1..Pn> {
340-
// WellFormed(Ty<...>) :- WC1, ..., WCm`
340+
// WellFormed(Ty<...>) :- WellFormed(WC1), ..., WellFormed(WCm)`
341341
// }
342342
// ```
343343

@@ -354,13 +354,14 @@ pub fn program_clauses_for_type_def<'a, 'tcx>(
354354
.map(|(wc, _)| wc.lower())
355355
.collect::<Vec<_>>();
356356

357-
// `WellFormed(Ty<...>) :- WC1, ..., WCm`
357+
// `WellFormed(Ty<...>) :- WellFormed(WC1), ..., WellFormed(WCm)`
358358
let well_formed_clause = ProgramClause {
359359
goal: DomainGoal::WellFormed(WellFormed::Ty(ty)),
360360
hypotheses: tcx.mk_goals(
361361
where_clauses
362362
.iter()
363363
.map(|wc| wc.subst(tcx, bound_vars))
364+
.map(|wc| wc.map_bound(|bound| bound.into_well_formed_goal()))
364365
.map(|wc| tcx.mk_goal(GoalKind::from_poly_domain_goal(wc, tcx))),
365366
),
366367
category: ProgramClauseCategory::WellFormed,
@@ -457,13 +458,13 @@ pub fn program_clauses_for_associated_type_def<'a, 'tcx>(
457458
// ```
458459
// forall<Self, P1..Pn, Pn+1..Pm> {
459460
// WellFormed((Trait::AssocType)<Self, P1..Pn, Pn+1..Pm>)
460-
// :- Implemented(Self: Trait<P1..Pn>)
461+
// :- WellFormed(Self: Trait<P1..Pn>)
461462
// }
462463
// ```
463464

464465
let trait_predicate = ty::TraitPredicate { trait_ref };
465466
let hypothesis = tcx.mk_goal(
466-
DomainGoal::Holds(WhereClause::Implemented(trait_predicate)).into_goal()
467+
DomainGoal::WellFormed(WellFormed::Trait(trait_predicate)).into_goal()
467468
);
468469

469470
let wf_clause = ProgramClause {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// compile-flags: -Z chalk
2+
3+
#![feature(trivial_bounds)]
4+
5+
trait Bar {
6+
fn foo();
7+
}
8+
trait Foo: Bar { }
9+
10+
struct S where S: Foo;
11+
12+
impl Foo for S {
13+
}
14+
15+
fn bar<T: Bar>() {
16+
T::foo();
17+
}
18+
19+
fn foo<T: Foo>() {
20+
bar::<T>()
21+
}
22+
23+
fn main() {
24+
// For some reason, the error is duplicated...
25+
26+
foo::<S>() //~ ERROR the type `S` is not well-formed (chalk)
27+
//~^ ERROR the type `S` is not well-formed (chalk)
28+
}

src/test/ui/chalkify/lower_env2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #[rustc_dump_program_clauses]
66
|
77
= note: forall<'a, T> { FromEnv(T: Foo) :- FromEnv(S<'a, T>). }
88
= note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(S<'a, T>). }
9-
= note: forall<'a, T> { WellFormed(S<'a, T>) :- Implemented(T: Foo), TypeOutlives(T: 'a). }
9+
= note: forall<'a, T> { WellFormed(S<'a, T>) :- WellFormed(T: Foo), TypeOutlives(T: 'a). }
1010

1111
error: program clause dump
1212
--> $DIR/lower_env2.rs:11:1

src/test/ui/chalkify/lower_struct.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #[rustc_dump_program_clauses]
77
= note: forall<'a, T> { FromEnv(T: std::marker::Sized) :- FromEnv(Foo<'a, T>). }
88
= note: forall<'a, T> { FromEnv(std::boxed::Box<T>: std::clone::Clone) :- FromEnv(Foo<'a, T>). }
99
= note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(Foo<'a, T>). }
10-
= note: forall<'a, T> { WellFormed(Foo<'a, T>) :- Implemented(T: std::marker::Sized), Implemented(std::boxed::Box<T>: std::clone::Clone), TypeOutlives(T: 'a). }
10+
= note: forall<'a, T> { WellFormed(Foo<'a, T>) :- WellFormed(T: std::marker::Sized), WellFormed(std::boxed::Box<T>: std::clone::Clone), TypeOutlives(T: 'a). }
1111

1212
error: aborting due to previous error
1313

src/test/ui/chalkify/lower_trait.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | #[rustc_dump_program_clauses]
1818
= note: forall<Self, S, T, ^3> { ProjectionEq(<Self as Foo<S, T>>::Assoc == ^3) :- Normalize(<Self as Foo<S, T>>::Assoc -> ^3). }
1919
= note: forall<Self, S, T> { FromEnv(Self: Foo<S, T>) :- FromEnv(Unnormalized(<Self as Foo<S, T>>::Assoc)). }
2020
= note: forall<Self, S, T> { ProjectionEq(<Self as Foo<S, T>>::Assoc == Unnormalized(<Self as Foo<S, T>>::Assoc)). }
21-
= note: forall<Self, S, T> { WellFormed(Unnormalized(<Self as Foo<S, T>>::Assoc)) :- Implemented(Self: Foo<S, T>). }
21+
= note: forall<Self, S, T> { WellFormed(Unnormalized(<Self as Foo<S, T>>::Assoc)) :- WellFormed(Self: Foo<S, T>). }
2222

2323
error: aborting due to 2 previous errors
2424

0 commit comments

Comments
 (0)