From 4f9fe856a25ab29345b90e7725509e9ee38a37be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:41 +0200 Subject: Adding upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_ast/Cargo.toml | 3 +- compiler/rustc_ast/src/ast.rs | 106 +++--- compiler/rustc_ast/src/attr/mod.rs | 632 ++++++++++++++++---------------- compiler/rustc_ast/src/format.rs | 272 ++++++++++++++ compiler/rustc_ast/src/lib.rs | 3 +- compiler/rustc_ast/src/mut_visit.rs | 58 ++- compiler/rustc_ast/src/tokenstream.rs | 42 ++- compiler/rustc_ast/src/util/comments.rs | 33 +- compiler/rustc_ast/src/util/parser.rs | 6 +- compiler/rustc_ast/src/util/unicode.rs | 2 +- compiler/rustc_ast/src/visit.rs | 13 + 11 files changed, 764 insertions(+), 406 deletions(-) create mode 100644 compiler/rustc_ast/src/format.rs (limited to 'compiler/rustc_ast') diff --git a/compiler/rustc_ast/Cargo.toml b/compiler/rustc_ast/Cargo.toml index 9253b7e68..f0632ac92 100644 --- a/compiler/rustc_ast/Cargo.toml +++ b/compiler/rustc_ast/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] bitflags = "1.2.1" +memchr = "2.5.0" rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } rustc_lexer = { path = "../rustc_lexer" } @@ -14,5 +15,5 @@ rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } -thin-vec = "0.2.9" +thin-vec = "0.2.12" tracing = "0.1" diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 9317579f7..03c375c46 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -18,6 +18,7 @@ //! - [`Attribute`]: Metadata associated with item. //! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators. +pub use crate::format::*; pub use crate::util::parser::ExprPrecedence; pub use GenericArgs::*; pub use UnsafeSource::*; @@ -208,7 +209,7 @@ pub struct AngleBracketedArgs { /// The overall span. pub span: Span, /// The comma separated parts in the `<...>`. - pub args: Vec, + pub args: ThinVec, } /// Either an argument for a parameter e.g., `'a`, `Vec`, `0`, @@ -252,7 +253,7 @@ pub struct ParenthesizedArgs { pub span: Span, /// `(A, B)` - pub inputs: Vec>, + pub inputs: ThinVec>, /// ```text /// Foo(A, B) -> C @@ -383,7 +384,7 @@ impl GenericParam { /// a function, enum, trait, etc. #[derive(Clone, Encodable, Decodable, Debug)] pub struct Generics { - pub params: Vec, + pub params: ThinVec, pub where_clause: WhereClause, pub span: Span, } @@ -391,7 +392,7 @@ pub struct Generics { impl Default for Generics { /// Creates an instance of `Generics`. fn default() -> Generics { - Generics { params: Vec::new(), where_clause: Default::default(), span: DUMMY_SP } + Generics { params: ThinVec::new(), where_clause: Default::default(), span: DUMMY_SP } } } @@ -402,13 +403,13 @@ pub struct WhereClause { /// if we parsed no predicates (e.g. `struct Foo where {}`). /// This allows us to pretty-print accurately. pub has_where_token: bool, - pub predicates: Vec, + pub predicates: ThinVec, pub span: Span, } impl Default for WhereClause { fn default() -> WhereClause { - WhereClause { has_where_token: false, predicates: Vec::new(), span: DUMMY_SP } + WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP } } } @@ -440,7 +441,7 @@ impl WherePredicate { pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding. - pub bound_generic_params: Vec, + pub bound_generic_params: ThinVec, /// The type being bounded. pub bounded_ty: P, /// Trait and lifetime bounds (`Clone + Send + 'static`). @@ -470,7 +471,7 @@ pub struct WhereEqPredicate { #[derive(Clone, Encodable, Decodable, Debug)] pub struct Crate { pub attrs: AttrVec, - pub items: Vec>, + pub items: ThinVec>, pub spans: ModSpans, /// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold /// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that. @@ -502,7 +503,7 @@ pub enum MetaItemKind { /// List meta item. /// /// E.g., `#[derive(..)]`, where the field represents the `..`. - List(Vec), + List(ThinVec), /// Name value meta item. /// @@ -530,7 +531,7 @@ pub enum NestedMetaItem { #[derive(Clone, Encodable, Decodable, Debug)] pub struct Block { /// The statements in the block. - pub stmts: Vec, + pub stmts: ThinVec, pub id: NodeId, /// Distinguishes between `unsafe { ... }` and `{ ... }`. pub rules: BlockCheckMode, @@ -580,7 +581,7 @@ impl Pat { // A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)` // assuming `T0` to `Tn` are all syntactically valid as types. PatKind::Tuple(pats) => { - let mut tys = Vec::with_capacity(pats.len()); + let mut tys = ThinVec::with_capacity(pats.len()); // FIXME(#48994) - could just be collected into an Option for pat in pats { tys.push(pat.to_ty()?); @@ -721,14 +722,14 @@ pub enum PatKind { /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). /// The `bool` is `true` in the presence of a `..`. - Struct(Option>, Path, Vec, /* recovered */ bool), + Struct(Option>, Path, ThinVec, /* recovered */ bool), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). - TupleStruct(Option>, Path, Vec>), + TupleStruct(Option>, Path, ThinVec>), /// An or-pattern `A | B | C`. /// Invariant: `pats.len() >= 2`. - Or(Vec>), + Or(ThinVec>), /// A possibly qualified path pattern. /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants @@ -737,7 +738,7 @@ pub enum PatKind { Path(Option>, Path), /// A tuple pattern (`(a, b)`). - Tuple(Vec>), + Tuple(ThinVec>), /// A `box` pattern. Box(P), @@ -752,7 +753,7 @@ pub enum PatKind { Range(Option>, Option>, Spanned), /// A slice pattern `[a, b, c]`. - Slice(Vec>), + Slice(ThinVec>), /// A rest pattern `..`. /// @@ -1168,7 +1169,7 @@ impl Expr { pub fn to_bound(&self) -> Option { match &self.kind { ExprKind::Path(None, path) => Some(GenericBound::Trait( - PolyTraitRef::new(Vec::new(), path.clone(), self.span), + PolyTraitRef::new(ThinVec::new(), path.clone(), self.span), TraitBoundModifier::None, )), _ => None, @@ -1203,7 +1204,7 @@ impl Expr { ExprKind::Array(exprs) if exprs.len() == 1 => exprs[0].to_ty().map(TyKind::Slice)?, ExprKind::Tup(exprs) => { - let tys = exprs.iter().map(|expr| expr.to_ty()).collect::>>()?; + let tys = exprs.iter().map(|expr| expr.to_ty()).collect::>>()?; TyKind::Tup(tys) } @@ -1269,6 +1270,7 @@ impl Expr { ExprKind::Try(..) => ExprPrecedence::Try, ExprKind::Yield(..) => ExprPrecedence::Yield, ExprKind::Yeet(..) => ExprPrecedence::Yeet, + ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs, ExprKind::Err => ExprPrecedence::Err, } } @@ -1335,7 +1337,7 @@ pub struct MethodCall { /// The receiver, e.g. `x`. pub receiver: P, /// The arguments, e.g. `a, b, c`. - pub args: Vec>, + pub args: ThinVec>, /// The span of the function, without the dot and receiver e.g. `foo::(a, b, c)`. pub span: Span, @@ -1355,7 +1357,7 @@ pub enum StructRest { pub struct StructExpr { pub qself: Option>, pub path: Path, - pub fields: Vec, + pub fields: ThinVec, pub rest: StructRest, } @@ -1364,7 +1366,7 @@ pub enum ExprKind { /// A `box x` expression. Box(P), /// An array (`[a, b, c, d]`) - Array(Vec>), + Array(ThinVec>), /// Allow anonymous constants from an inline `const` block ConstBlock(AnonConst), /// A function call @@ -1373,11 +1375,11 @@ pub enum ExprKind { /// and the second field is the list of arguments. /// This also represents calling the constructor of /// tuple-like ADTs such as tuple structs and enum variants. - Call(P, Vec>), + Call(P, ThinVec>), /// A method call (e.g. `x.foo::(a, b, c)`). MethodCall(Box), /// A tuple (e.g., `(a, b, c, d)`). - Tup(Vec>), + Tup(ThinVec>), /// A binary operation (e.g., `a + b`, `a * b`). Binary(BinOp, P, P), /// A unary operation (e.g., `!x`, `*x`). @@ -1412,7 +1414,7 @@ pub enum ExprKind { /// `'label: loop { block }` Loop(P, Option