mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
rust-analyzer guided tuple field to named field
This commit is contained in:
parent
b08a557f80
commit
e3828777a6
@ -2891,7 +2891,11 @@ pub struct Fn {
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct Static(pub P<Ty>, pub Mutability, pub Option<P<Expr>>);
|
||||
pub struct Static {
|
||||
pub ty: P<Ty>,
|
||||
pub mutability: Mutability,
|
||||
pub expr: Option<P<Expr>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum ItemKind {
|
||||
@ -2978,7 +2982,7 @@ impl ItemKind {
|
||||
match self {
|
||||
ItemKind::ExternCrate(..) => "extern crate",
|
||||
ItemKind::Use(..) => "`use` import",
|
||||
ItemKind::Static(Static(..)) => "static item",
|
||||
ItemKind::Static(..) => "static item",
|
||||
ItemKind::Const(..) => "constant item",
|
||||
ItemKind::Fn(..) => "function",
|
||||
ItemKind::Mod(..) => "module",
|
||||
@ -3087,7 +3091,9 @@ pub enum ForeignItemKind {
|
||||
impl From<ForeignItemKind> for ItemKind {
|
||||
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
|
||||
match foreign_item_kind {
|
||||
ForeignItemKind::Static(a, b, c) => ItemKind::Static(Static(a, b, c)),
|
||||
ForeignItemKind::Static(a, b, c) => {
|
||||
ItemKind::Static(Static { ty: a, mutability: b, expr: c })
|
||||
}
|
||||
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
|
||||
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
|
||||
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
|
||||
@ -3100,7 +3106,9 @@ impl TryFrom<ItemKind> for ForeignItemKind {
|
||||
|
||||
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
|
||||
Ok(match item_kind {
|
||||
ItemKind::Static(Static(a, b, c)) => ForeignItemKind::Static(a, b, c),
|
||||
ItemKind::Static(Static { ty: a, mutability: b, expr: c }) => {
|
||||
ForeignItemKind::Static(a, b, c)
|
||||
}
|
||||
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
|
||||
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
|
||||
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
|
||||
|
@ -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(Static(ty, _, expr)) => {
|
||||
ItemKind::Static(Static { ty, mutability: _, expr }) => {
|
||||
vis.visit_ty(ty);
|
||||
visit_opt(expr, |expr| vis.visit_expr(expr));
|
||||
}
|
||||
|
@ -305,7 +305,8 @@ 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(Static(typ, _, expr)) | ItemKind::Const(_, typ, expr) => {
|
||||
ItemKind::Static(Static { ty: typ, mutability: _, expr })
|
||||
| ItemKind::Const(_, typ, expr) => {
|
||||
visitor.visit_ty(typ);
|
||||
walk_list!(visitor, visit_expr, expr);
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
|
||||
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
|
||||
}
|
||||
ItemKind::Static(ast::Static(t, m, e)) => {
|
||||
ItemKind::Static(ast::Static { 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)
|
||||
}
|
||||
|
@ -990,7 +990,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
replace_span: self.ending_semi_or_hi(item.span),
|
||||
});
|
||||
}
|
||||
ItemKind::Static(Static(.., None)) => {
|
||||
ItemKind::Static(Static { expr: None, .. }) => {
|
||||
self.session.emit_err(errors::StaticWithoutBody {
|
||||
span: item.span,
|
||||
replace_span: self.ending_semi_or_hi(item.span),
|
||||
|
@ -157,7 +157,7 @@ impl<'a> State<'a> {
|
||||
self.print_use_tree(tree);
|
||||
self.word(";");
|
||||
}
|
||||
ast::ItemKind::Static(Static(ty, mutbl, body)) => {
|
||||
ast::ItemKind::Static(Static { ty, mutability: mutbl, expr: body }) => {
|
||||
let def = ast::Defaultness::Final;
|
||||
self.print_item_const(
|
||||
item.ident,
|
||||
|
@ -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(ast::Static(ty, ..)) = &item.kind
|
||||
&& let ItemKind::Static(ast::Static { 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(ast::Static(ty, ..)) = &item.kind
|
||||
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind
|
||||
{
|
||||
(item, true, ecx.with_def_site_ctxt(ty.span))
|
||||
} else {
|
||||
|
@ -620,14 +620,14 @@ impl<'a> ExtCtxt<'a> {
|
||||
span: Span,
|
||||
name: Ident,
|
||||
ty: P<ast::Ty>,
|
||||
mutbl: ast::Mutability,
|
||||
mutability: ast::Mutability,
|
||||
expr: P<ast::Expr>,
|
||||
) -> P<ast::Item> {
|
||||
self.item(
|
||||
span,
|
||||
name,
|
||||
AttrVec::new(),
|
||||
ast::ItemKind::Static(ast::Static(ty, mutbl, Some(expr))),
|
||||
ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ use crate::{
|
||||
types::{transparent_newtype_field, CItemKind},
|
||||
EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext,
|
||||
};
|
||||
use ast::Static;
|
||||
use hir::IsAsync;
|
||||
use rustc_ast::attr;
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
@ -371,7 +370,7 @@ impl EarlyLintPass for UnsafeCode {
|
||||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Static(Static(..)) => {
|
||||
ast::ItemKind::Static(..) => {
|
||||
if let Some(attr) = attr::find_by_name(&it.attrs, sym::no_mangle) {
|
||||
self.report_unsafe(cx, attr.span, BuiltinUnsafe::NoMangleStatic);
|
||||
}
|
||||
|
@ -805,7 +805,7 @@ trait UnusedDelimLint {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
|
||||
use ast::ItemKind::*;
|
||||
|
||||
if let Const(.., Some(expr)) | Static(ast::Static(.., Some(expr))) = &item.kind {
|
||||
if let Const(.., Some(expr)) | Static(ast::Static { expr: Some(expr), .. }) = &item.kind {
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
expr,
|
||||
|
@ -228,7 +228,7 @@ impl<'a> Parser<'a> {
|
||||
self.bump(); // `static`
|
||||
let m = self.parse_mutability();
|
||||
let (ident, ty, expr) = self.parse_item_global(Some(m))?;
|
||||
(ident, ItemKind::Static(Static(ty, m, expr)))
|
||||
(ident, ItemKind::Static(Static { 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 @@ impl<'a> Parser<'a> {
|
||||
let kind = match AssocItemKind::try_from(kind) {
|
||||
Ok(kind) => kind,
|
||||
Err(kind) => match kind {
|
||||
ItemKind::Static(Static(a, _, b)) => {
|
||||
ItemKind::Static(Static { ty: a, mutability: _, expr: b }) => {
|
||||
self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span });
|
||||
AssocItemKind::Const(Defaultness::Final, a, b)
|
||||
}
|
||||
|
@ -688,8 +688,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
// These items live in the value namespace.
|
||||
ItemKind::Static(ast::Static(_, mt, _)) => {
|
||||
let res = Res::Def(DefKind::Static(mt), def_id);
|
||||
ItemKind::Static(ast::Static { mutability, .. }) => {
|
||||
let res = Res::Def(DefKind::Static(mutability), def_id);
|
||||
self.r.define(parent, ident, ValueNS, (res, vis, sp, expansion));
|
||||
}
|
||||
ItemKind::Const(..) => {
|
||||
|
@ -2346,7 +2346,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
});
|
||||
}
|
||||
|
||||
ItemKind::Static(ast::Static(ref ty, _, ref expr)) | ItemKind::Const(_, ref ty, ref expr) => {
|
||||
ItemKind::Static(ast::Static { ref ty, ref expr, .. })
|
||||
| ItemKind::Const(_, ref ty, ref expr) => {
|
||||
self.with_static_rib(|this| {
|
||||
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
|
||||
this.visit_ty(ty);
|
||||
|
@ -106,7 +106,7 @@ impl EarlyLintPass for RedundantStaticLifetimes {
|
||||
// #2438)
|
||||
}
|
||||
|
||||
if let ItemKind::Static(Static(ref var_type, _, _)) = item.kind {
|
||||
if let ItemKind::Static(Static{ ty: ref var_type,.. }) = item.kind {
|
||||
Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime");
|
||||
}
|
||||
}
|
||||
|
@ -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(ast::Static(lt, lm, le)), Static(ast::Static(rt, rm, re))) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
|
||||
(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),
|
||||
(Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
|
||||
(
|
||||
Fn(box ast::Fn {
|
||||
|
@ -1805,7 +1805,7 @@ pub(crate) struct StaticParts<'a> {
|
||||
impl<'a> StaticParts<'a> {
|
||||
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
|
||||
let (defaultness, prefix, ty, mutability, expr) = match item.kind {
|
||||
ast::ItemKind::Static(ast::Static(ref ty, mutability, ref expr)) => {
|
||||
ast::ItemKind::Static(ast::Static { ref ty, mutability, ref expr}) => {
|
||||
(None, "static", ty, mutability, expr)
|
||||
}
|
||||
ast::ItemKind::Const(defaultness, ref ty, ref expr) => {
|
||||
|
Loading…
Reference in New Issue
Block a user