Skip to content

Commit e382877

Browse files
committed
rust-analyzer guided tuple field to named field
1 parent b08a557 commit e382877

File tree

16 files changed

+33
-24
lines changed

16 files changed

+33
-24
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,11 @@ pub struct Fn {
28912891
}
28922892

28932893
#[derive(Clone, Encodable, Decodable, Debug)]
2894-
pub struct Static(pub P<Ty>, pub Mutability, pub Option<P<Expr>>);
2894+
pub struct Static {
2895+
pub ty: P<Ty>,
2896+
pub mutability: Mutability,
2897+
pub expr: Option<P<Expr>>,
2898+
}
28952899

28962900
#[derive(Clone, Encodable, Decodable, Debug)]
28972901
pub enum ItemKind {
@@ -2978,7 +2982,7 @@ impl ItemKind {
29782982
match self {
29792983
ItemKind::ExternCrate(..) => "extern crate",
29802984
ItemKind::Use(..) => "`use` import",
2981-
ItemKind::Static(Static(..)) => "static item",
2985+
ItemKind::Static(..) => "static item",
29822986
ItemKind::Const(..) => "constant item",
29832987
ItemKind::Fn(..) => "function",
29842988
ItemKind::Mod(..) => "module",
@@ -3087,7 +3091,9 @@ pub enum ForeignItemKind {
30873091
impl From<ForeignItemKind> for ItemKind {
30883092
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
30893093
match foreign_item_kind {
3090-
ForeignItemKind::Static(a, b, c) => ItemKind::Static(Static(a, b, c)),
3094+
ForeignItemKind::Static(a, b, c) => {
3095+
ItemKind::Static(Static { ty: a, mutability: b, expr: c })
3096+
}
30913097
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
30923098
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
30933099
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
@@ -3100,7 +3106,9 @@ impl TryFrom<ItemKind> for ForeignItemKind {
31003106

31013107
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
31023108
Ok(match item_kind {
3103-
ItemKind::Static(Static(a, b, c)) => ForeignItemKind::Static(a, b, c),
3109+
ItemKind::Static(Static { ty: a, mutability: b, expr: c }) => {
3110+
ForeignItemKind::Static(a, b, c)
3111+
}
31043112
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
31053113
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
31063114
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10301030
match kind {
10311031
ItemKind::ExternCrate(_orig_name) => {}
10321032
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
1033-
ItemKind::Static(Static(ty, _, expr)) => {
1033+
ItemKind::Static(Static { ty, mutability: _, expr }) => {
10341034
vis.visit_ty(ty);
10351035
visit_opt(expr, |expr| vis.visit_expr(expr));
10361036
}

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
305305
match &item.kind {
306306
ItemKind::ExternCrate(_) => {}
307307
ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
308-
ItemKind::Static(Static(typ, _, expr)) | ItemKind::Const(_, typ, expr) => {
308+
ItemKind::Static(Static { ty: typ, mutability: _, expr })
309+
| ItemKind::Const(_, typ, expr) => {
309310
visitor.visit_ty(typ);
310311
walk_list!(visitor, visit_expr, expr);
311312
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
229229

230230
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
231231
}
232-
ItemKind::Static(ast::Static(t, m, e)) => {
232+
ItemKind::Static(ast::Static { ty: t, mutability: m, expr: e }) => {
233233
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
234234
hir::ItemKind::Static(ty, *m, body_id)
235235
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
990990
replace_span: self.ending_semi_or_hi(item.span),
991991
});
992992
}
993-
ItemKind::Static(Static(.., None)) => {
993+
ItemKind::Static(Static { expr: None, .. }) => {
994994
self.session.emit_err(errors::StaticWithoutBody {
995995
span: item.span,
996996
replace_span: self.ending_semi_or_hi(item.span),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a> State<'a> {
157157
self.print_use_tree(tree);
158158
self.word(";");
159159
}
160-
ast::ItemKind::Static(Static(ty, mutbl, body)) => {
160+
ast::ItemKind::Static(Static { ty, mutability: mutbl, expr: body }) => {
161161
let def = ast::Defaultness::Final;
162162
self.print_item_const(
163163
item.ident,

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn expand(
2525
// FIXME - if we get deref patterns, use them to reduce duplication here
2626
let (item, is_stmt, ty_span) =
2727
if let Annotatable::Item(item) = &item
28-
&& let ItemKind::Static(ast::Static(ty, ..)) = &item.kind
28+
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind
2929
{
3030
(item, false, ecx.with_def_site_ctxt(ty.span))
3131
} else if let Annotatable::Stmt(stmt) = &item
3232
&& let StmtKind::Item(item) = &stmt.kind
33-
&& let ItemKind::Static(ast::Static(ty, ..)) = &item.kind
33+
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind
3434
{
3535
(item, true, ecx.with_def_site_ctxt(ty.span))
3636
} else {

compiler/rustc_expand/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,14 @@ impl<'a> ExtCtxt<'a> {
620620
span: Span,
621621
name: Ident,
622622
ty: P<ast::Ty>,
623-
mutbl: ast::Mutability,
623+
mutability: ast::Mutability,
624624
expr: P<ast::Expr>,
625625
) -> P<ast::Item> {
626626
self.item(
627627
span,
628628
name,
629629
AttrVec::new(),
630-
ast::ItemKind::Static(ast::Static(ty, mutbl, Some(expr))),
630+
ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }),
631631
)
632632
}
633633

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use crate::{
4343
types::{transparent_newtype_field, CItemKind},
4444
EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext,
4545
};
46-
use ast::Static;
4746
use hir::IsAsync;
4847
use rustc_ast::attr;
4948
use rustc_ast::tokenstream::{TokenStream, TokenTree};
@@ -371,7 +370,7 @@ impl EarlyLintPass for UnsafeCode {
371370
}
372371
}
373372

374-
ast::ItemKind::Static(Static(..)) => {
373+
ast::ItemKind::Static(..) => {
375374
if let Some(attr) = attr::find_by_name(&it.attrs, sym::no_mangle) {
376375
self.report_unsafe(cx, attr.span, BuiltinUnsafe::NoMangleStatic);
377376
}

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ trait UnusedDelimLint {
805805
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
806806
use ast::ItemKind::*;
807807

808-
if let Const(.., Some(expr)) | Static(ast::Static(.., Some(expr))) = &item.kind {
808+
if let Const(.., Some(expr)) | Static(ast::Static { expr: Some(expr), .. }) = &item.kind {
809809
self.check_unused_delims_expr(
810810
cx,
811811
expr,

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'a> Parser<'a> {
228228
self.bump(); // `static`
229229
let m = self.parse_mutability();
230230
let (ident, ty, expr) = self.parse_item_global(Some(m))?;
231-
(ident, ItemKind::Static(Static(ty, m, expr)))
231+
(ident, ItemKind::Static(Static { ty, mutability: m, expr }))
232232
} else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) {
233233
// CONST ITEM
234234
if self.token.is_keyword(kw::Impl) {
@@ -863,7 +863,7 @@ impl<'a> Parser<'a> {
863863
let kind = match AssocItemKind::try_from(kind) {
864864
Ok(kind) => kind,
865865
Err(kind) => match kind {
866-
ItemKind::Static(Static(a, _, b)) => {
866+
ItemKind::Static(Static { ty: a, mutability: _, expr: b }) => {
867867
self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span });
868868
AssocItemKind::Const(Defaultness::Final, a, b)
869869
}

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
688688
}
689689

690690
// These items live in the value namespace.
691-
ItemKind::Static(ast::Static(_, mt, _)) => {
692-
let res = Res::Def(DefKind::Static(mt), def_id);
691+
ItemKind::Static(ast::Static { mutability, .. }) => {
692+
let res = Res::Def(DefKind::Static(mutability), def_id);
693693
self.r.define(parent, ident, ValueNS, (res, vis, sp, expansion));
694694
}
695695
ItemKind::Const(..) => {

compiler/rustc_resolve/src/late.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23462346
});
23472347
}
23482348

2349-
ItemKind::Static(ast::Static(ref ty, _, ref expr)) | ItemKind::Const(_, ref ty, ref expr) => {
2349+
ItemKind::Static(ast::Static { ref ty, ref expr, .. })
2350+
| ItemKind::Const(_, ref ty, ref expr) => {
23502351
self.with_static_rib(|this| {
23512352
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
23522353
this.visit_ty(ty);

src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl EarlyLintPass for RedundantStaticLifetimes {
106106
// #2438)
107107
}
108108

109-
if let ItemKind::Static(Static(ref var_type, _, _)) = item.kind {
109+
if let ItemKind::Static(Static{ ty: ref var_type,.. }) = item.kind {
110110
Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime");
111111
}
112112
}

src/tools/clippy/clippy_utils/src/ast_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
286286
match (l, r) {
287287
(ExternCrate(l), ExternCrate(r)) => l == r,
288288
(Use(l), Use(r)) => eq_use_tree(l, r),
289-
(Static(ast::Static(lt, lm, le)), Static(ast::Static(rt, rm, re))) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
289+
(Static(ast::Static{ ty: lt, mutability: lm, expr: le}), Static(ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
290290
(Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
291291
(
292292
Fn(box ast::Fn {

src/tools/rustfmt/src/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ pub(crate) struct StaticParts<'a> {
18051805
impl<'a> StaticParts<'a> {
18061806
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
18071807
let (defaultness, prefix, ty, mutability, expr) = match item.kind {
1808-
ast::ItemKind::Static(ast::Static(ref ty, mutability, ref expr)) => {
1808+
ast::ItemKind::Static(ast::Static { ref ty, mutability, ref expr}) => {
18091809
(None, "static", ty, mutability, expr)
18101810
}
18111811
ast::ItemKind::Const(defaultness, ref ty, ref expr) => {

0 commit comments

Comments
 (0)