Skip to content

Commit

Permalink
Use a dummy outlives requirement for where Type:, (see rust-lang#53696
Browse files Browse the repository at this point in the history
)

A `WF(Type)` predicate was used previously, which did not play
well with implied bounds in chalk.
  • Loading branch information
scalexm committed Nov 13, 2018
1 parent 156a932 commit 79b6c41
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/librustc_traits/lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ impl<'tcx> Lower<PolyDomainGoal<'tcx>> for ty::Predicate<'tcx> {
Predicate::RegionOutlives(predicate) => predicate.lower(),
Predicate::TypeOutlives(predicate) => predicate.lower(),
Predicate::Projection(predicate) => predicate.lower(),
Predicate::WellFormed(ty) => {
ty::Binder::dummy(DomainGoal::WellFormed(WellFormed::Ty(*ty)))

Predicate::WellFormed(..) |
Predicate::ObjectSafe(..) |
Predicate::ClosureKind(..) |
Predicate::Subtype(..) |
Predicate::ConstEvaluatable(..) => {
bug!("unexpected predicate {}", self)
}
Predicate::ObjectSafe(..)
| Predicate::ClosureKind(..)
| Predicate::Subtype(..)
| Predicate::ConstEvaluatable(..) => unimplemented!(),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,8 +1857,9 @@ fn explicit_predicates_of<'a, 'tcx>(
&hir::WherePredicate::BoundPredicate(ref bound_pred) => {
let ty = icx.to_ty(&bound_pred.bounded_ty);

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

Expand Down
13 changes: 4 additions & 9 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,15 +1325,10 @@ impl<'a> Clean<WherePredicate> for ty::Predicate<'a> {
Predicate::RegionOutlives(ref pred) => pred.clean(cx),
Predicate::TypeOutlives(ref pred) => pred.clean(cx),
Predicate::Projection(ref pred) => pred.clean(cx),
Predicate::WellFormed(ty) => {
// This comes from `where Ty:` (i.e. no bounds) (see #53696).
WherePredicate::BoundPredicate {
ty: ty.clean(cx),
bounds: vec![],
}
}
Predicate::ObjectSafe(_) => panic!("not user writable"),
Predicate::ClosureKind(..) => panic!("not user writable"),

Predicate::WellFormed(..) |
Predicate::ObjectSafe(..) |
Predicate::ClosureKind(..) |
Predicate::ConstEvaluatable(..) => panic!("not user writable"),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/chalkify/lower_trait_where_clause.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
= note: forall<'a, 'b, Self, T, U> { Implemented(Self: Foo<'a, 'b, T, U>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
= note: forall<'a, 'b, Self, T, U> { RegionOutlives('a: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
= note: forall<'a, 'b, Self, T, U> { TypeOutlives(U: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
= 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>). }
= note: forall<'a, 'b, Self, T, U> { WellFormed(std::boxed::Box<T>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
= note: forall<'a, 'b, Self, T, U> { TypeOutlives(std::boxed::Box<T>: '<empty>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
= 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>). }

error: aborting due to previous error

0 comments on commit 79b6c41

Please sign in to comment.