Skip to content

Commit 79b6c41

Browse files
committed
Use a dummy outlives requirement for where Type:, (see rust-lang#53696)
A `WF(Type)` predicate was used previously, which did not play well with implied bounds in chalk.
1 parent 156a932 commit 79b6c41

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/librustc_traits/lowering/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ impl<'tcx> Lower<PolyDomainGoal<'tcx>> for ty::Predicate<'tcx> {
113113
Predicate::RegionOutlives(predicate) => predicate.lower(),
114114
Predicate::TypeOutlives(predicate) => predicate.lower(),
115115
Predicate::Projection(predicate) => predicate.lower(),
116-
Predicate::WellFormed(ty) => {
117-
ty::Binder::dummy(DomainGoal::WellFormed(WellFormed::Ty(*ty)))
116+
117+
Predicate::WellFormed(..) |
118+
Predicate::ObjectSafe(..) |
119+
Predicate::ClosureKind(..) |
120+
Predicate::Subtype(..) |
121+
Predicate::ConstEvaluatable(..) => {
122+
bug!("unexpected predicate {}", self)
118123
}
119-
Predicate::ObjectSafe(..)
120-
| Predicate::ClosureKind(..)
121-
| Predicate::Subtype(..)
122-
| Predicate::ConstEvaluatable(..) => unimplemented!(),
123124
}
124125
}
125126
}

src/librustc_typeck/collect.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1857,8 +1857,9 @@ fn explicit_predicates_of<'a, 'tcx>(
18571857
&hir::WherePredicate::BoundPredicate(ref bound_pred) => {
18581858
let ty = icx.to_ty(&bound_pred.bounded_ty);
18591859

1860-
// Keep the type around in a WF predicate, in case of no bounds.
1861-
// That way, `where Ty:` is not a complete noop (see #53696).
1860+
// Keep the type around in a dummy predicate, in case of no bounds.
1861+
// That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
1862+
// is still checked for WF.
18621863
if bound_pred.bounds.is_empty() {
18631864
if let ty::Param(_) = ty.sty {
18641865
// This is a `where T:`, which can be in the HIR from the
@@ -1869,7 +1870,10 @@ fn explicit_predicates_of<'a, 'tcx>(
18691870
// compiler/tooling bugs from not handling WF predicates.
18701871
} else {
18711872
let span = bound_pred.bounded_ty.span;
1872-
predicates.push((ty::Predicate::WellFormed(ty), span));
1873+
let predicate = ty::OutlivesPredicate(ty, tcx.mk_region(ty::ReEmpty));
1874+
predicates.push(
1875+
(ty::Predicate::TypeOutlives(ty::Binder::dummy(predicate)), span)
1876+
);
18731877
}
18741878
}
18751879

src/librustdoc/clean/mod.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1325,15 +1325,10 @@ impl<'a> Clean<WherePredicate> for ty::Predicate<'a> {
13251325
Predicate::RegionOutlives(ref pred) => pred.clean(cx),
13261326
Predicate::TypeOutlives(ref pred) => pred.clean(cx),
13271327
Predicate::Projection(ref pred) => pred.clean(cx),
1328-
Predicate::WellFormed(ty) => {
1329-
// This comes from `where Ty:` (i.e. no bounds) (see #53696).
1330-
WherePredicate::BoundPredicate {
1331-
ty: ty.clean(cx),
1332-
bounds: vec![],
1333-
}
1334-
}
1335-
Predicate::ObjectSafe(_) => panic!("not user writable"),
1336-
Predicate::ClosureKind(..) => panic!("not user writable"),
1328+
1329+
Predicate::WellFormed(..) |
1330+
Predicate::ObjectSafe(..) |
1331+
Predicate::ClosureKind(..) |
13371332
Predicate::ConstEvaluatable(..) => panic!("not user writable"),
13381333
}
13391334
}

src/test/ui/chalkify/lower_trait_where_clause.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
88
= note: forall<'a, 'b, Self, T, U> { Implemented(Self: Foo<'a, 'b, T, U>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
99
= note: forall<'a, 'b, Self, T, U> { RegionOutlives('a: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
1010
= note: forall<'a, 'b, Self, T, U> { TypeOutlives(U: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
11-
= note: forall<'a, 'b, Self, T, U> { WellFormed(Self: Foo<'a, 'b, T, U>) :- Implemented(Self: Foo<'a, 'b, T, U>), WellFormed(T: std::borrow::Borrow<U>), TypeOutlives(U: 'b), RegionOutlives('a: 'b), WellFormed(std::boxed::Box<T>). }
12-
= note: forall<'a, 'b, Self, T, U> { WellFormed(std::boxed::Box<T>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
11+
= note: forall<'a, 'b, Self, T, U> { TypeOutlives(std::boxed::Box<T>: '<empty>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
12+
= note: forall<'a, 'b, Self, T, U> { WellFormed(Self: Foo<'a, 'b, T, U>) :- Implemented(Self: Foo<'a, 'b, T, U>), WellFormed(T: std::borrow::Borrow<U>), TypeOutlives(U: 'b), RegionOutlives('a: 'b), TypeOutlives(std::boxed::Box<T>: '<empty>). }
1313

1414
error: aborting due to previous error
1515

0 commit comments

Comments
 (0)