From 11adc1300cbff4970f97f9f647ab51bb0db872df Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 23 Jun 2018 00:21:35 +0100 Subject: [PATCH] Address minor comments --- src/librustc/ty/mod.rs | 2 +- src/librustc/ty/subst.rs | 1 - src/librustc_lint/types.rs | 8 -------- src/librustc_passes/ast_validation.rs | 5 +---- src/librustc_privacy/lib.rs | 13 +++++-------- src/librustc_resolve/lib.rs | 9 +++++---- 6 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 6c27d527ae89..4479c7239df5 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -931,7 +931,7 @@ impl<'a, 'gcx, 'tcx> Generics { pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool { for param in &self.params { match param.kind { - GenericParamDefKind::Type {..} => return true, + GenericParamDefKind::Type { .. } => return true, GenericParamDefKind::Lifetime => {} } } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 2e3c6df9754d..a6ff979f472a 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -231,7 +231,6 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { mk_kind: &mut F) where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx> { - if let Some(def_id) = defs.parent { let parent_defs = tcx.generics_of(def_id); Substs::fill_item(substs, tcx, parent_defs, mk_kind); diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index f1636c4dcb08..2a30aeb6a39d 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -819,14 +819,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { if let hir::ItemKind::Enum(ref enum_definition, _) = it.node { let item_def_id = cx.tcx.hir.local_def_id(it.id); - let generics = cx.tcx.generics_of(item_def_id); - for param in &generics.params { - match param.kind { - ty::GenericParamDefKind::Lifetime { .. } => {}, - ty::GenericParamDefKind::Type { .. } => return, - } - } - // Sizes only make sense for non-generic types. let t = cx.tcx.type_of(item_def_id); let ty = cx.tcx.erase_regions(&t); match cx.layout_of(ty) { diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 0ea90e745319..110797a59cb7 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -539,10 +539,7 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> { fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) { match *generic_args { GenericArgs::AngleBracketed(ref data) => { - data.args.iter().for_each(|arg| match arg { - GenericArg::Type(ty) => self.visit_ty(ty), - _ => {} - }); + data.args.iter().for_each(|arg| self.visit_generic_arg(arg)); for type_binding in &data.bindings { // Type bindings such as `Item=impl Debug` in `Iterator` // are allowed to contain nested `impl Trait`. diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index fcb1b65014be..d9c3fc221dce 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -23,7 +23,7 @@ extern crate rustc_typeck; extern crate syntax_pos; extern crate rustc_data_structures; -use rustc::hir::{self, GenericParamKind, PatKind}; +use rustc::hir::{self, PatKind}; use rustc::hir::def::Def; use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId}; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; @@ -1270,14 +1270,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn visit_generics(&mut self, generics: &'tcx hir::Generics) { - generics.params.iter().for_each(|param| match param.kind { - GenericParamKind::Lifetime { .. } => {} - GenericParamKind::Type { .. } => { - for bound in ¶m.bounds { - self.check_generic_bound(bound); - } + for param in &generics.params { + for bound in ¶m.bounds { + self.check_generic_bound(bound); } - }); + } for predicate in &generics.where_clause.predicates { match predicate { &hir::WherePredicate::BoundPredicate(ref bound_pred) => { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2e163cb4c6a3..83d068a3df80 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -822,11 +822,12 @@ impl<'a, 'tcx, 'cl> Visitor<'tcx> for Resolver<'a, 'cl> { .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => None, GenericParamKind::Type { ref default, .. } => { - if found_default || default.is_some() { - found_default = true; - return Some((Ident::with_empty_ctxt(param.ident.name), Def::Err)); + found_default |= default.is_some(); + if found_default { + Some((Ident::with_empty_ctxt(param.ident.name), Def::Err)); + } else { + None } - None } }));