1
Fork 0

Remove methods from ast::GenericParam and ast::Generics

This commit is contained in:
varkor 2018-05-26 23:21:08 +01:00
parent 2c6ff2469a
commit e1d888c722
8 changed files with 17 additions and 47 deletions

View file

@ -324,7 +324,10 @@ impl<'a> LoweringContext<'a> {
let count = generics let count = generics
.params .params
.iter() .iter()
.filter(|param| param.is_lifetime_param()) .filter(|param| match param.kind {
ast::GenericParamKindAST::Lifetime { .. } => true,
_ => false,
})
.count(); .count();
self.lctx.type_def_lifetime_params.insert(def_id, count); self.lctx.type_def_lifetime_params.insert(def_id, count);
} }

View file

@ -294,7 +294,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => { ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => {
if is_auto == IsAuto::Yes { if is_auto == IsAuto::Yes {
// Auto traits cannot have generics, super traits nor contain items. // 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, struct_span_err!(self.session, item.span, E0567,
"auto traits cannot have generic parameters").emit(); "auto traits cannot have generic parameters").emit();
} }

View file

@ -342,22 +342,6 @@ pub struct GenericParamAST {
pub kind: GenericParamKindAST, 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 /// Represents lifetime, type and const parameters attached to a declaration of
/// a function, enum, trait, etc. /// a function, enum, trait, etc.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@ -367,29 +351,6 @@ pub struct Generics {
pub span: Span, 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<Span> {
for param in &self.params {
if param.ident.name == name {
return Some(param.ident.span);
}
}
None
}
}
impl Default for Generics { impl Default for Generics {
/// Creates an instance of `Generics`. /// Creates an instance of `Generics`.
fn default() -> Generics { fn default() -> Generics {

View file

@ -1797,7 +1797,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, associated_type_defaults, ti.span, gate_feature_post!(&self, associated_type_defaults, ti.span,
"associated type defaults are unstable"); "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, gate_feature_post!(&self, generic_associated_types, ti.span,
"generic associated types are unstable"); "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"); 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, gate_feature_post!(&self, generic_associated_types, ii.span,
"generic associated types are unstable"); "generic associated types are unstable");
} }

View file

@ -1329,7 +1329,7 @@ impl<'a> State<'a> {
self.print_unsafety(unsafety)?; self.print_unsafety(unsafety)?;
self.word_nbsp("impl")?; self.word_nbsp("impl")?;
if generics.is_parameterized() { if !generics.params.is_empty() {
self.print_generic_params(&generics.params)?; self.print_generic_params(&generics.params)?;
self.s.space()?; self.s.space()?;
} }

View file

@ -353,7 +353,7 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
match (has_output, has_should_panic_attr) { match (has_output, has_should_panic_attr) {
(true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs), (true, true) => No(BadTestSignature::ShouldPanicOnlyWithNoArgs),
(true, false) => if generics.is_parameterized() { (true, false) => if !generics.params.is_empty() {
No(BadTestSignature::WrongTypeSignature) No(BadTestSignature::WrongTypeSignature)
} else { } else {
Yes Yes

View file

@ -49,7 +49,10 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
ItemKind::Struct(_, Generics { ref params, .. }) | ItemKind::Struct(_, Generics { ref params, .. }) |
ItemKind::Enum(_, Generics { ref params, .. }) => { ItemKind::Enum(_, Generics { ref params, .. }) => {
if attr::contains_name(&annitem.attrs, "rustc_copy_clone_marker") && 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![]; bounds = vec![];
is_shallow = true; is_shallow = true;

View file

@ -422,7 +422,10 @@ impl<'a> TraitDef<'a> {
ast::ItemKind::Struct(_, ref generics) | ast::ItemKind::Struct(_, ref generics) |
ast::ItemKind::Enum(_, ref generics) | ast::ItemKind::Enum(_, ref generics) |
ast::ItemKind::Union(_, 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 // Non-ADT derive is an error, but it should have been