and refactor to just move the checking
This commit is contained in:
parent
a2899408dd
commit
65ccf24ce8
7 changed files with 100 additions and 39 deletions
|
|
@ -21,7 +21,6 @@ use rustc::session::Session;
|
|||
use syntax::ast::*;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::visit::{self, Visitor};
|
||||
use syntax_pos::Span;
|
||||
use errors;
|
||||
|
|
@ -35,8 +34,16 @@ impl<'a> AstValidator<'a> {
|
|||
&self.session.parse_sess.span_diagnostic
|
||||
}
|
||||
|
||||
fn check_lifetime(&self, lifetime: &Lifetime) {
|
||||
if !lifetime.ident.without_first_quote().is_valid() &&
|
||||
!lifetime.ident.name.is_static_keyword() {
|
||||
self.err_handler().span_err(lifetime.span, "lifetimes cannot use keyword names");
|
||||
}
|
||||
}
|
||||
|
||||
fn check_label(&self, label: Ident, span: Span) {
|
||||
if label.name == keywords::StaticLifetime.name() || label.name == "'_" {
|
||||
if label.name.is_static_keyword() || !label.without_first_quote().is_valid()
|
||||
|| label.name == "'_" {
|
||||
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
|
||||
}
|
||||
}
|
||||
|
|
@ -202,7 +209,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
|
||||
fn visit_item(&mut self, item: &'a Item) {
|
||||
match item.node {
|
||||
ItemKind::Impl(.., Some(..), _, ref impl_items) => {
|
||||
ItemKind::Impl(.., ref generics, Some(..), _, ref impl_items) => {
|
||||
self.invalid_visibility(&item.vis, item.span, None);
|
||||
for impl_item in impl_items {
|
||||
self.invalid_visibility(&impl_item.vis, impl_item.span, None);
|
||||
|
|
@ -210,11 +217,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
self.check_trait_fn_not_const(sig.constness);
|
||||
}
|
||||
}
|
||||
generics.lifetimes.iter().for_each(|l| self.check_lifetime(&l.lifetime))
|
||||
}
|
||||
ItemKind::Impl(.., None, _, _) => {
|
||||
ItemKind::Impl(.., ref generics, None, _, _) => {
|
||||
self.invalid_visibility(&item.vis,
|
||||
item.span,
|
||||
Some("place qualifiers on individual impl items instead"));
|
||||
generics.lifetimes.iter().for_each(|l| self.check_lifetime(&l.lifetime))
|
||||
}
|
||||
ItemKind::AutoImpl(..) => {
|
||||
self.invalid_visibility(&item.vis, item.span, None);
|
||||
|
|
@ -225,13 +234,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
Some("place qualifiers on individual foreign items \
|
||||
instead"));
|
||||
}
|
||||
ItemKind::Enum(ref def, _) => {
|
||||
ItemKind::Enum(ref def, ref generics) => {
|
||||
for variant in &def.variants {
|
||||
self.invalid_non_exhaustive_attribute(variant);
|
||||
for field in variant.node.data.fields() {
|
||||
self.invalid_visibility(&field.vis, field.span, None);
|
||||
}
|
||||
}
|
||||
generics.lifetimes.iter().for_each(|l| self.check_lifetime(&l.lifetime))
|
||||
}
|
||||
ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => {
|
||||
if is_auto == IsAuto::Yes {
|
||||
|
|
@ -268,6 +278,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
generics.lifetimes.iter().for_each(|l| self.check_lifetime(&l.lifetime))
|
||||
}
|
||||
ItemKind::Mod(_) => {
|
||||
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
|
||||
|
|
@ -278,7 +289,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
self.session.buffer_lint(lint, item.id, item.span, msg);
|
||||
}
|
||||
}
|
||||
ItemKind::Union(ref vdata, _) => {
|
||||
ItemKind::Union(ref vdata, ref generics) => {
|
||||
if !vdata.is_struct() {
|
||||
self.err_handler().span_err(item.span,
|
||||
"tuple and unit unions are not permitted");
|
||||
|
|
@ -287,6 +298,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
self.err_handler().span_err(item.span,
|
||||
"unions cannot have zero fields");
|
||||
}
|
||||
generics.lifetimes.iter().for_each(|l| self.check_lifetime(&l.lifetime))
|
||||
}
|
||||
ItemKind::Fn(.., ref generics, _) |
|
||||
ItemKind::Ty(_, ref generics) |
|
||||
ItemKind::Struct(_, ref generics) => {
|
||||
generics.lifetimes.iter().for_each(|l| self.check_lifetime(&l.lifetime))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue