Skip to content

Commit e1d888c

Browse files
committed
Remove methods from ast::GenericParam and ast::Generics
1 parent 2c6ff24 commit e1d888c

File tree

8 files changed

+17
-47
lines changed

8 files changed

+17
-47
lines changed

src/librustc/hir/lowering.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ impl<'a> LoweringContext<'a> {
324324
let count = generics
325325
.params
326326
.iter()
327-
.filter(|param| param.is_lifetime_param())
327+
.filter(|param| match param.kind {
328+
ast::GenericParamKindAST::Lifetime { .. } => true,
329+
_ => false,
330+
})
328331
.count();
329332
self.lctx.type_def_lifetime_params.insert(def_id, count);
330333
}

src/librustc_passes/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
294294
ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => {
295295
if is_auto == IsAuto::Yes {
296296
// Auto traits cannot have generics, super traits nor contain items.
297-
if generics.is_parameterized() {
297+
if !generics.params.is_empty() {
298298
struct_span_err!(self.session, item.span, E0567,
299299
"auto traits cannot have generic parameters").emit();
300300
}

src/libsyntax/ast.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,6 @@ pub struct GenericParamAST {
342342
pub kind: GenericParamKindAST,
343343
}
344344

345-
impl GenericParamAST {
346-
pub fn is_lifetime_param(&self) -> bool {
347-
match self.kind {
348-
GenericParamKindAST::Lifetime { .. } => true,
349-
_ => false,
350-
}
351-
}
352-
353-
pub fn is_type_param(&self) -> bool {
354-
match self.kind {
355-
GenericParamKindAST::Type { .. } => true,
356-
_ => false,
357-
}
358-
}
359-
}
360-
361345
/// Represents lifetime, type and const parameters attached to a declaration of
362346
/// a function, enum, trait, etc.
363347
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@@ -367,29 +351,6 @@ pub struct Generics {
367351
pub span: Span,
368352
}
369353

370-
impl Generics {
371-
pub fn is_lt_parameterized(&self) -> bool {
372-
self.params.iter().any(|param| param.is_lifetime_param())
373-
}
374-
375-
pub fn is_type_parameterized(&self) -> bool {
376-
self.params.iter().any(|param| param.is_type_param())
377-
}
378-
379-
pub fn is_parameterized(&self) -> bool {
380-
!self.params.is_empty()
381-
}
382-
383-
pub fn span_for_name(&self, name: &str) -> Option<Span> {
384-
for param in &self.params {
385-
if param.ident.name == name {
386-
return Some(param.ident.span);
387-
}
388-
}
389-
None
390-
}
391-
}
392-
393354
impl Default for Generics {
394355
/// Creates an instance of `Generics`.
395356
fn default() -> Generics {

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
17971797
gate_feature_post!(&self, associated_type_defaults, ti.span,
17981798
"associated type defaults are unstable");
17991799
}
1800-
if ti.generics.is_parameterized() {
1800+
if !ti.generics.params.is_empty() {
18011801
gate_feature_post!(&self, generic_associated_types, ti.span,
18021802
"generic associated types are unstable");
18031803
}
@@ -1824,7 +1824,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18241824
gate_feature_post!(&self, const_fn, ii.span, "const fn is unstable");
18251825
}
18261826
}
1827-
ast::ImplItemKind::Type(_) if ii.generics.is_parameterized() => {
1827+
ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => {
18281828
gate_feature_post!(&self, generic_associated_types, ii.span,
18291829
"generic associated types are unstable");
18301830
}

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ impl<'a> State<'a> {
13291329
self.print_unsafety(unsafety)?;
13301330
self.word_nbsp("impl")?;
13311331

1332-
if generics.is_parameterized() {
1332+
if !generics.params.is_empty() {
13331333
self.print_generic_params(&generics.params)?;
13341334
self.s.space()?;
13351335
}

src/libsyntax/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
353353

354354
match (has_output, has_should_panic_attr) {
355355
(true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs),
356-
(true, false) => if generics.is_parameterized() {
356+
(true, false) => if !generics.params.is_empty() {
357357
No(BadTestSignature::WrongTypeSignature)
358358
} else {
359359
Yes

src/libsyntax_ext/deriving/clone.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
4949
ItemKind::Struct(_, Generics { ref params, .. }) |
5050
ItemKind::Enum(_, Generics { ref params, .. }) => {
5151
if attr::contains_name(&annitem.attrs, "rustc_copy_clone_marker") &&
52-
!params.iter().any(|param| param.is_type_param())
52+
!params.iter().any(|param| match param.kind {
53+
ast::GenericParamKindAST::Type { .. } => true,
54+
_ => false,
55+
})
5356
{
5457
bounds = vec![];
5558
is_shallow = true;

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,10 @@ impl<'a> TraitDef<'a> {
422422
ast::ItemKind::Struct(_, ref generics) |
423423
ast::ItemKind::Enum(_, ref generics) |
424424
ast::ItemKind::Union(_, ref generics) => {
425-
!generics.params.iter().any(|p| p.is_type_param())
425+
!generics.params.iter().any(|param| match param.kind {
426+
ast::GenericParamKindAST::Type { .. } => true,
427+
_ => false,
428+
})
426429
}
427430
_ => {
428431
// Non-ADT derive is an error, but it should have been

0 commit comments

Comments
 (0)