diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 68ceb39d575d..67afe5891299 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -324,7 +324,10 @@ impl<'a> LoweringContext<'a> { let count = generics .params .iter() - .filter(|param| param.is_lifetime_param()) + .filter(|param| match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => true, + _ => false, + }) .count(); self.lctx.type_def_lifetime_params.insert(def_id, count); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index d7ebd40f49b4..9a1dfbd931a3 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -294,7 +294,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => { if is_auto == IsAuto::Yes { // Auto traits cannot have generics, super traits nor contain items. - if generics.is_parameterized() { + if !generics.params.is_empty() { struct_span_err!(self.session, item.span, E0567, "auto traits cannot have generic parameters").emit(); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c354edc5aaff..715e4d233dfb 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -342,22 +342,6 @@ pub struct GenericParamAST { pub kind: GenericParamKindAST, } -impl GenericParamAST { - pub fn is_lifetime_param(&self) -> bool { - match self.kind { - GenericParamKindAST::Lifetime { .. } => true, - _ => false, - } - } - - pub fn is_type_param(&self) -> bool { - match self.kind { - GenericParamKindAST::Type { .. } => true, - _ => false, - } - } -} - /// Represents lifetime, type and const parameters attached to a declaration of /// a function, enum, trait, etc. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -367,29 +351,6 @@ pub struct Generics { pub span: Span, } -impl Generics { - pub fn is_lt_parameterized(&self) -> bool { - self.params.iter().any(|param| param.is_lifetime_param()) - } - - pub fn is_type_parameterized(&self) -> bool { - self.params.iter().any(|param| param.is_type_param()) - } - - pub fn is_parameterized(&self) -> bool { - !self.params.is_empty() - } - - pub fn span_for_name(&self, name: &str) -> Option { - for param in &self.params { - if param.ident.name == name { - return Some(param.ident.span); - } - } - None - } -} - impl Default for Generics { /// Creates an instance of `Generics`. fn default() -> Generics { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a2ea6a214841..be4cf197be4e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1797,7 +1797,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { gate_feature_post!(&self, associated_type_defaults, ti.span, "associated type defaults are unstable"); } - if ti.generics.is_parameterized() { + if !ti.generics.params.is_empty() { gate_feature_post!(&self, generic_associated_types, ti.span, "generic associated types are unstable"); } @@ -1824,7 +1824,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { gate_feature_post!(&self, const_fn, ii.span, "const fn is unstable"); } } - ast::ImplItemKind::Type(_) if ii.generics.is_parameterized() => { + ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => { gate_feature_post!(&self, generic_associated_types, ii.span, "generic associated types are unstable"); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1626135400de..458947299c81 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1329,7 +1329,7 @@ impl<'a> State<'a> { self.print_unsafety(unsafety)?; self.word_nbsp("impl")?; - if generics.is_parameterized() { + if !generics.params.is_empty() { self.print_generic_params(&generics.params)?; self.s.space()?; } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index da7deb3c4cfe..f896fa351b0a 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -353,7 +353,7 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { match (has_output, has_should_panic_attr) { (true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs), - (true, false) => if generics.is_parameterized() { + (true, false) => if !generics.params.is_empty() { No(BadTestSignature::WrongTypeSignature) } else { Yes diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 40d49b499604..5f943a4cd00d 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -49,7 +49,10 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, ItemKind::Struct(_, Generics { ref params, .. }) | ItemKind::Enum(_, Generics { ref params, .. }) => { if attr::contains_name(&annitem.attrs, "rustc_copy_clone_marker") && - !params.iter().any(|param| param.is_type_param()) + !params.iter().any(|param| match param.kind { + ast::GenericParamKindAST::Type { .. } => true, + _ => false, + }) { bounds = vec![]; is_shallow = true; diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index cbf7b1e08761..e461c9640d1a 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -422,7 +422,10 @@ impl<'a> TraitDef<'a> { ast::ItemKind::Struct(_, ref generics) | ast::ItemKind::Enum(_, ref generics) | ast::ItemKind::Union(_, ref generics) => { - !generics.params.iter().any(|p| p.is_type_param()) + !generics.params.iter().any(|param| match param.kind { + ast::GenericParamKindAST::Type { .. } => true, + _ => false, + }) } _ => { // Non-ADT derive is an error, but it should have been