Ensure type_param_predicates fn only returns predicates for type param with given def-ID.

This commit is contained in:
Alexander Regueiro 2019-06-17 23:41:20 +01:00
parent 3d9d36b3ff
commit 709b924643
3 changed files with 12 additions and 6 deletions

View file

@ -1649,7 +1649,7 @@ pub struct ParamEnv<'tcx> {
/// `Obligation`s that the caller must satisfy. This is basically
/// the set of bounds on the in-scope type parameters, translated
/// into `Obligation`s, and elaborated and normalized.
pub caller_bounds: &'tcx List<(ty::Predicate<'tcx>, Span)>,
pub caller_bounds: &'tcx List<ty::Predicate<'tcx>>,
/// Typically, this is `Reveal::UserFacing`, but during codegen we
/// want `Reveal::All` -- note that this is always paired with an

View file

@ -806,7 +806,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
binding,
bounds,
speculative,
&mut dup_bindings
&mut dup_bindings,
);
// Okay to ignore `Err` because of `ErrorReported` (see above).
}

View file

@ -322,9 +322,16 @@ fn type_param_predicates(
let icx = ItemCtxt::new(tcx, item_def_id);
let mut result = (*result).clone();
result.predicates.extend(extend.into_iter());
result.predicates
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
OnlySelfBounds(true)));
result.predicates.extend(
icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
.into_iter()
.filter(|(predicate, _)| {
match predicate {
ty::Predicate::Trait(ref data) => data.skip_binder().self_ty().is_param(index),
_ => false,
}
})
);
tcx.arena.alloc(result)
}
@ -2300,7 +2307,6 @@ fn predicates_from_bound<'tcx>(
tr,
param_ty,
&mut bounds,
false,
);
bounds.predicates(astconv.tcx(), param_ty)
}