Remove methods from ast::GenericParam and ast::Generics
This commit is contained in:
parent
2c6ff2469a
commit
e1d888c722
8 changed files with 17 additions and 47 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<Span> {
|
||||
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 {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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()?;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue