Skip to content

Commit

Permalink
Fix binding levels in implied bounds rules
Browse files Browse the repository at this point in the history
  • Loading branch information
scalexm committed Dec 27, 2018
1 parent c0d7803 commit ea4187a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/librustc_traits/lowering/mod.rs
Expand Up @@ -211,7 +211,6 @@ fn program_clauses_for_trait<'a, 'tcx>(
let where_clauses = &predicates
.iter()
.map(|(wc, _)| wc.lower())
.map(|wc| wc.subst(tcx, bound_vars))
.collect::<Vec<_>>();

// Rule Implied-Bound-From-Trait
Expand All @@ -232,14 +231,13 @@ fn program_clauses_for_trait<'a, 'tcx>(
.map(|wc| {
// we move binders to the left
wc.map_bound(|goal| ProgramClause {
goal: goal.into_from_env_goal(),

// FIXME: As where clauses can only bind lifetimes for now,
// and that named bound regions have a def-id, it is safe
// to just inject `hypotheses` (which contains named vars bound at index `0`)
// into this binding level. This may change if we ever allow where clauses
// to bind types (e.g., for GATs things), because bound types only use a `BoundVar`
// FIXME: As where clauses can only bind lifetimes for now, and that named
// bound regions have a def-id, it is safe to just inject `bound_vars` and
// `hypotheses` (which contain named vars bound at index `0`) into this
// binding level. This may change if we ever allow where clauses to bind
// types (e.g. for GATs things), because bound types only use a `BoundVar`
// index (no def-id).
goal: goal.subst(tcx, bound_vars).into_from_env_goal(),
hypotheses,

category: ProgramClauseCategory::ImpliedBound,
Expand Down Expand Up @@ -346,7 +344,6 @@ pub fn program_clauses_for_type_def<'a, 'tcx>(
let where_clauses = tcx.predicates_of(def_id).predicates
.iter()
.map(|(wc, _)| wc.lower())
.map(|wc| wc.subst(tcx, bound_vars))
.collect::<Vec<_>>();

// `WellFormed(Ty<...>) :- WC1, ..., WCm`
Expand All @@ -355,7 +352,7 @@ pub fn program_clauses_for_type_def<'a, 'tcx>(
hypotheses: tcx.mk_goals(
where_clauses
.iter()
.cloned()
.map(|wc| wc.subst(tcx, bound_vars))
.map(|wc| tcx.mk_goal(GoalKind::from_poly_domain_goal(wc, tcx))),
),
category: ProgramClauseCategory::WellFormed,
Expand Down Expand Up @@ -383,11 +380,10 @@ pub fn program_clauses_for_type_def<'a, 'tcx>(
.map(|wc| {
// move the binders to the left
wc.map_bound(|goal| ProgramClause {
goal: goal.into_from_env_goal(),

// FIXME: we inject `hypotheses` into this binding level,
// which may be incorrect in the future: see the FIXME in
// `program_clauses_for_trait`
// FIXME: we inject `bound_vars` and `hypotheses` into this binding
// level, which may be incorrect in the future: see the FIXME in
// `program_clauses_for_trait`.
goal: goal.subst(tcx, bound_vars).into_from_env_goal(),
hypotheses,

category: ProgramClauseCategory::ImpliedBound,
Expand Down

0 comments on commit ea4187a

Please sign in to comment.