diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 062cf4e..e829a88 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,6 +37,8 @@ jobs: - uses: Swatinem/rust-cache@v2 + - name: run tests with default features + run: cargo test --all - name: run tests with embedded parser run: cargo test --all --no-default-features - name: run tests with generated parser diff --git a/Cargo.toml b/Cargo.toml index a452175..a8ce804 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,11 +16,9 @@ members = [ ] [workspace.dependencies] -rustpython-ast = { path = "ast", version = "0.2.0" } -rustpython-parser-core = { path = "core", version = "0.2.0" } +rustpython-ast = { path = "ast", version = "0.2.0", default-features = false } +rustpython-parser-core = { path = "core", version = "0.2.0", default-features = false } rustpython-literal = { path = "literal", version = "0.2.0" } -ruff_text_size = { path = "ruff_text_size" } -ruff_source_location = { path = "ruff_source_location" } ahash = "0.7.6" anyhow = "1.0.45" diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 1c98911..78e90e1 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -8,9 +8,9 @@ repository = "https://github.com/RustPython/RustPython" license = "MIT" [features] -default = ["constant-optimization", "fold", "source-code"] +default = ["location"] constant-optimization = ["fold"] -source-code = ["fold"] +location = ["fold", "rustpython-parser-core/location"] fold = [] unparse = ["rustpython-literal"] visitor = [] diff --git a/ast/src/builtin.rs b/ast/src/builtin.rs index cd62f54..b1a5536 100644 --- a/ast/src/builtin.rs +++ b/ast/src/builtin.rs @@ -13,16 +13,33 @@ impl Identifier { pub fn new(s: impl Into) -> Self { Self(s.into()) } +} + +impl std::cmp::PartialEq for Identifier { #[inline] - pub fn as_str(&self) -> &str { - self.0.as_str() + fn eq(&self, other: &str) -> bool { + self.0 == other } } -impl std::string::ToString for Identifier { +impl std::cmp::PartialEq for Identifier { #[inline] - fn to_string(&self) -> String { - self.0.clone() + fn eq(&self, other: &String) -> bool { + &self.0 == other + } +} + +impl std::ops::Deref for Identifier { + type Target = String; + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl std::fmt::Display for Identifier { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) } } @@ -33,24 +50,46 @@ impl From for String { } } -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +impl From for Identifier { + #[inline] + fn from(id: String) -> Self { + Self(id) + } +} + +impl<'a> From<&'a str> for Identifier { + #[inline] + fn from(id: &'a str) -> Identifier { + id.to_owned().into() + } +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Int(u32); impl Int { pub fn new(i: u32) -> Self { Self(i) } - pub fn new_bool(i: bool) -> Self { - Self(i as u32) - } pub fn to_u32(&self) -> u32 { self.0 } pub fn to_usize(&self) -> usize { self.0 as _ } - pub fn to_bool(&self) -> bool { - self.0 > 0 +} + +impl std::cmp::PartialEq for Int { + #[inline] + fn eq(&self, other: &u32) -> bool { + self.0 == *other + } +} + +impl std::cmp::PartialEq for Int { + #[inline] + fn eq(&self, other: &usize) -> bool { + self.0 as usize == *other } } @@ -165,11 +204,11 @@ impl Attributed { impl Attributed { /// Creates a new node that spans the position specified by `range`. - pub fn new(range: impl Into, node: T) -> Self { + pub fn new(range: impl Into, node: impl Into) -> Self { Self { range: range.into(), custom: (), - node, + node: node.into(), } } diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 2bd6fef..fbc12bd 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -8,7 +8,7 @@ mod generic { include!("gen/generic.rs"); } mod impls; -#[cfg(feature = "source-code")] +#[cfg(feature = "location")] mod source_locator; #[cfg(feature = "unparse")] mod unparse; @@ -32,11 +32,12 @@ mod visitor { include!("gen/visitor.rs"); } -#[cfg(feature = "source-code")] +#[cfg(feature = "location")] pub mod located { include!("gen/located.rs"); } +#[cfg(feature = "location")] pub use rustpython_parser_core::source_code; #[cfg(feature = "visitor")] pub use visitor::Visitor; diff --git a/core/Cargo.toml b/core/Cargo.toml index 8269c44..c0c31e3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -20,5 +20,5 @@ serde = { version = "1.0.133", optional = true, default-features = false, featur lz4_flex = "0.9.2" [features] -default = ["source-code"] -source-code = ["ruff_source_location"] +default = [] +location = ["ruff_source_location"] diff --git a/core/src/lib.rs b/core/src/lib.rs index 5608dbd..06b2d3b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -4,7 +4,7 @@ mod error; mod format; pub mod mode; -#[cfg(feature = "source-code")] +#[cfg(feature = "location")] pub mod source_code; pub use error::BaseError; diff --git a/literal/src/escape.rs b/literal/src/escape.rs index 921d3dc..80a105c 100644 --- a/literal/src/escape.rs +++ b/literal/src/escape.rs @@ -1,4 +1,4 @@ -#[derive(Debug, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum Quote { Single, Double, @@ -80,15 +80,21 @@ pub struct UnicodeEscape<'a> { } impl<'a> UnicodeEscape<'a> { + #[inline] pub fn with_forced_quote(source: &'a str, quote: Quote) -> Self { let layout = EscapeLayout { quote, len: None }; Self { source, layout } } - pub fn new_repr(source: &'a str) -> Self { - let layout = Self::repr_layout(source, Quote::Single); + #[inline] + pub fn with_preferred_quote(source: &'a str, quote: Quote) -> Self { + let layout = Self::repr_layout(source, quote); Self { source, layout } } - + #[inline] + pub fn new_repr(source: &'a str) -> Self { + Self::with_preferred_quote(source, Quote::Single) + } + #[inline] pub fn str_repr<'r>(&'a self) -> StrRepr<'r, 'a> { StrRepr(self) } @@ -265,18 +271,25 @@ pub struct AsciiEscape<'a> { } impl<'a> AsciiEscape<'a> { + #[inline] pub fn new(source: &'a [u8], layout: EscapeLayout) -> Self { Self { source, layout } } + #[inline] pub fn with_forced_quote(source: &'a [u8], quote: Quote) -> Self { let layout = EscapeLayout { quote, len: None }; Self { source, layout } } - pub fn new_repr(source: &'a [u8]) -> Self { - let layout = Self::repr_layout(source, Quote::Single); + #[inline] + pub fn with_preferred_quote(source: &'a [u8], quote: Quote) -> Self { + let layout = Self::repr_layout(source, quote); Self { source, layout } } - + #[inline] + pub fn new_repr(source: &'a [u8]) -> Self { + Self::with_preferred_quote(source, Quote::Single) + } + #[inline] pub fn bytes_repr<'r>(&'a self) -> BytesRepr<'r, 'a> { BytesRepr(self) } diff --git a/parser/Cargo.toml b/parser/Cargo.toml index dd9cb54..8d89cf3 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -9,7 +9,8 @@ license = "MIT" edition = "2021" [features] -default = [] +default = ["location"] +location = ["rustpython-ast/location"] serde = ["dep:serde", "rustpython-parser-core/serde"] [build-dependencies] diff --git a/parser/src/lib.rs b/parser/src/lib.rs index dc5f91e..6268d07 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -113,7 +113,9 @@ #![doc(html_root_url = "https://docs.rs/rustpython-parser/")] pub use rustpython_ast as ast; -pub use rustpython_parser_core::{source_code, text_size, Mode}; +#[cfg(feature = "location")] +pub use rustpython_parser_core::source_code; +pub use rustpython_parser_core::{text_size, Mode}; mod function; // Skip flattening lexer to distinguish from full parser diff --git a/parser/src/python.lalrpop b/parser/src/python.lalrpop index 096c4a6..a72c88e 100644 --- a/parser/src/python.lalrpop +++ b/parser/src/python.lalrpop @@ -81,7 +81,7 @@ DelStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtDelete { targets: targets.into_iter().map(|expr| set_context(expr, ast::ExprContext::Del)).collect() }.into() + ast::StmtDelete { targets: targets.into_iter().map(|expr| set_context(expr, ast::ExprContext::Del)).collect() } ) }, }; @@ -93,7 +93,7 @@ ExpressionStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtExpr { value: Box::new(expression) }.into() + ast::StmtExpr { value: Box::new(expression) } ) } else { let mut targets = vec![set_context(expression, ast::ExprContext::Store)]; @@ -108,7 +108,7 @@ ExpressionStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtAssign { targets, value, type_comment: None }.into() + ast::StmtAssign { targets, value, type_comment: None } ) } }, @@ -120,7 +120,7 @@ ExpressionStatement: ast::Stmt = { target: Box::new(set_context(target, ast::ExprContext::Store)), op, value: Box::new(rhs) - }.into(), + }, ) }, > ":" > => { @@ -133,7 +133,7 @@ ExpressionStatement: ast::Stmt = { annotation: Box::new(annotation), value: rhs.map(Box::new), simple, - }.into(), + }, ) }, }; @@ -203,14 +203,14 @@ FlowStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtReturn { value: value.map(Box::new) }.into() + ast::StmtReturn { value: value.map(Box::new) } ) }, => { ast::Stmt::new( location.. end_location, - ast::StmtExpr { value: Box::new(expression) }.into() + ast::StmtExpr { value: Box::new(expression) } ) }, RaiseStatement, @@ -221,14 +221,14 @@ RaiseStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtRaise { exc: None, cause: None }.into() + ast::StmtRaise { exc: None, cause: None } ) }, "raise" > )?> => { ast::Stmt::new( location.. end_location, - ast::StmtRaise { exc: Some(Box::new(t)), cause: c.map(|x| Box::new(x.1)) }.into() + ast::StmtRaise { exc: Some(Box::new(t)), cause: c.map(|x| Box::new(x.1)) } ) }, }; @@ -238,7 +238,7 @@ ImportStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtImport { names }.into() + ast::StmtImport { names } ) }, "from" "import" => { @@ -250,7 +250,7 @@ ImportStatement: ast::Stmt = { level, module, names - }.into(), + }, ) }, }; @@ -302,7 +302,7 @@ GlobalStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtGlobal { names }.into() + ast::StmtGlobal { names } ) }, }; @@ -312,7 +312,7 @@ NonlocalStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtNonlocal { names }.into() + ast::StmtNonlocal { names } ) }, }; @@ -325,7 +325,7 @@ AssertStatement: ast::Stmt = { ast::StmtAssert { test: Box::new(test), msg: msg.map(|e| Box::new(e.1)) - }.into() + } ) }, }; @@ -356,7 +356,7 @@ MatchStatement: ast::Stmt = { ast::StmtMatch { subject: Box::new(subject), cases - }.into() + } ) }, "match" "," ":" "\n" Indent Dedent => { @@ -373,7 +373,7 @@ MatchStatement: ast::Stmt = { ast::StmtMatch { subject: Box::new(subject), cases - }.into() + } ) }, "match" "," > ","? ":" "\n" Indent Dedent => { @@ -396,10 +396,10 @@ MatchStatement: ast::Stmt = { ast::ExprTuple { elts: subjects, ctx: ast::ExprContext::Load, - }.into(), + }, )), cases - }.into() + } ) } } @@ -426,7 +426,7 @@ Patterns: ast::Pattern = { end_location, ast::PatternMatchSequence { patterns: vec![pattern] - }.into(), + }, ), "," > ","? => { let mut patterns = patterns; @@ -436,7 +436,7 @@ Patterns: ast::Pattern = { end_location, ast::PatternMatchSequence { patterns - }.into(), + }, ) }, => pattern @@ -461,7 +461,7 @@ AsPattern: ast::Pattern = { ast::PatternMatchAs { pattern: Some(Box::new(pattern)), name: Some(name), - }.into(), + }, )) } }, @@ -475,7 +475,7 @@ OrPattern: ast::Pattern = { ast::Pattern::new( location.. end_location, - ast::PatternMatchOr { patterns }.into() + ast::PatternMatchOr { patterns } ) } } @@ -546,7 +546,7 @@ ConstantAtom: ast::Expr = { => ast::Expr::new( location.. end_location, - ast::ExprConstant { value, kind: None }.into() + ast::ExprConstant { value, kind: None } ), } @@ -558,7 +558,7 @@ ConstantExpr: ast::Expr = { ast::ExprUnaryOp { op: ast::Unaryop::USub, operand: Box::new(operand) - }.into() + } ), } @@ -570,7 +570,7 @@ AddOpExpr: ast::Expr = { left: Box::new(left), op, right: Box::new(right), - }.into() + } ), } @@ -606,7 +606,7 @@ MatchName: ast::Expr = { => ast::Expr::new( location.. end_location, - ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into(), + ast::ExprName { id: name, ctx: ast::ExprContext::Load }, ), } @@ -618,7 +618,7 @@ MatchNameOrAttr: ast::Expr = { value: Box::new(name), attr, ctx: ast::ExprContext::Load, - }.into(), + }, ), "." => ast::Expr::new( location.. @@ -627,7 +627,7 @@ MatchNameOrAttr: ast::Expr = { value: Box::new(e), attr, ctx: ast::ExprContext::Load, - }.into(), + }, ) } @@ -647,7 +647,7 @@ MappingKey: ast::Expr = { ast::ExprConstant { value: ast::Constant::None, kind: None, - }.into(), + }, ), "True" => ast::Expr::new( location.. @@ -655,7 +655,7 @@ MappingKey: ast::Expr = { ast::ExprConstant { value: true.into(), kind: None, - }.into(), + }, ), "False" => ast::Expr::new( location.. @@ -663,7 +663,7 @@ MappingKey: ast::Expr = { ast::ExprConstant { value: false.into(), kind: None, - }.into(), + }, ), =>? Ok(parse_strings(s)?), } @@ -807,7 +807,7 @@ IfStatement: ast::Stmt = { let x = ast::Stmt::new( i.0.. end_location, - ast::StmtIf { test: Box::new(i.2), body: i.4, orelse: last }.into() + ast::StmtIf { test: Box::new(i.2), body: i.4, orelse: last } ); last = vec![x]; } @@ -815,7 +815,7 @@ IfStatement: ast::Stmt = { ast::Stmt::new( location.. end_location, - ast::StmtIf { test: Box::new(test), body, orelse: last }.into() + ast::StmtIf { test: Box::new(test), body, orelse: last } ) }, }; @@ -835,7 +835,7 @@ WhileStatement: ast::Stmt = { test: Box::new(test), body, orelse - }.into(), + }, ) }, }; @@ -851,7 +851,7 @@ ForStatement: ast::Stmt = { let target = Box::new(set_context(target, ast::ExprContext::Store)); let iter = Box::new(iter); let type_comment = None; - let node = if is_async.is_some() { + let node: ast::StmtKind = if is_async.is_some() { ast::StmtAsyncFor { target, iter, body, orelse, type_comment }.into() } else { ast::StmtFor { target, iter, body, orelse, type_comment }.into() @@ -878,7 +878,7 @@ TryStatement: ast::Stmt = { handlers, orelse, finalbody, - }.into(), + }, ) }, "try" ":" => { @@ -898,7 +898,7 @@ TryStatement: ast::Stmt = { handlers, orelse, finalbody, - }.into(), + }, ) }, "try" ":" => { @@ -914,7 +914,7 @@ TryStatement: ast::Stmt = { handlers, orelse, finalbody, - }.into(), + }, ) }, }; @@ -929,7 +929,7 @@ ExceptStarClause: ast::Excepthandler = { type_: Some(Box::new(typ)), name: None, body, - }.into(), + }, ) }, "except" "*" "as" Identifier)> ":" => { @@ -941,7 +941,7 @@ ExceptStarClause: ast::Excepthandler = { type_: Some(Box::new(x.0)), name: Some(x.2), body, - }.into(), + }, ) }, }; @@ -957,7 +957,7 @@ ExceptClause: ast::Excepthandler = { type_: typ.map(Box::new), name: None, body, - }.into(), + }, ) }, "except" "as" Identifier)> ":" => { @@ -969,7 +969,7 @@ ExceptClause: ast::Excepthandler = { type_: Some(Box::new(x.0)), name: Some(x.2), body, - }.into(), + }, ) }, }; @@ -978,7 +978,7 @@ WithStatement: ast::Stmt = { "with" ":" => { let end_location = body.last().unwrap().end(); let type_comment = None; - let node = if is_async.is_some() { + let node: ast::StmtKind = if is_async.is_some() { ast::StmtAsyncWith { items, body, type_comment }.into() } else { ast::StmtWith { items, body, type_comment }.into() @@ -1019,7 +1019,7 @@ FuncDef: ast::Stmt = { let returns = r.map(|x| Box::new(x.1)); let end_location = body.last().unwrap().end(); let type_comment = None; - let node = if is_async.is_some() { + let node: ast::StmtKind = if is_async.is_some() { ast::StmtAsyncFunctionDef { name, args, body, decorator_list, returns, type_comment }.into() } else { ast::StmtFunctionDef { name, args, body, decorator_list, returns, type_comment }.into() @@ -1202,7 +1202,7 @@ ClassDef: ast::Stmt = { keywords, body, decorator_list, - }.into(), + }, ) }, }; @@ -1218,12 +1218,12 @@ YieldExpr: ast::Expr = { "yield" => ast::Expr::new( location.. end_location, - ast::ExprYield { value: value.map(Box::new) }.into() + ast::ExprYield { value: value.map(Box::new) } ), "yield" "from" > => ast::Expr::new( location.. end_location, - ast::ExprYieldFrom { value: Box::new(e) }.into() + ast::ExprYieldFrom { value: Box::new(e) } ), }; @@ -1235,7 +1235,7 @@ Test: ast::Expr = { test: Box::new(test), body: Box::new(body), orelse: Box::new(orelse), - }.into() + } ), OrTest, LambdaDef, @@ -1255,10 +1255,10 @@ NamedExpression: ast::Expr = { target: Box::new(ast::Expr::new( location.. end_location, - ast::ExprName { id, ctx: ast::ExprContext::Store }.into(), + ast::ExprName { id, ctx: ast::ExprContext::Store }, )), value: Box::new(value), - }.into() + } ) }, }; @@ -1285,7 +1285,7 @@ LambdaDef: ast::Expr = { ast::ExprLambda { args: Box::new(p), body: Box::new(body) - }.into() + } )) } } @@ -1297,7 +1297,7 @@ OrTest: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprBoolOp { op: ast::Boolop::Or, values }.into() + ast::ExprBoolOp { op: ast::Boolop::Or, values } ) }, AndTest, @@ -1310,7 +1310,7 @@ AndTest: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprBoolOp { op: ast::Boolop::And, values }.into() + ast::ExprBoolOp { op: ast::Boolop::And, values } ) }, NotTest, @@ -1320,7 +1320,7 @@ NotTest: ast::Expr = { "not" > => ast::Expr::new( location.. end_location, - ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not }.into() + ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not } ), Comparison, }; @@ -1331,7 +1331,7 @@ Comparison: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprCompare { left: Box::new(left), ops, comparators }.into() + ast::ExprCompare { left: Box::new(left), ops, comparators } ) }, Expression, @@ -1354,7 +1354,7 @@ Expression: ast::Expr = { > "|" > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) } ), XorExpression, }; @@ -1363,7 +1363,7 @@ XorExpression: ast::Expr = { > "^" > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) } ), AndExpression, }; @@ -1372,7 +1372,7 @@ AndExpression: ast::Expr = { > "&" > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) } ), ShiftExpression, }; @@ -1381,7 +1381,7 @@ ShiftExpression: ast::Expr = { > > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) } ), ArithmeticExpression, }; @@ -1395,7 +1395,7 @@ ArithmeticExpression: ast::Expr = { > > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) } ), Term, }; @@ -1409,7 +1409,7 @@ Term: ast::Expr = { > > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) } ), Factor, }; @@ -1426,7 +1426,7 @@ Factor: ast::Expr = { > => ast::Expr::new( location.. end_location, - ast::ExprUnaryOp { operand: Box::new(e), op }.into() + ast::ExprUnaryOp { operand: Box::new(e), op } ), Power, }; @@ -1441,7 +1441,7 @@ Power: ast::Expr = { > "**" > => ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) } ), AtomExpr, }; @@ -1451,7 +1451,7 @@ AtomExpr: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprAwait { value: Box::new(atom) }.into() + ast::ExprAwait { value: Box::new(atom) } ) }, AtomExpr2, @@ -1463,18 +1463,18 @@ AtomExpr2: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords }.into() + ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords } ) }, > "[" "]" => ast::Expr::new( location.. end_location, - ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load }.into() + ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load } ), > "." => ast::Expr::new( location.. end_location, - ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load }.into() + ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load } ), }; @@ -1491,7 +1491,7 @@ SubscriptList: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprTuple { elts: dims, ctx: ast::ExprContext::Load }.into(), + ast::ExprTuple { elts: dims, ctx: ast::ExprContext::Load }, ) } } @@ -1506,7 +1506,7 @@ Subscript: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprSlice { lower, upper, step }.into() + ast::ExprSlice { lower, upper, step } ) } }; @@ -1520,26 +1520,26 @@ Atom: ast::Expr = { => ast::Expr::new( location.. end_location, - ast::ExprConstant { value, kind: None }.into() + ast::ExprConstant { value, kind: None } ), => ast::Expr::new( location.. end_location, - ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into() + ast::ExprName { id: name, ctx: ast::ExprContext::Load } ), "[" "]" => { let elts = e.unwrap_or_default(); ast::Expr::new( location.. end_location, - ast::ExprList { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprList { elts, ctx: ast::ExprContext::Load } ) }, "[" "]" => { ast::Expr::new( location.. end_location, - ast::ExprListComp { elt: Box::new(elt), generators }.into() + ast::ExprListComp { elt: Box::new(elt), generators } ) }, "(" >> ")" if Goal != "no-withitems" => { @@ -1549,7 +1549,7 @@ Atom: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts, ctx: ast::ExprContext::Load } ) } }, @@ -1567,21 +1567,21 @@ Atom: ast::Expr = { Ok(ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into(), + ast::ExprTuple { elts, ctx: ast::ExprContext::Load }, )) } }, "(" ")" => ast::Expr::new( location.. end_location, - ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load } ), "(" ")" => e, "(" ")" => { ast::Expr::new( location.. end_location, - ast::ExprGeneratorExp { elt: Box::new(elt), generators }.into() + ast::ExprGeneratorExp { elt: Box::new(elt), generators } ) }, "(" "**" > ")" =>? { @@ -1599,7 +1599,7 @@ Atom: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprDict { keys, values }.into() + ast::ExprDict { keys, values } ) }, "{" "}" => { @@ -1610,25 +1610,25 @@ Atom: ast::Expr = { key: Box::new(e1.0), value: Box::new(e1.1), generators, - }.into() + } ) }, "{" "}" => ast::Expr::new( location.. end_location, - ast::ExprSet { elts }.into() + ast::ExprSet { elts } ), "{" "}" => { ast::Expr::new( location.. end_location, - ast::ExprSetComp { elt: Box::new(elt), generators }.into() + ast::ExprSetComp { elt: Box::new(elt), generators } ) }, - "True" => ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }.into()), - "False" => ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }.into()), - "None" => ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }.into()), - "..." => ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }.into()), + "True" => ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }), + "False" => ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }), + "None" => ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }), + "..." => ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }), }; ListLiteralValues: Vec = { @@ -1682,7 +1682,7 @@ GenericList: ast::Expr = { ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts, ctx: ast::ExprContext::Load } ) } } @@ -1693,7 +1693,7 @@ StarExpr: ast::Expr = { "*" > => ast::Expr::new( location.. end_location, - ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }.into(), + ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }, ) }; @@ -1730,7 +1730,7 @@ FunctionArgument: (Option<(TextSize, TextSize, Option)>, ast::E ast::ExprGeneratorExp { elt: Box::new(e), generators: c, - }.into() + } ), None => e, }; @@ -1741,7 +1741,7 @@ FunctionArgument: (Option<(TextSize, TextSize, Option)>, ast::E let expr = ast::Expr::new( location.. end_location, - ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }.into(), + ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }, ); (None, expr) }, diff --git a/parser/src/python.rs b/parser/src/python.rs index 1781a94..fe34e85 100644 --- a/parser/src/python.rs +++ b/parser/src/python.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.20.0" -// sha3: 0198c5dceea306627c61f209b8fb7f17dffba455b06a7ba59f55447f864b84db +// sha3: 94b68331f7fbb668c2e962084095e319cfff9ba09cd78a361c735e7e60c57497 use crate::{ ast, lexer::{LexicalError, LexicalErrorType}, @@ -36842,7 +36842,7 @@ fn __action21< ast::Stmt::new( location.. end_location, - ast::StmtDelete { targets: targets.into_iter().map(|expr| set_context(expr, ast::ExprContext::Del)).collect() }.into() + ast::StmtDelete { targets: targets.into_iter().map(|expr| set_context(expr, ast::ExprContext::Del)).collect() } ) } } @@ -36862,7 +36862,7 @@ fn __action22< ast::Stmt::new( location.. end_location, - ast::StmtExpr { value: Box::new(expression) }.into() + ast::StmtExpr { value: Box::new(expression) } ) } else { let mut targets = vec![set_context(expression, ast::ExprContext::Store)]; @@ -36877,7 +36877,7 @@ fn __action22< ast::Stmt::new( location.. end_location, - ast::StmtAssign { targets, value, type_comment: None }.into() + ast::StmtAssign { targets, value, type_comment: None } ) } } @@ -36901,7 +36901,7 @@ fn __action23< target: Box::new(set_context(target, ast::ExprContext::Store)), op, value: Box::new(rhs) - }.into(), + }, ) } } @@ -36927,7 +36927,7 @@ fn __action24< annotation: Box::new(annotation), value: rhs.map(Box::new), simple, - }.into(), + }, ) } } @@ -37187,7 +37187,7 @@ fn __action50< ast::Stmt::new( location.. end_location, - ast::StmtReturn { value: value.map(Box::new) }.into() + ast::StmtReturn { value: value.map(Box::new) } ) } } @@ -37204,7 +37204,7 @@ fn __action51< ast::Stmt::new( location.. end_location, - ast::StmtExpr { value: Box::new(expression) }.into() + ast::StmtExpr { value: Box::new(expression) } ) } } @@ -37230,7 +37230,7 @@ fn __action53< ast::Stmt::new( location.. end_location, - ast::StmtRaise { exc: None, cause: None }.into() + ast::StmtRaise { exc: None, cause: None } ) } } @@ -37249,7 +37249,7 @@ fn __action54< ast::Stmt::new( location.. end_location, - ast::StmtRaise { exc: Some(Box::new(t)), cause: c.map(|x| Box::new(x.1)) }.into() + ast::StmtRaise { exc: Some(Box::new(t)), cause: c.map(|x| Box::new(x.1)) } ) } } @@ -37267,7 +37267,7 @@ fn __action55< ast::Stmt::new( location.. end_location, - ast::StmtImport { names }.into() + ast::StmtImport { names } ) } } @@ -37292,7 +37292,7 @@ fn __action56< level, module, names - }.into(), + }, ) } } @@ -37416,7 +37416,7 @@ fn __action66< ast::Stmt::new( location.. end_location, - ast::StmtGlobal { names }.into() + ast::StmtGlobal { names } ) } } @@ -37434,7 +37434,7 @@ fn __action67< ast::Stmt::new( location.. end_location, - ast::StmtNonlocal { names }.into() + ast::StmtNonlocal { names } ) } } @@ -37456,7 +37456,7 @@ fn __action68< ast::StmtAssert { test: Box::new(test), msg: msg.map(|e| Box::new(e.1)) - }.into() + } ) } } @@ -37560,7 +37560,7 @@ fn __action77< ast::StmtMatch { subject: Box::new(subject), cases - }.into() + } ) } } @@ -37593,7 +37593,7 @@ fn __action78< ast::StmtMatch { subject: Box::new(subject), cases - }.into() + } ) } } @@ -37634,10 +37634,10 @@ fn __action79< ast::ExprTuple { elts: subjects, ctx: ast::ExprContext::Load, - }.into(), + }, )), cases - }.into() + } ) } } @@ -37687,7 +37687,7 @@ fn __action82< end_location, ast::PatternMatchSequence { patterns: vec![pattern] - }.into(), + }, ) } @@ -37710,7 +37710,7 @@ fn __action83< end_location, ast::PatternMatchSequence { patterns - }.into(), + }, ) } } @@ -37765,7 +37765,7 @@ fn __action87< ast::PatternMatchAs { pattern: Some(Box::new(pattern)), name: Some(name), - }.into(), + }, )) } } @@ -37795,7 +37795,7 @@ fn __action89< ast::Pattern::new( location.. end_location, - ast::PatternMatchOr { patterns }.into() + ast::PatternMatchOr { patterns } ) } } @@ -37993,7 +37993,7 @@ fn __action102< ast::Expr::new( location.. end_location, - ast::ExprConstant { value, kind: None }.into() + ast::ExprConstant { value, kind: None } ) } @@ -38021,7 +38021,7 @@ fn __action104< ast::ExprUnaryOp { op: ast::Unaryop::USub, operand: Box::new(operand) - }.into() + } ) } @@ -38042,7 +38042,7 @@ fn __action105< left: Box::new(left), op, right: Box::new(right), - }.into() + } ) } @@ -38141,7 +38141,7 @@ fn __action113< ast::Expr::new( location.. end_location, - ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into(), + ast::ExprName { id: name, ctx: ast::ExprContext::Load }, ) } @@ -38162,7 +38162,7 @@ fn __action114< value: Box::new(name), attr, ctx: ast::ExprContext::Load, - }.into(), + }, ) } @@ -38183,7 +38183,7 @@ fn __action115< value: Box::new(e), attr, ctx: ast::ExprContext::Load, - }.into(), + }, ) } @@ -38239,7 +38239,7 @@ fn __action120< ast::ExprConstant { value: ast::Constant::None, kind: None, - }.into(), + }, ) } @@ -38257,7 +38257,7 @@ fn __action121< ast::ExprConstant { value: true.into(), kind: None, - }.into(), + }, ) } @@ -38275,7 +38275,7 @@ fn __action122< ast::ExprConstant { value: false.into(), kind: None, - }.into(), + }, ) } @@ -38613,7 +38613,7 @@ fn __action138< let x = ast::Stmt::new( i.0.. end_location, - ast::StmtIf { test: Box::new(i.2), body: i.4, orelse: last }.into() + ast::StmtIf { test: Box::new(i.2), body: i.4, orelse: last } ); last = vec![x]; } @@ -38621,7 +38621,7 @@ fn __action138< ast::Stmt::new( location.. end_location, - ast::StmtIf { test: Box::new(test), body, orelse: last }.into() + ast::StmtIf { test: Box::new(test), body, orelse: last } ) } } @@ -38651,7 +38651,7 @@ fn __action139< test: Box::new(test), body, orelse - }.into(), + }, ) } } @@ -38680,7 +38680,7 @@ fn __action140< let target = Box::new(set_context(target, ast::ExprContext::Store)); let iter = Box::new(iter); let type_comment = None; - let node = if is_async.is_some() { + let node: ast::StmtKind = if is_async.is_some() { ast::StmtAsyncFor { target, iter, body, orelse, type_comment }.into() } else { ast::StmtFor { target, iter, body, orelse, type_comment }.into() @@ -38719,7 +38719,7 @@ fn __action141< handlers, orelse, finalbody, - }.into(), + }, ) } } @@ -38754,7 +38754,7 @@ fn __action142< handlers, orelse, finalbody, - }.into(), + }, ) } } @@ -38782,7 +38782,7 @@ fn __action143< handlers, orelse, finalbody, - }.into(), + }, ) } } @@ -38807,7 +38807,7 @@ fn __action144< type_: Some(Box::new(typ)), name: None, body, - }.into(), + }, ) } } @@ -38832,7 +38832,7 @@ fn __action145< type_: Some(Box::new(x.0)), name: Some(x.2), body, - }.into(), + }, ) } } @@ -38856,7 +38856,7 @@ fn __action146< type_: typ.map(Box::new), name: None, body, - }.into(), + }, ) } } @@ -38880,7 +38880,7 @@ fn __action147< type_: Some(Box::new(x.0)), name: Some(x.2), body, - }.into(), + }, ) } } @@ -38899,7 +38899,7 @@ fn __action148< { let end_location = body.last().unwrap().end(); let type_comment = None; - let node = if is_async.is_some() { + let node: ast::StmtKind = if is_async.is_some() { ast::StmtAsyncWith { items, body, type_comment }.into() } else { ast::StmtWith { items, body, type_comment }.into() @@ -38987,7 +38987,7 @@ fn __action154< let returns = r.map(|x| Box::new(x.1)); let end_location = body.last().unwrap().end(); let type_comment = None; - let node = if is_async.is_some() { + let node: ast::StmtKind = if is_async.is_some() { ast::StmtAsyncFunctionDef { name, args, body, decorator_list, returns, type_comment }.into() } else { ast::StmtFunctionDef { name, args, body, decorator_list, returns, type_comment }.into() @@ -39093,7 +39093,7 @@ fn __action159< keywords, body, decorator_list, - }.into(), + }, ) } } @@ -39124,7 +39124,7 @@ fn __action161< ast::Expr::new( location.. end_location, - ast::ExprYield { value: value.map(Box::new) }.into() + ast::ExprYield { value: value.map(Box::new) } ) } @@ -39141,7 +39141,7 @@ fn __action162< ast::Expr::new( location.. end_location, - ast::ExprYieldFrom { value: Box::new(e) }.into() + ast::ExprYieldFrom { value: Box::new(e) } ) } @@ -39181,10 +39181,10 @@ fn __action165< target: Box::new(ast::Expr::new( location.. end_location, - ast::ExprName { id, ctx: ast::ExprContext::Store }.into(), + ast::ExprName { id, ctx: ast::ExprContext::Store }, )), value: Box::new(value), - }.into() + } ) } } @@ -39221,7 +39221,7 @@ fn __action166< ast::ExprLambda { args: Box::new(p), body: Box::new(body) - }.into() + } )) } } @@ -39448,7 +39448,7 @@ fn __action189< ast::Expr::new( location.. end_location, - ast::ExprTuple { elts: dims, ctx: ast::ExprContext::Load }.into(), + ast::ExprTuple { elts: dims, ctx: ast::ExprContext::Load }, ) } } @@ -39481,7 +39481,7 @@ fn __action191< ast::Expr::new( location.. end_location, - ast::ExprSlice { lower, upper, step }.into() + ast::ExprSlice { lower, upper, step } ) } } @@ -39615,7 +39615,7 @@ fn __action204< ast::Expr::new( location.. end_location, - ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }.into(), + ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }, ) } @@ -39699,7 +39699,7 @@ fn __action210< ast::ExprGeneratorExp { elt: Box::new(e), generators: c, - }.into() + } ), None => e, }; @@ -39733,7 +39733,7 @@ fn __action212< let expr = ast::Expr::new( location.. end_location, - ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }.into(), + ast::ExprStarred { value: Box::new(e), ctx: ast::ExprContext::Load }, ); (None, expr) } @@ -39854,7 +39854,7 @@ fn __action223< ast::Expr::new( location.. end_location, - ast::ExprBoolOp { op: ast::Boolop::Or, values }.into() + ast::ExprBoolOp { op: ast::Boolop::Or, values } ) } } @@ -39903,7 +39903,7 @@ fn __action227< ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts, ctx: ast::ExprContext::Load } ) } } @@ -39939,7 +39939,7 @@ fn __action229< ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts, ctx: ast::ExprContext::Load } ) } } @@ -39958,7 +39958,7 @@ fn __action230< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) } ) } @@ -41181,7 +41181,7 @@ fn __action337< test: Box::new(test), body: Box::new(body), orelse: Box::new(orelse), - }.into() + } ) } @@ -41748,7 +41748,7 @@ fn __action395< test: Box::new(test), body: Box::new(body), orelse: Box::new(orelse), - }.into() + } ) } @@ -42099,7 +42099,7 @@ fn __action423< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) } ) } @@ -42199,7 +42199,7 @@ fn __action432< ast::Expr::new( location.. end_location, - ast::ExprBoolOp { op: ast::Boolop::And, values }.into() + ast::ExprBoolOp { op: ast::Boolop::And, values } ) } } @@ -42340,7 +42340,7 @@ fn __action446< ast::Expr::new( location.. end_location, - ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not }.into() + ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not } ) } @@ -42414,7 +42414,7 @@ fn __action453< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) } ) } @@ -42701,7 +42701,7 @@ fn __action481< ast::Expr::new( location.. end_location, - ast::ExprBoolOp { op: ast::Boolop::Or, values }.into() + ast::ExprBoolOp { op: ast::Boolop::Or, values } ) } } @@ -42882,7 +42882,7 @@ fn __action499< ast::Expr::new( location.. end_location, - ast::ExprBoolOp { op: ast::Boolop::And, values }.into() + ast::ExprBoolOp { op: ast::Boolop::And, values } ) } } @@ -42947,7 +42947,7 @@ fn __action505< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) } ) } @@ -42993,7 +42993,7 @@ fn __action509< ast::Expr::new( location.. end_location, - ast::ExprCompare { left: Box::new(left), ops, comparators }.into() + ast::ExprCompare { left: Box::new(left), ops, comparators } ) } } @@ -43049,7 +43049,7 @@ fn __action514< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) } ) } @@ -43074,7 +43074,7 @@ fn __action516< ast::Expr::new( location.. end_location, - ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not }.into() + ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not } ) } @@ -43101,7 +43101,7 @@ fn __action518< ast::Expr::new( location.. end_location, - ast::ExprCompare { left: Box::new(left), ops, comparators }.into() + ast::ExprCompare { left: Box::new(left), ops, comparators } ) } } @@ -43128,7 +43128,7 @@ fn __action520< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) } ) } @@ -43153,7 +43153,7 @@ fn __action522< ast::Expr::new( location.. end_location, - ast::ExprUnaryOp { operand: Box::new(e), op }.into() + ast::ExprUnaryOp { operand: Box::new(e), op } ) } @@ -43179,7 +43179,7 @@ fn __action524< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitOr, right: Box::new(e2) } ) } @@ -43205,7 +43205,7 @@ fn __action526< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitXor, right: Box::new(e2) } ) } @@ -43231,7 +43231,7 @@ fn __action528< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) } ) } @@ -43257,7 +43257,7 @@ fn __action530< ast::Expr::new( location.. end_location, - ast::ExprAwait { value: Box::new(atom) }.into() + ast::ExprAwait { value: Box::new(atom) } ) } } @@ -43284,7 +43284,7 @@ fn __action532< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op: ast::Operator::BitAnd, right: Box::new(e2) } ) } @@ -43310,7 +43310,7 @@ fn __action534< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) }.into() + ast::ExprBinOp { left: Box::new(e1), op, right: Box::new(e2) } ) } @@ -43347,7 +43347,7 @@ fn __action537< ast::Expr::new( location.. end_location, - ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords }.into() + ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords } ) } } @@ -43366,7 +43366,7 @@ fn __action538< ast::Expr::new( location.. end_location, - ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load }.into() + ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load } ) } @@ -43383,7 +43383,7 @@ fn __action539< ast::Expr::new( location.. end_location, - ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load }.into() + ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load } ) } @@ -43408,7 +43408,7 @@ fn __action541< ast::Expr::new( location.. end_location, - ast::ExprConstant { value, kind: None }.into() + ast::ExprConstant { value, kind: None } ) } @@ -43423,7 +43423,7 @@ fn __action542< ast::Expr::new( location.. end_location, - ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into() + ast::ExprName { id: name, ctx: ast::ExprContext::Load } ) } @@ -43442,7 +43442,7 @@ fn __action543< ast::Expr::new( location.. end_location, - ast::ExprList { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprList { elts, ctx: ast::ExprContext::Load } ) } } @@ -43462,7 +43462,7 @@ fn __action544< ast::Expr::new( location.. end_location, - ast::ExprListComp { elt: Box::new(elt), generators }.into() + ast::ExprListComp { elt: Box::new(elt), generators } ) } } @@ -43485,7 +43485,7 @@ fn __action545< ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts, ctx: ast::ExprContext::Load } ) } } @@ -43518,7 +43518,7 @@ fn __action546< Ok(ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into(), + ast::ExprTuple { elts, ctx: ast::ExprContext::Load }, )) } } @@ -43536,7 +43536,7 @@ fn __action547< ast::Expr::new( location.. end_location, - ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load } ) } @@ -43566,7 +43566,7 @@ fn __action549< ast::Expr::new( location.. end_location, - ast::ExprGeneratorExp { elt: Box::new(elt), generators }.into() + ast::ExprGeneratorExp { elt: Box::new(elt), generators } ) } } @@ -43609,7 +43609,7 @@ fn __action551< ast::Expr::new( location.. end_location, - ast::ExprDict { keys, values }.into() + ast::ExprDict { keys, values } ) } } @@ -43633,7 +43633,7 @@ fn __action552< key: Box::new(e1.0), value: Box::new(e1.1), generators, - }.into() + } ) } } @@ -43651,7 +43651,7 @@ fn __action553< ast::Expr::new( location.. end_location, - ast::ExprSet { elts }.into() + ast::ExprSet { elts } ) } @@ -43670,7 +43670,7 @@ fn __action554< ast::Expr::new( location.. end_location, - ast::ExprSetComp { elt: Box::new(elt), generators }.into() + ast::ExprSetComp { elt: Box::new(elt), generators } ) } } @@ -43683,7 +43683,7 @@ fn __action555< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }) } #[allow(clippy::too_many_arguments)] @@ -43694,7 +43694,7 @@ fn __action556< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }) } #[allow(clippy::too_many_arguments)] @@ -43705,7 +43705,7 @@ fn __action557< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }) } #[allow(clippy::too_many_arguments)] @@ -43716,7 +43716,7 @@ fn __action558< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }) } #[allow(clippy::too_many_arguments)] @@ -43732,7 +43732,7 @@ fn __action559< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) } ) } @@ -43758,7 +43758,7 @@ fn __action561< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(a), op, right: Box::new(b) } ) } @@ -43898,7 +43898,7 @@ fn __action575< ast::Expr::new( location.. end_location, - ast::ExprUnaryOp { operand: Box::new(e), op }.into() + ast::ExprUnaryOp { operand: Box::new(e), op } ) } @@ -43924,7 +43924,7 @@ fn __action577< ast::Expr::new( location.. end_location, - ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) }.into() + ast::ExprBinOp { left: Box::new(e), op: ast::Operator::Pow, right: Box::new(b) } ) } @@ -43950,7 +43950,7 @@ fn __action579< ast::Expr::new( location.. end_location, - ast::ExprAwait { value: Box::new(atom) }.into() + ast::ExprAwait { value: Box::new(atom) } ) } } @@ -43988,7 +43988,7 @@ fn __action582< ast::Expr::new( location.. end_location, - ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords }.into() + ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords } ) } } @@ -44007,7 +44007,7 @@ fn __action583< ast::Expr::new( location.. end_location, - ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load }.into() + ast::ExprSubscript { value: Box::new(e), slice: Box::new(s), ctx: ast::ExprContext::Load } ) } @@ -44024,7 +44024,7 @@ fn __action584< ast::Expr::new( location.. end_location, - ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load }.into() + ast::ExprAttribute { value: Box::new(e), attr, ctx: ast::ExprContext::Load } ) } @@ -44049,7 +44049,7 @@ fn __action586< ast::Expr::new( location.. end_location, - ast::ExprConstant { value, kind: None }.into() + ast::ExprConstant { value, kind: None } ) } @@ -44064,7 +44064,7 @@ fn __action587< ast::Expr::new( location.. end_location, - ast::ExprName { id: name, ctx: ast::ExprContext::Load }.into() + ast::ExprName { id: name, ctx: ast::ExprContext::Load } ) } @@ -44083,7 +44083,7 @@ fn __action588< ast::Expr::new( location.. end_location, - ast::ExprList { elts, ctx: ast::ExprContext::Load }.into() + ast::ExprList { elts, ctx: ast::ExprContext::Load } ) } } @@ -44103,7 +44103,7 @@ fn __action589< ast::Expr::new( location.. end_location, - ast::ExprListComp { elt: Box::new(elt), generators }.into() + ast::ExprListComp { elt: Box::new(elt), generators } ) } } @@ -44135,7 +44135,7 @@ fn __action590< Ok(ast::Expr::new( location.. end_location, - ast::ExprTuple { elts, ctx: ast::ExprContext::Load }.into(), + ast::ExprTuple { elts, ctx: ast::ExprContext::Load }, )) } } @@ -44153,7 +44153,7 @@ fn __action591< ast::Expr::new( location.. end_location, - ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load }.into() + ast::ExprTuple { elts: Vec::new(), ctx: ast::ExprContext::Load } ) } @@ -44183,7 +44183,7 @@ fn __action593< ast::Expr::new( location.. end_location, - ast::ExprGeneratorExp { elt: Box::new(elt), generators }.into() + ast::ExprGeneratorExp { elt: Box::new(elt), generators } ) } } @@ -44226,7 +44226,7 @@ fn __action595< ast::Expr::new( location.. end_location, - ast::ExprDict { keys, values }.into() + ast::ExprDict { keys, values } ) } } @@ -44250,7 +44250,7 @@ fn __action596< key: Box::new(e1.0), value: Box::new(e1.1), generators, - }.into() + } ) } } @@ -44268,7 +44268,7 @@ fn __action597< ast::Expr::new( location.. end_location, - ast::ExprSet { elts }.into() + ast::ExprSet { elts } ) } @@ -44287,7 +44287,7 @@ fn __action598< ast::Expr::new( location.. end_location, - ast::ExprSetComp { elt: Box::new(elt), generators }.into() + ast::ExprSetComp { elt: Box::new(elt), generators } ) } } @@ -44300,7 +44300,7 @@ fn __action599< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: true.into(), kind: None }) } #[allow(clippy::too_many_arguments)] @@ -44311,7 +44311,7 @@ fn __action600< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: false.into(), kind: None }) } #[allow(clippy::too_many_arguments)] @@ -44322,7 +44322,7 @@ fn __action601< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::None, kind: None }) } #[allow(clippy::too_many_arguments)] @@ -44333,7 +44333,7 @@ fn __action602< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::Expr { - ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }.into()) + ast::Expr::new(location..end_location, ast::ExprConstant { value: ast::Constant::Ellipsis, kind: None }) } #[allow(clippy::too_many_arguments)] diff --git a/parser/src/string.rs b/parser/src/string.rs index 532fae5..d809797 100644 --- a/parser/src/string.rs +++ b/parser/src/string.rs @@ -629,8 +629,7 @@ pub(crate) fn parse_strings( ast::ExprConstant { value: Constant::Bytes(content), kind: None, - } - .into(), + }, )); } @@ -652,8 +651,7 @@ pub(crate) fn parse_strings( ast::ExprConstant { value: Constant::Str(content.join("")), kind: initial_kind, - } - .into(), + }, )); } @@ -667,8 +665,7 @@ pub(crate) fn parse_strings( ast::ExprConstant { value: Constant::Str(current.drain(..).join("")), kind: initial_kind.clone(), - } - .into(), + }, ) }; @@ -695,7 +692,7 @@ pub(crate) fn parse_strings( Ok(Expr::new( initial_start..last_end, - ast::ExprJoinedStr { values: deduped }.into(), + ast::ExprJoinedStr { values: deduped }, )) } diff --git a/ruff_source_location/Cargo.toml b/ruff_source_location/Cargo.toml index d915169..ab602c5 100644 --- a/ruff_source_location/Cargo.toml +++ b/ruff_source_location/Cargo.toml @@ -11,7 +11,7 @@ rust-version = { workspace = true } [lib] [dependencies] -ruff_text_size = { workspace = true, features = ["serde"] } +ruff_text_size = { path = "../ruff_text_size" } memchr = "2.5.0" once_cell = { workspace = true }