diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
commit | 631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch) | |
tree | a1b87c8f8cad01cf18f7c5f57a08f102771ed303 /compiler/rustc_ast/src/ast.rs | |
parent | Adding debian version 1.69.0+dfsg1-1. (diff) | |
download | rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast/src/ast.rs')
-rw-r--r-- | compiler/rustc_ast/src/ast.rs | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 03c375c46..df1a71675 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -231,15 +231,15 @@ impl AngleBracketedArg { } } -impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs { - fn into(self) -> Option<P<GenericArgs>> { - Some(P(GenericArgs::AngleBracketed(self))) +impl Into<P<GenericArgs>> for AngleBracketedArgs { + fn into(self) -> P<GenericArgs> { + P(GenericArgs::AngleBracketed(self)) } } -impl Into<Option<P<GenericArgs>>> for ParenthesizedArgs { - fn into(self) -> Option<P<GenericArgs>> { - Some(P(GenericArgs::Parenthesized(self))) +impl Into<P<GenericArgs>> for ParenthesizedArgs { + fn into(self) -> P<GenericArgs> { + P(GenericArgs::Parenthesized(self)) } } @@ -1184,6 +1184,15 @@ impl Expr { expr } + pub fn peel_parens_and_refs(&self) -> &Expr { + let mut expr = self; + while let ExprKind::Paren(inner) | ExprKind::AddrOf(BorrowKind::Ref, _, inner) = &expr.kind + { + expr = inner; + } + expr + } + /// Attempts to reparse as `Ty` (for diagnostic purposes). pub fn to_ty(&self) -> Option<P<Ty>> { let kind = match &self.kind { @@ -1230,7 +1239,6 @@ impl Expr { pub fn precedence(&self) -> ExprPrecedence { match self.kind { - ExprKind::Box(_) => ExprPrecedence::Box, ExprKind::Array(_) => ExprPrecedence::Array, ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock, ExprKind::Call(..) => ExprPrecedence::Call, @@ -1291,8 +1299,7 @@ impl Expr { /// To a first-order approximation, is this a pattern? pub fn is_approximately_pattern(&self) -> bool { match &self.peel_parens().kind { - ExprKind::Box(_) - | ExprKind::Array(_) + ExprKind::Array(_) | ExprKind::Call(_, _) | ExprKind::Tup(_) | ExprKind::Lit(_) @@ -1363,8 +1370,6 @@ pub struct StructExpr { #[derive(Clone, Encodable, Decodable, Debug)] pub enum ExprKind { - /// A `box x` expression. - Box(P<Expr>), /// An array (`[a, b, c, d]`) Array(ThinVec<P<Expr>>), /// Allow anonymous constants from an inline `const` block @@ -1421,13 +1426,9 @@ pub enum ExprKind { Block(P<Block>, Option<Label>), /// An async block (`async move { ... }`). /// - /// The `NodeId` is the `NodeId` for the closure that results from - /// desugaring an async block, just like the NodeId field in the - /// `Async::Yes` variant. This is necessary in order to create a def for the - /// closure which can be used as a parent of any child defs. Defs - /// created during lowering cannot be made the parent of any other - /// preexisting defs. - Async(CaptureBy, NodeId, P<Block>), + /// The async block used to have a `NodeId`, which was removed in favor of + /// using the parent `NodeId` of the parent `Expr`. + Async(CaptureBy, P<Block>), /// An await expression (`my_future.await`). Await(P<Expr>), @@ -2569,7 +2570,7 @@ pub enum AttrStyle { rustc_index::newtype_index! { #[custom_encodable] - #[debug_format = "AttrId({})]"] + #[debug_format = "AttrId({})"] pub struct AttrId {} } @@ -2886,6 +2887,20 @@ pub struct Fn { } #[derive(Clone, Encodable, Decodable, Debug)] +pub struct StaticItem { + pub ty: P<Ty>, + pub mutability: Mutability, + pub expr: Option<P<Expr>>, +} + +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct ConstItem { + pub defaultness: Defaultness, + pub ty: P<Ty>, + pub expr: Option<P<Expr>>, +} + +#[derive(Clone, Encodable, Decodable, Debug)] pub enum ItemKind { /// An `extern crate` item, with the optional *original* crate name if the crate was renamed. /// @@ -2898,11 +2913,11 @@ pub enum ItemKind { /// A static item (`static`). /// /// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`. - Static(P<Ty>, Mutability, Option<P<Expr>>), + Static(Box<StaticItem>), /// A constant item (`const`). /// /// E.g., `const FOO: i32 = 42;`. - Const(Defaultness, P<Ty>, Option<P<Expr>>), + Const(Box<ConstItem>), /// A function declaration (`fn`). /// /// E.g., `fn foo(bar: usize) -> usize { .. }`. @@ -3018,7 +3033,7 @@ pub type AssocItem = Item<AssocItemKind>; pub enum AssocItemKind { /// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`. /// If `def` is parsed, then the constant is provided, and otherwise required. - Const(Defaultness, P<Ty>, Option<P<Expr>>), + Const(Box<ConstItem>), /// An associated function. Fn(Box<Fn>), /// An associated type. @@ -3030,7 +3045,7 @@ pub enum AssocItemKind { impl AssocItemKind { pub fn defaultness(&self) -> Defaultness { match *self { - Self::Const(defaultness, ..) + Self::Const(box ConstItem { defaultness, .. }) | Self::Fn(box Fn { defaultness, .. }) | Self::Type(box TyAlias { defaultness, .. }) => defaultness, Self::MacCall(..) => Defaultness::Final, @@ -3041,7 +3056,7 @@ impl AssocItemKind { impl From<AssocItemKind> for ItemKind { fn from(assoc_item_kind: AssocItemKind) -> ItemKind { match assoc_item_kind { - AssocItemKind::Const(a, b, c) => ItemKind::Const(a, b, c), + AssocItemKind::Const(item) => ItemKind::Const(item), AssocItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind), AssocItemKind::Type(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind), AssocItemKind::MacCall(a) => ItemKind::MacCall(a), @@ -3054,7 +3069,7 @@ impl TryFrom<ItemKind> for AssocItemKind { fn try_from(item_kind: ItemKind) -> Result<AssocItemKind, ItemKind> { Ok(match item_kind { - ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c), + ItemKind::Const(item) => AssocItemKind::Const(item), ItemKind::Fn(fn_kind) => AssocItemKind::Fn(fn_kind), ItemKind::TyAlias(ty_kind) => AssocItemKind::Type(ty_kind), ItemKind::MacCall(a) => AssocItemKind::MacCall(a), @@ -3079,7 +3094,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(a, b, c), + ForeignItemKind::Static(a, b, c) => { + 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), ForeignItemKind::MacCall(a) => ItemKind::MacCall(a), @@ -3092,7 +3109,9 @@ impl TryFrom<ItemKind> for ForeignItemKind { fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> { Ok(match item_kind { - ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c), + ItemKind::Static(box StaticItem { 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), @@ -3109,8 +3128,8 @@ mod size_asserts { use super::*; use rustc_data_structures::static_assert_size; // tidy-alphabetical-start - static_assert_size!(AssocItem, 104); - static_assert_size!(AssocItemKind, 32); + static_assert_size!(AssocItem, 88); + static_assert_size!(AssocItemKind, 16); static_assert_size!(Attribute, 32); static_assert_size!(Block, 32); static_assert_size!(Expr, 72); |