Rename ast::Static to ast::StaticItem to match ast::ConstItem

This commit is contained in:
Oli Scherer 2023-03-29 14:14:11 +00:00
parent 4bebdd7104
commit 373807a95c
15 changed files with 68 additions and 68 deletions

View file

@ -2891,7 +2891,7 @@ pub struct Fn {
}
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Static {
pub struct StaticItem {
pub ty: P<Ty>,
pub mutability: Mutability,
pub expr: Option<P<Expr>>,
@ -2917,7 +2917,7 @@ pub enum ItemKind {
/// A static item (`static`).
///
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
Static(Box<Static>),
Static(Box<StaticItem>),
/// A constant item (`const`).
///
/// E.g., `const FOO: i32 = 42;`.
@ -3099,7 +3099,7 @@ impl From<ForeignItemKind> for ItemKind {
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
match foreign_item_kind {
ForeignItemKind::Static(a, b, c) => {
ItemKind::Static(Static { ty: a, mutability: b, expr: c }.into())
ItemKind::Static(StaticItem { ty: a, mutability: b, expr: c }.into())
}
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
@ -3113,7 +3113,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
Ok(match item_kind {
ItemKind::Static(box Static { ty: a, mutability: b, expr: c }) => {
ItemKind::Static(box StaticItem { ty: a, mutability: b, expr: c }) => {
ForeignItemKind::Static(a, b, c)
}
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),

View file

@ -10,7 +10,7 @@
use crate::ptr::P;
use crate::token::{self, Token};
use crate::tokenstream::*;
use crate::{ast::*, Static};
use crate::{ast::*, StaticItem};
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::sync::Lrc;
@ -1030,7 +1030,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
match kind {
ItemKind::ExternCrate(_orig_name) => {}
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
ItemKind::Static(box Static { ty, mutability: _, expr }) => {
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
vis.visit_ty(ty);
visit_opt(expr, |expr| vis.visit_expr(expr));
}

View file

@ -13,7 +13,7 @@
//! instance, a walker looking for item names in a module will miss all of
//! those that are created by the expansion of a macro.
use crate::{ast::*, Static};
use crate::{ast::*, StaticItem};
use rustc_span::symbol::Ident;
use rustc_span::Span;
@ -305,7 +305,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
match &item.kind {
ItemKind::ExternCrate(_) => {}
ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
ItemKind::Static(box Static { ty, mutability: _, expr })
ItemKind::Static(box StaticItem { ty, mutability: _, expr })
| ItemKind::Const(box ConstItem { ty, expr, .. }) => {
visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr);

View file

@ -229,7 +229,7 @@ fn lower_item_kind(
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
}
ItemKind::Static(box ast::Static { ty: t, mutability: m, expr: e }) => {
ItemKind::Static(box ast::StaticItem { ty: t, mutability: m, expr: e }) => {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
hir::ItemKind::Static(ty, *m, body_id)
}

View file

@ -10,7 +10,7 @@
use rustc_ast::ptr::P;
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
use rustc_ast::*;
use rustc_ast::{walk_list, Static};
use rustc_ast::{walk_list, StaticItem};
use rustc_ast_pretty::pprust::{self, State};
use rustc_data_structures::fx::FxIndexMap;
use rustc_macros::Subdiagnostic;
@ -990,7 +990,7 @@ fn visit_item(&mut self, item: &'a Item) {
replace_span: self.ending_semi_or_hi(item.span),
});
}
ItemKind::Static(box Static { expr: None, .. }) => {
ItemKind::Static(box StaticItem { expr: None, .. }) => {
self.session.emit_err(errors::StaticWithoutBody {
span: item.span,
replace_span: self.ending_semi_or_hi(item.span),

View file

@ -2,7 +2,7 @@
use crate::pprust::state::delimited::IterDelimited;
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
use ast::Static;
use ast::StaticItem;
use rustc_ast as ast;
use rustc_ast::GenericBound;
use rustc_ast::ModKind;
@ -157,7 +157,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
self.print_use_tree(tree);
self.word(";");
}
ast::ItemKind::Static(box Static { ty, mutability: mutbl, expr: body }) => {
ast::ItemKind::Static(box StaticItem { ty, mutability: mutbl, expr: body }) => {
let def = ast::Defaultness::Final;
self.print_item_const(
item.ident,

View file

@ -25,12 +25,12 @@ pub fn expand(
// FIXME - if we get deref patterns, use them to reduce duplication here
let (item, is_stmt, ty_span) =
if let Annotatable::Item(item) = &item
&& let ItemKind::Static(box ast::Static { ty, ..}) = &item.kind
&& let ItemKind::Static(box ast::StaticItem { ty, ..}) = &item.kind
{
(item, false, ecx.with_def_site_ctxt(ty.span))
} else if let Annotatable::Stmt(stmt) = &item
&& let StmtKind::Item(item) = &stmt.kind
&& let ItemKind::Static(box ast::Static { ty, ..}) = &item.kind
&& let ItemKind::Static(box ast::StaticItem { ty, ..}) = &item.kind
{
(item, true, ecx.with_def_site_ctxt(ty.span))
} else {

View file

@ -627,7 +627,7 @@ pub fn item_static(
span,
name,
AttrVec::new(),
ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }.into()),
ast::ItemKind::Static(ast::StaticItem { ty, mutability, expr: Some(expr) }.into()),
)
}

View file

@ -806,7 +806,7 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
use ast::ItemKind::*;
if let Const(box ast::ConstItem { expr: Some(expr), .. })
| Static(box ast::Static { expr: Some(expr), .. }) = &item.kind
| Static(box ast::StaticItem { expr: Some(expr), .. }) = &item.kind
{
self.check_unused_delims_expr(
cx,

View file

@ -3,7 +3,7 @@
use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
use ast::Static;
use ast::StaticItem;
use rustc_ast::ast::*;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, TokenKind};
@ -228,7 +228,7 @@ fn parse_item_kind(
self.bump(); // `static`
let m = self.parse_mutability();
let (ident, ty, expr) = self.parse_item_global(Some(m))?;
(ident, ItemKind::Static(Box::new(Static { ty, mutability: m, expr })))
(ident, ItemKind::Static(Box::new(StaticItem { ty, mutability: m, expr })))
} else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) {
// CONST ITEM
if self.token.is_keyword(kw::Impl) {
@ -863,7 +863,7 @@ fn parse_assoc_item(
let kind = match AssocItemKind::try_from(kind) {
Ok(kind) => kind,
Err(kind) => match kind {
ItemKind::Static(box Static { ty, mutability: _, expr }) => {
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span });
AssocItemKind::Const(Box::new(ConstItem {
defaultness: Defaultness::Final,

View file

@ -688,7 +688,7 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
}
// These items live in the value namespace.
ItemKind::Static(box ast::Static { mutability, .. }) => {
ItemKind::Static(box ast::StaticItem { mutability, .. }) => {
let res = Res::Def(DefKind::Static(mutability), def_id);
self.r.define(parent, ident, ValueNS, (res, vis, sp, expansion));
}

View file

@ -2346,7 +2346,7 @@ fn resolve_item(&mut self, item: &'ast Item) {
});
}
ItemKind::Static(box ast::Static { ref ty, ref expr, .. })
ItemKind::Static(box ast::StaticItem { ref ty, ref expr, .. })
| ItemKind::Const(box ast::ConstItem { ref ty, ref expr, .. }) => {
self.with_static_rib(|this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {

View file

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::snippet;
use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, Static, ConstItem};
use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, StaticItem, ConstItem};
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
@ -106,7 +106,7 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
// #2438)
}
if let ItemKind::Static(box Static { ty: ref var_type,.. }) = item.kind {
if let ItemKind::Static(box StaticItem { ty: ref var_type,.. }) = item.kind {
Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime");
}
}

View file

@ -286,7 +286,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
match (l, r) {
(ExternCrate(l), ExternCrate(r)) => l == r,
(Use(l), Use(r)) => eq_use_tree(l, r),
(Static(box ast::Static{ ty: lt, mutability: lm, expr: le}), Static(box ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
(Static(box ast::StaticItem { ty: lt, mutability: lm, expr: le}), Static(box ast::StaticItem { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
(Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
(
Fn(box ast::Fn {

View file

@ -15,45 +15,45 @@ ast-stats-1 Arm 96 ( 1.5%) 2 48
ast-stats-1 ForeignItem 96 ( 1.5%) 1 96
ast-stats-1 - Fn 96 ( 1.5%) 1
ast-stats-1 FnDecl 120 ( 1.8%) 5 24
ast-stats-1 FieldDef 160 ( 2.4%) 2 80
ast-stats-1 Stmt 160 ( 2.4%) 5 32
ast-stats-1 FieldDef 160 ( 2.5%) 2 80
ast-stats-1 Stmt 160 ( 2.5%) 5 32
ast-stats-1 - Local 32 ( 0.5%) 1
ast-stats-1 - MacCall 32 ( 0.5%) 1
ast-stats-1 - Expr 96 ( 1.5%) 3
ast-stats-1 Param 160 ( 2.4%) 4 40
ast-stats-1 Block 192 ( 2.9%) 6 32
ast-stats-1 Param 160 ( 2.5%) 4 40
ast-stats-1 Block 192 ( 3.0%) 6 32
ast-stats-1 Variant 208 ( 3.2%) 2 104
ast-stats-1 GenericBound 224 ( 3.4%) 4 56
ast-stats-1 - Trait 224 ( 3.4%) 4
ast-stats-1 AssocItem 416 ( 6.3%) 4 104
ast-stats-1 - Type 208 ( 3.2%) 2
ast-stats-1 - Fn 208 ( 3.2%) 2
ast-stats-1 GenericParam 480 ( 7.3%) 5 96
ast-stats-1 Pat 504 ( 7.7%) 7 72
ast-stats-1 GenericBound 224 ( 3.5%) 4 56
ast-stats-1 - Trait 224 ( 3.5%) 4
ast-stats-1 AssocItem 352 ( 5.4%) 4 88
ast-stats-1 - Type 176 ( 2.7%) 2
ast-stats-1 - Fn 176 ( 2.7%) 2
ast-stats-1 GenericParam 480 ( 7.4%) 5 96
ast-stats-1 Pat 504 ( 7.8%) 7 72
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Wild 72 ( 1.1%) 1
ast-stats-1 - Ident 360 ( 5.5%) 5
ast-stats-1 Expr 576 ( 8.8%) 8 72
ast-stats-1 Expr 576 ( 8.9%) 8 72
ast-stats-1 - Path 72 ( 1.1%) 1
ast-stats-1 - Match 72 ( 1.1%) 1
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Lit 144 ( 2.2%) 2
ast-stats-1 - Block 216 ( 3.3%) 3
ast-stats-1 PathSegment 720 (11.0%) 30 24
ast-stats-1 Ty 896 (13.7%) 14 64
ast-stats-1 PathSegment 720 (11.1%) 30 24
ast-stats-1 Ty 896 (13.8%) 14 64
ast-stats-1 - Ptr 64 ( 1.0%) 1
ast-stats-1 - Ref 64 ( 1.0%) 1
ast-stats-1 - ImplicitSelf 128 ( 2.0%) 2
ast-stats-1 - Path 640 ( 9.8%) 10
ast-stats-1 Item 1_224 (18.7%) 9 136
ast-stats-1 - Path 640 ( 9.9%) 10
ast-stats-1 Item 1_224 (18.9%) 9 136
ast-stats-1 - Trait 136 ( 2.1%) 1
ast-stats-1 - Enum 136 ( 2.1%) 1
ast-stats-1 - ForeignMod 136 ( 2.1%) 1
ast-stats-1 - Impl 136 ( 2.1%) 1
ast-stats-1 - Fn 272 ( 4.2%) 2
ast-stats-1 - Use 408 ( 6.2%) 3
ast-stats-1 - Use 408 ( 6.3%) 3
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total 6_552
ast-stats-1 Total 6_488
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name Accumulated Size Count Item Size
@ -65,32 +65,32 @@ ast-stats-2 ExprField 48 ( 0.7%) 1 48
ast-stats-2 WherePredicate 56 ( 0.8%) 1 56
ast-stats-2 - BoundPredicate 56 ( 0.8%) 1
ast-stats-2 Local 72 ( 1.0%) 1 72
ast-stats-2 Arm 96 ( 1.3%) 2 48
ast-stats-2 ForeignItem 96 ( 1.3%) 1 96
ast-stats-2 - Fn 96 ( 1.3%) 1
ast-stats-2 Arm 96 ( 1.4%) 2 48
ast-stats-2 ForeignItem 96 ( 1.4%) 1 96
ast-stats-2 - Fn 96 ( 1.4%) 1
ast-stats-2 InlineAsm 120 ( 1.7%) 1 120
ast-stats-2 FnDecl 120 ( 1.7%) 5 24
ast-stats-2 Attribute 128 ( 1.8%) 4 32
ast-stats-2 - DocComment 32 ( 0.4%) 1
ast-stats-2 - Normal 96 ( 1.3%) 3
ast-stats-2 FieldDef 160 ( 2.2%) 2 80
ast-stats-2 Stmt 160 ( 2.2%) 5 32
ast-stats-2 - Local 32 ( 0.4%) 1
ast-stats-2 - Semi 32 ( 0.4%) 1
ast-stats-2 - Expr 96 ( 1.3%) 3
ast-stats-2 Param 160 ( 2.2%) 4 40
ast-stats-2 - DocComment 32 ( 0.5%) 1
ast-stats-2 - Normal 96 ( 1.4%) 3
ast-stats-2 FieldDef 160 ( 2.3%) 2 80
ast-stats-2 Stmt 160 ( 2.3%) 5 32
ast-stats-2 - Local 32 ( 0.5%) 1
ast-stats-2 - Semi 32 ( 0.5%) 1
ast-stats-2 - Expr 96 ( 1.4%) 3
ast-stats-2 Param 160 ( 2.3%) 4 40
ast-stats-2 Block 192 ( 2.7%) 6 32
ast-stats-2 Variant 208 ( 2.9%) 2 104
ast-stats-2 GenericBound 224 ( 3.1%) 4 56
ast-stats-2 - Trait 224 ( 3.1%) 4
ast-stats-2 AssocItem 416 ( 5.8%) 4 104
ast-stats-2 - Type 208 ( 2.9%) 2
ast-stats-2 - Fn 208 ( 2.9%) 2
ast-stats-2 GenericParam 480 ( 6.7%) 5 96
ast-stats-2 Pat 504 ( 7.0%) 7 72
ast-stats-2 GenericBound 224 ( 3.2%) 4 56
ast-stats-2 - Trait 224 ( 3.2%) 4
ast-stats-2 AssocItem 352 ( 5.0%) 4 88
ast-stats-2 - Type 176 ( 2.5%) 2
ast-stats-2 - Fn 176 ( 2.5%) 2
ast-stats-2 GenericParam 480 ( 6.8%) 5 96
ast-stats-2 Pat 504 ( 7.1%) 7 72
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - Wild 72 ( 1.0%) 1
ast-stats-2 - Ident 360 ( 5.0%) 5
ast-stats-2 - Ident 360 ( 5.1%) 5
ast-stats-2 Expr 648 ( 9.1%) 9 72
ast-stats-2 - Path 72 ( 1.0%) 1
ast-stats-2 - Match 72 ( 1.0%) 1
@ -98,22 +98,22 @@ ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
ast-stats-2 - Lit 144 ( 2.0%) 2
ast-stats-2 - Block 216 ( 3.0%) 3
ast-stats-2 PathSegment 792 (11.1%) 33 24
ast-stats-2 Ty 896 (12.5%) 14 64
ast-stats-2 PathSegment 792 (11.2%) 33 24
ast-stats-2 Ty 896 (12.6%) 14 64
ast-stats-2 - Ptr 64 ( 0.9%) 1
ast-stats-2 - Ref 64 ( 0.9%) 1
ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2
ast-stats-2 - Path 640 ( 8.9%) 10
ast-stats-2 Item 1_496 (20.9%) 11 136
ast-stats-2 - Path 640 ( 9.0%) 10
ast-stats-2 Item 1_496 (21.1%) 11 136
ast-stats-2 - Trait 136 ( 1.9%) 1
ast-stats-2 - Enum 136 ( 1.9%) 1
ast-stats-2 - ExternCrate 136 ( 1.9%) 1
ast-stats-2 - ForeignMod 136 ( 1.9%) 1
ast-stats-2 - Impl 136 ( 1.9%) 1
ast-stats-2 - Fn 272 ( 3.8%) 2
ast-stats-2 - Use 544 ( 7.6%) 4
ast-stats-2 - Use 544 ( 7.7%) 4
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total 7_152
ast-stats-2 Total 7_088
ast-stats-2
hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size