Skip to content

Commit c0a3752

Browse files
committed
XXX: Static
1 parent 300d74d commit c0a3752

File tree

16 files changed

+78
-50
lines changed

16 files changed

+78
-50
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,13 @@ pub struct TraitAlias {
28222822
pub bounds: GenericBounds,
28232823
}
28242824

2825+
#[derive(Clone, Encodable, Decodable, Debug)]
2826+
pub struct Static {
2827+
pub ty: P<Ty>,
2828+
pub mutbl: Mutability,
2829+
pub expr: Option<P<Expr>>,
2830+
}
2831+
28252832
#[derive(Clone, Encodable, Decodable, Debug)]
28262833
pub struct Const {
28272834
pub defaultness: Defaultness,
@@ -2842,7 +2849,7 @@ pub enum ItemKind {
28422849
/// A static item (`static`).
28432850
///
28442851
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
2845-
Static(P<Ty>, Mutability, Option<P<Expr>>),
2852+
Static(Box<Static>),
28462853
/// A constant item (`const`).
28472854
///
28482855
/// E.g., `const FOO: i32 = 42;`.
@@ -3011,7 +3018,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
30113018
#[derive(Clone, Encodable, Decodable, Debug)]
30123019
pub enum ForeignItemKind {
30133020
/// A foreign static item (`static FOO: u8`).
3014-
Static(P<Ty>, Mutability, Option<P<Expr>>),
3021+
Static(Box<Static>),
30153022
/// An foreign function.
30163023
Fn(Box<Fn>),
30173024
/// An foreign type.
@@ -3023,7 +3030,7 @@ pub enum ForeignItemKind {
30233030
impl From<ForeignItemKind> for ItemKind {
30243031
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
30253032
match foreign_item_kind {
3026-
ForeignItemKind::Static(a, b, c) => ItemKind::Static(a, b, c),
3033+
ForeignItemKind::Static(static_) => ItemKind::Static(static_),
30273034
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
30283035
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
30293036
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
@@ -3036,7 +3043,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
30363043

30373044
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
30383045
Ok(match item_kind {
3039-
ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
3046+
ItemKind::Static(static_) => ForeignItemKind::Static(static_),
30403047
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
30413048
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
30423049
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
@@ -3059,8 +3066,8 @@ mod size_asserts {
30593066
static_assert_size!(Block, 48);
30603067
static_assert_size!(Expr, 104);
30613068
static_assert_size!(Fn, 192);
3062-
static_assert_size!(ForeignItem, 112);
3063-
static_assert_size!(ForeignItemKind, 24);
3069+
static_assert_size!(ForeignItem, 104);
3070+
static_assert_size!(ForeignItemKind, 16);
30643071
static_assert_size!(GenericBound, 88);
30653072
static_assert_size!(Generics, 72);
30663073
static_assert_size!(Impl, 200);

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10101010
match kind {
10111011
ItemKind::ExternCrate(_orig_name) => {}
10121012
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
1013-
ItemKind::Static(ty, _, expr) => {
1013+
ItemKind::Static(box Static { ty, mutbl: _, expr }) => {
10141014
vis.visit_ty(ty);
10151015
visit_opt(expr, |expr| vis.visit_expr(expr));
10161016
}
@@ -1178,7 +1178,7 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>(
11781178
visitor.visit_vis(vis);
11791179
visit_attrs(attrs, visitor);
11801180
match kind {
1181-
ForeignItemKind::Static(ty, _, expr) => {
1181+
ForeignItemKind::Static(box Static { ty, mutbl: _, expr }) => {
11821182
visitor.visit_ty(ty);
11831183
visit_opt(expr, |expr| visitor.visit_expr(expr));
11841184
}

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
299299
match item.kind {
300300
ItemKind::ExternCrate(_) => {}
301301
ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
302-
ItemKind::Static(ref ty, _, ref expr)
302+
ItemKind::Static(box Static { ref ty, mutbl: _, ref expr })
303303
| ItemKind::Const(box Const { ref ty, ref expr, .. }) => {
304304
visitor.visit_ty(ty);
305305
walk_list!(visitor, visit_expr, expr);
@@ -560,7 +560,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
560560
visitor.visit_ident(ident);
561561
walk_list!(visitor, visit_attribute, attrs);
562562
match kind {
563-
ForeignItemKind::Static(ty, _, expr) => {
563+
ForeignItemKind::Static(box Static { ty, mutbl: _, expr }) => {
564564
visitor.visit_ty(ty);
565565
walk_list!(visitor, visit_expr, expr);
566566
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
234234

235235
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
236236
}
237-
ItemKind::Static(ref t, m, ref e) => {
238-
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
239-
hir::ItemKind::Static(ty, m, body_id)
237+
ItemKind::Static(box Static { ref ty, mutbl, ref expr }) => {
238+
let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref());
239+
hir::ItemKind::Static(ty, mutbl, body_id)
240240
}
241241
ItemKind::Const(box Const { ref ty, ref expr, .. }) => {
242242
let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref());
@@ -657,10 +657,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
657657

658658
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
659659
}
660-
ForeignItemKind::Static(ref t, m, _) => {
660+
ForeignItemKind::Static(box Static { ref ty, mutbl, .. }) => {
661661
let ty =
662-
self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
663-
hir::ForeignItemKind::Static(ty, m)
662+
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
663+
hir::ForeignItemKind::Static(ty, mutbl)
664664
}
665665
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
666666
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13341334
let msg = "free constant item without body";
13351335
self.error_item_without_body(item.span, "constant", msg, " = <expr>;");
13361336
}
1337-
ItemKind::Static(.., None) => {
1337+
ItemKind::Static(box Static { expr: None, .. }) => {
13381338
let msg = "free static item without body";
13391339
self.error_item_without_body(item.span, "static", msg, " = <expr>;");
13401340
}
@@ -1390,8 +1390,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13901390
self.check_foreign_ty_genericless(generics, where_clauses.0.1);
13911391
self.check_foreign_item_ascii_only(fi.ident);
13921392
}
1393-
ForeignItemKind::Static(_, _, body) => {
1394-
self.check_foreign_kind_bodyless(fi.ident, "static", body.as_ref().map(|b| b.span));
1393+
ForeignItemKind::Static(box Static { expr, .. }) => {
1394+
self.check_foreign_kind_bodyless(fi.ident, "static", expr.as_ref().map(|e| e.span));
13951395
self.check_foreign_item_ascii_only(fi.ident);
13961396
}
13971397
ForeignItemKind::MacCall(..) => {}

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ impl<'a> State<'a> {
2929
ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
3030
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
3131
}
32-
ast::ForeignItemKind::Static(ty, mutbl, body) => {
33-
let def = ast::Defaultness::Final;
34-
self.print_item_const(ident, Some(*mutbl), ty, body.as_deref(), vis, def);
32+
ast::ForeignItemKind::Static(box ast::Static { ty, mutbl, expr }) => {
33+
let defaultness = ast::Defaultness::Final;
34+
self.print_item_const(ident, Some(*mutbl), ty, expr.as_deref(), vis, defaultness);
3535
}
3636
ast::ForeignItemKind::TyAlias(box ast::TyAlias {
3737
defaultness,
@@ -156,7 +156,7 @@ impl<'a> State<'a> {
156156
self.print_use_tree(tree);
157157
self.word(";");
158158
}
159-
ast::ItemKind::Static(ref ty, mutbl, ref expr) => {
159+
ast::ItemKind::Static(box ast::Static { ref ty, mutbl, ref expr }) => {
160160
let defaultness = ast::Defaultness::Final;
161161
self.print_item_const(
162162
item.ident,

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::expand::allocator::{
55
};
66
use rustc_ast::ptr::P;
77
use rustc_ast::{self as ast, Attribute, Expr, FnHeader, FnSig, Generics, Param, StmtKind};
8-
use rustc_ast::{Fn, ItemKind, Mutability, Stmt, Ty, TyKind, Unsafe};
8+
use rustc_ast::{Fn, ItemKind, Mutability, Static, Stmt, Ty, TyKind, Unsafe};
99
use rustc_expand::base::{Annotatable, ExtCtxt};
1010
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1111
use rustc_span::Span;
@@ -28,12 +28,16 @@ pub fn expand(
2828
// FIXME - if we get deref patterns, use them to reduce duplication here
2929
let (item, is_stmt, ty_span) = match &item {
3030
Annotatable::Item(item) => match item.kind {
31-
ItemKind::Static(ref ty, ..) => (item, false, ecx.with_def_site_ctxt(ty.span)),
31+
ItemKind::Static(box Static { ref ty, .. }) => {
32+
(item, false, ecx.with_def_site_ctxt(ty.span))
33+
}
3234
_ => return not_static(),
3335
},
3436
Annotatable::Stmt(stmt) => match &stmt.kind {
3537
StmtKind::Item(item_) => match item_.kind {
36-
ItemKind::Static(ref ty, ..) => (item_, true, ecx.with_def_site_ctxt(ty.span)),
38+
ItemKind::Static(box Static { ref ty, .. }) => {
39+
(item_, true, ecx.with_def_site_ctxt(ty.span))
40+
}
3741
_ => return not_static(),
3842
},
3943
_ => return not_static(),

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ pub fn expand_test_or_bench(
325325
field("testfn", test_fn), // }
326326
],
327327
), // }
328-
)},
329-
),
330-
));
328+
),
329+
})),
330+
);
331331
test_const = test_const.map(|mut tc| {
332332
tc.vis.kind = ast::VisibilityKind::Public;
333333
tc

compiler/rustc_expand/src/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,12 @@ impl<'a> ExtCtxt<'a> {
592592
mutbl: ast::Mutability,
593593
expr: P<ast::Expr>,
594594
) -> P<ast::Item> {
595-
self.item(span, name, Vec::new(), ast::ItemKind::Static(ty, mutbl, Some(expr)))
595+
self.item(
596+
span,
597+
name,
598+
Vec::new(),
599+
ast::ItemKind::Static(Box::new(ast::Static { ty, mutbl, expr: Some(expr) })),
600+
)
596601
}
597602

598603
pub fn item_const(

compiler/rustc_lint/src/unused.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ trait UnusedDelimLint {
657657
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
658658
use ast::ItemKind::*;
659659

660-
if let Const(box ast::Const { expr: Some(expr), .. }) | Static(.., Some(expr)) = &item.kind
660+
if let Const(box ast::Const { expr: Some(expr), .. })
661+
| Static(box ast::Static { expr: Some(expr), .. }) = &item.kind
661662
{
662663
self.check_unused_delims_expr(
663664
cx,

0 commit comments

Comments
 (0)