diff --git a/Cargo.lock b/Cargo.lock index c867bb4ceaa9e..e1359b9e9e402 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3476,6 +3476,7 @@ dependencies = [ "rustc_session", "rustc_span", "smallvec", + "thin-vec", "tracing", ] @@ -3916,6 +3917,7 @@ dependencies = [ "rustc_macros", "rustc_session", "rustc_span", + "thin-vec", "tracing", "unicode-normalization", "unicode-width", @@ -4051,6 +4053,7 @@ dependencies = [ "rustc_session", "rustc_span", "smallvec", + "thin-vec", "tracing", ] diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 5d9d0a5fecacc..e6b72bd58c540 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -36,7 +36,7 @@ use rustc_span::{Span, DUMMY_SP}; use std::convert::TryFrom; use std::fmt; use std::mem; -use thin_vec::ThinVec; +use thin_vec::{thin_vec, ThinVec}; /// A "Label" is an identifier of some point in sources, /// e.g. in the following code: @@ -90,7 +90,7 @@ pub struct Path { pub span: Span, /// The segments in the path: the things separated by `::`. /// Global paths begin with `kw::PathRoot`. - pub segments: Vec, + pub segments: ThinVec, pub tokens: Option, } @@ -114,7 +114,7 @@ impl Path { // Convert a span and an identifier to the corresponding // one-segment path. pub fn from_ident(ident: Ident) -> Path { - Path { segments: vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None } + Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None } } pub fn is_global(&self) -> bool { @@ -718,10 +718,10 @@ 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, Vec, /* recovered */ bool), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). - TupleStruct(Option, Path, Vec>), + TupleStruct(Option>, Path, Vec>), /// An or-pattern `A | B | C`. /// Invariant: `pats.len() >= 2`. @@ -731,7 +731,7 @@ pub enum PatKind { /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants /// or associated constants. Qualified path patterns `::B::C`/`::B::C` can /// only legally refer to associated constants. - Path(Option, Path), + Path(Option>, Path), /// A tuple pattern (`(a, b)`). Tuple(Vec>), @@ -1272,6 +1272,18 @@ impl Expr { } } +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct Closure { + pub binder: ClosureBinder, + pub capture_clause: CaptureBy, + pub asyncness: Async, + pub movability: Movability, + pub fn_decl: P, + pub body: P, + /// The span of the argument block `|...|`. + pub fn_decl_span: Span, +} + /// Limit types of a range (inclusive or exclusive) #[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)] pub enum RangeLimits { @@ -1281,6 +1293,20 @@ pub enum RangeLimits { Closed, } +/// A method call (e.g. `x.foo::(a, b, c)`). +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct MethodCall { + /// The method name and its generic arguments, e.g. `foo::`. + pub seg: PathSegment, + /// The receiver, e.g. `x`. + pub receiver: P, + /// The arguments, e.g. `a, b, c`. + pub args: Vec>, + /// The span of the function, without the dot and receiver e.g. `foo::(a, b, c)`. + pub span: Span, +} + #[derive(Clone, Encodable, Decodable, Debug)] pub enum StructRest { /// `..x`. @@ -1293,7 +1319,7 @@ pub enum StructRest { #[derive(Clone, Encodable, Decodable, Debug)] pub struct StructExpr { - pub qself: Option, + pub qself: Option>, pub path: Path, pub fields: Vec, pub rest: StructRest, @@ -1314,17 +1340,8 @@ pub enum ExprKind { /// This also represents calling the constructor of /// tuple-like ADTs such as tuple structs and enum variants. Call(P, Vec>), - /// A method call (`x.foo::<'static, Bar, Baz>(a, b, c, d)`) - /// - /// The `PathSegment` represents the method name and its generic arguments - /// (within the angle brackets). - /// The standalone `Expr` is the receiver expression. - /// The vector of `Expr` is the arguments. - /// `x.foo::(a, b, c, d)` is represented as - /// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, x, [a, b, c, d])`. - /// This `Span` is the span of the function, without the dot and receiver - /// (e.g. `foo(a, b)` in `x.foo(a, b)` - MethodCall(PathSegment, P, Vec>, Span), + /// A method call (e.g. `x.foo::(a, b, c)`). + MethodCall(Box), /// A tuple (e.g., `(a, b, c, d)`). Tup(Vec>), /// A binary operation (e.g., `a + b`, `a * b`). @@ -1363,9 +1380,7 @@ pub enum ExprKind { /// A `match` block. Match(P, Vec), /// A closure (e.g., `move |a, b, c| a + b + c`). - /// - /// The final span is the span of the argument block `|...|`. - Closure(ClosureBinder, CaptureBy, Async, Movability, P, P, Span), + Closure(Box), /// A block (`'label: { ... }`). Block(P, Option