From 469c3bf75b5768611f65c65c3bbafab3c315dcdf Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Thu, 1 Nov 2018 02:00:32 +0000 Subject: [PATCH] Resolve nits brought up in review. --- src/librustc_typeck/collect.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 21a1abd97a5a..9ffbe1a68b87 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -58,6 +58,8 @@ use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs, Unsafety}; use std::iter; +struct OnlySelfBounds(bool); + /////////////////////////////////////////////////////////////////////////// // Main entry point @@ -331,7 +333,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { ast_generics: &hir::Generics, param_id: ast::NodeId, ty: Ty<'tcx>, - only_self_bounds: bool, + only_self_bounds: OnlySelfBounds, ) -> Vec<(ty::Predicate<'tcx>, Span)> { let from_ty_params = ast_generics .params @@ -354,12 +356,10 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { .flat_map(|bp| { let bt = if is_param(self.tcx, &bp.bounded_ty, param_id) { Some(ty) + } else if only_self_bounds.0 { + None } else { - if only_self_bounds { - None - } else { - Some(self.to_ty(&bp.bounded_ty)) - } + Some(self.to_ty(&bp.bounded_ty)) }; bp.bounds.iter().filter_map(move |b| { if let Some(bt) = bt { Some((bt, b)) } else { None } @@ -710,7 +710,10 @@ fn super_predicates_of<'a, 'tcx>( let superbounds1 = superbounds1.predicates(tcx, self_param_ty); // Convert any explicit superbounds in the where clause, - // e.g. `trait Foo where Self : Bar`: + // e.g. `trait Foo where Self : Bar`. + // In the case of trait aliases, however, we include all bounds in the where clause, + // so e.g. `trait Foo = where u32: PartialEq` would include `u32: PartialEq` + // as one of its "superpredicates". let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id); let superbounds2 = icx.type_parameter_bounds_in_generics( generics, item.id, self_param_ty, !is_trait_alias);