From 709b9246434944f5eb7c626d43dbaf6cea00e531 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Mon, 17 Jun 2019 23:41:20 +0100 Subject: [PATCH] Ensure `type_param_predicates` fn only returns predicates for type param with given def-ID. --- src/librustc/ty/mod.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/collect.rs | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index c6aadc598b7e..1eda57608e75 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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>, /// Typically, this is `Reveal::UserFacing`, but during codegen we /// want `Reveal::All` -- note that this is always paired with an diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 64c0011a7b39..881f66afc91d 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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). } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 4056d6f974c5..357dcd878f51 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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) }