From 6b7ca2fcf2ebbba705f7a98c00bd56b5348ee9d7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 8 Sep 2022 10:52:51 +1000 Subject: [PATCH] Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns. --- compiler/rustc_ast/src/ast.rs | 69 ++++--- compiler/rustc_ast/src/mut_visit.rs | 32 +++- compiler/rustc_ast/src/util/classify.rs | 4 +- compiler/rustc_ast/src/util/parser.rs | 2 +- compiler/rustc_ast/src/visit.rs | 18 +- compiler/rustc_ast_lowering/src/expr.rs | 16 +- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_ast_lowering/src/path.rs | 2 +- .../rustc_ast_pretty/src/pprust/state/expr.rs | 21 ++- .../src/assert/context.rs | 16 +- compiler/rustc_expand/src/build.rs | 14 +- compiler/rustc_lint/src/early.rs | 5 +- compiler/rustc_lint/src/unused.rs | 2 +- .../rustc_parse/src/parser/diagnostics.rs | 10 +- compiler/rustc_parse/src/parser/expr.rs | 42 +++-- compiler/rustc_parse/src/parser/pat.rs | 8 +- compiler/rustc_parse/src/parser/path.rs | 4 +- compiler/rustc_resolve/src/def_collector.rs | 4 +- compiler/rustc_resolve/src/late.rs | 59 +++--- .../rustc_resolve/src/late/diagnostics.rs | 18 +- src/test/ui-fulldeps/pprust-expr-roundtrip.rs | 30 +-- src/test/ui/stats/hir-stats.stderr | 178 +++++++++--------- .../clippy/clippy_lints/src/double_parens.rs | 8 +- .../clippy_lints/src/option_env_unwrap.rs | 6 +- .../clippy/clippy_lints/src/precedence.rs | 8 +- .../src/redundant_closure_call.rs | 12 +- .../src/suspicious_operation_groupings.rs | 4 +- .../clippy_lints/src/unnested_or_patterns.rs | 2 +- .../clippy_lints/src/unused_rounding.rs | 6 +- .../clippy/clippy_utils/src/ast_utils.rs | 32 +++- src/tools/rustfmt/src/attr.rs | 6 +- src/tools/rustfmt/src/chains.rs | 12 +- src/tools/rustfmt/src/closures.rs | 30 +-- src/tools/rustfmt/src/expr.rs | 26 +-- src/tools/rustfmt/src/patterns.rs | 9 +- src/tools/rustfmt/src/types.rs | 8 +- src/tools/rustfmt/src/utils.rs | 2 +- 37 files changed, 409 insertions(+), 318 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 5d9d0a5feca..a9b3aa1d560 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -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