Box the biggest ast::ItemKind variants
This commit is contained in:
parent
fee0d31397
commit
b87e1ecdf0
34 changed files with 309 additions and 204 deletions
|
@ -920,7 +920,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
|
||||
match item.kind {
|
||||
ItemKind::Impl {
|
||||
ItemKind::Impl(box ImplKind {
|
||||
unsafety,
|
||||
polarity,
|
||||
defaultness: _,
|
||||
|
@ -929,7 +929,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
of_trait: Some(ref t),
|
||||
ref self_ty,
|
||||
items: _,
|
||||
} => {
|
||||
}) => {
|
||||
self.with_in_trait_impl(true, |this| {
|
||||
this.invalid_visibility(&item.vis, None);
|
||||
if let TyKind::Err = self_ty.kind {
|
||||
|
@ -957,7 +957,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
});
|
||||
return; // Avoid visiting again.
|
||||
}
|
||||
ItemKind::Impl {
|
||||
ItemKind::Impl(box ImplKind {
|
||||
unsafety,
|
||||
polarity,
|
||||
defaultness,
|
||||
|
@ -966,7 +966,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
of_trait: None,
|
||||
ref self_ty,
|
||||
items: _,
|
||||
} => {
|
||||
}) => {
|
||||
let error = |annotation_span, annotation| {
|
||||
let mut err = self.err_handler().struct_span_err(
|
||||
self_ty.span,
|
||||
|
@ -998,7 +998,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
.emit();
|
||||
}
|
||||
}
|
||||
ItemKind::Fn(def, _, _, ref body) => {
|
||||
ItemKind::Fn(box FnKind(def, _, _, ref body)) => {
|
||||
self.check_defaultness(item.span, def);
|
||||
|
||||
if body.is_none() {
|
||||
|
@ -1027,7 +1027,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => {
|
||||
ItemKind::Trait(box TraitKind(
|
||||
is_auto,
|
||||
_,
|
||||
ref generics,
|
||||
ref bounds,
|
||||
ref trait_items,
|
||||
)) => {
|
||||
if is_auto == IsAuto::Yes {
|
||||
// Auto traits cannot have generics, super traits nor contain items.
|
||||
self.deny_generic_params(generics, item.ident.span);
|
||||
|
@ -1075,7 +1081,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
let msg = "free static item without body";
|
||||
self.error_item_without_body(item.span, "static", msg, " = <expr>;");
|
||||
}
|
||||
ItemKind::TyAlias(def, _, ref bounds, ref body) => {
|
||||
ItemKind::TyAlias(box TyAliasKind(def, _, ref bounds, ref body)) => {
|
||||
self.check_defaultness(item.span, def);
|
||||
if body.is_none() {
|
||||
let msg = "free type alias without body";
|
||||
|
@ -1091,12 +1097,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
|
||||
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||
match &fi.kind {
|
||||
ForeignItemKind::Fn(def, sig, _, body) => {
|
||||
ForeignItemKind::Fn(box FnKind(def, sig, _, body)) => {
|
||||
self.check_defaultness(fi.span, *def);
|
||||
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
|
||||
self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header);
|
||||
}
|
||||
ForeignItemKind::TyAlias(def, generics, bounds, body) => {
|
||||
ForeignItemKind::TyAlias(box TyAliasKind(def, generics, bounds, body)) => {
|
||||
self.check_defaultness(fi.span, *def);
|
||||
self.check_foreign_kind_bodyless(fi.ident, "type", body.as_ref().map(|b| b.span));
|
||||
self.check_type_no_bounds(bounds, "`extern` blocks");
|
||||
|
@ -1336,10 +1342,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
AssocItemKind::Const(_, _, body) => {
|
||||
self.check_impl_item_provided(item.span, body, "constant", " = <expr>;");
|
||||
}
|
||||
AssocItemKind::Fn(_, _, _, body) => {
|
||||
AssocItemKind::Fn(box FnKind(_, _, _, body)) => {
|
||||
self.check_impl_item_provided(item.span, body, "function", " { <body> }");
|
||||
}
|
||||
AssocItemKind::TyAlias(_, _, bounds, body) => {
|
||||
AssocItemKind::TyAlias(box TyAliasKind(_, _, bounds, body)) => {
|
||||
self.check_impl_item_provided(item.span, body, "type", " = <type>;");
|
||||
self.check_type_no_bounds(bounds, "`impl`s");
|
||||
}
|
||||
|
@ -1349,7 +1355,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
|
||||
if ctxt == AssocCtxt::Trait || self.in_trait_impl {
|
||||
self.invalid_visibility(&item.vis, None);
|
||||
if let AssocItemKind::Fn(_, sig, _, _) = &item.kind {
|
||||
if let AssocItemKind::Fn(box FnKind(_, sig, _, _)) = &item.kind {
|
||||
self.check_trait_fn_not_const(sig.header.constness);
|
||||
self.check_trait_fn_not_async(item.span, sig.header.asyncness);
|
||||
}
|
||||
|
|
|
@ -365,7 +365,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Impl { polarity, defaultness, ref of_trait, .. } => {
|
||||
ast::ItemKind::Impl(box ast::ImplKind {
|
||||
polarity, defaultness, ref of_trait, ..
|
||||
}) => {
|
||||
if let ast::ImplPolarity::Negative(span) = polarity {
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
|
@ -381,7 +383,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Trait(ast::IsAuto::Yes, ..) => {
|
||||
ast::ItemKind::Trait(box ast::TraitKind(ast::IsAuto::Yes, ..)) => {
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
auto_traits,
|
||||
|
@ -399,7 +401,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
gate_feature_post!(&self, decl_macro, i.span, msg);
|
||||
}
|
||||
|
||||
ast::ItemKind::TyAlias(_, _, _, Some(ref ty)) => self.check_impl_trait(&ty),
|
||||
ast::ItemKind::TyAlias(box ast::TyAliasKind(_, _, _, Some(ref ty))) => {
|
||||
self.check_impl_trait(&ty)
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
@ -555,13 +559,13 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
|
||||
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
|
||||
let is_fn = match i.kind {
|
||||
ast::AssocItemKind::Fn(_, ref sig, _, _) => {
|
||||
ast::AssocItemKind::Fn(box ast::FnKind(_, ref sig, _, _)) => {
|
||||
if let (ast::Const::Yes(_), AssocCtxt::Trait) = (sig.header.constness, ctxt) {
|
||||
gate_feature_post!(&self, const_fn, i.span, "const fn is unstable");
|
||||
}
|
||||
true
|
||||
}
|
||||
ast::AssocItemKind::TyAlias(_, ref generics, _, ref ty) => {
|
||||
ast::AssocItemKind::TyAlias(box ast::TyAliasKind(_, ref generics, _, ref ty)) => {
|
||||
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#![feature(bindings_after_at)]
|
||||
#![feature(iter_is_partitioned)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(box_patterns)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
pub mod ast_validation;
|
||||
|
|
|
@ -68,7 +68,7 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
|||
self.count += 1;
|
||||
walk_generics(self, g)
|
||||
}
|
||||
fn visit_fn(&mut self, fk: FnKind<'_>, s: Span, _: NodeId) {
|
||||
fn visit_fn(&mut self, fk: visit::FnKind<'_>, s: Span, _: NodeId) {
|
||||
self.count += 1;
|
||||
walk_fn(self, fk, s)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue