Switch to Rust 2024 edition (#18129)

This commit is contained in:
Micha Reiser 2025-05-16 13:25:28 +02:00 committed by GitHub
parent e67b35743a
commit 9ae698fe30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
1082 changed files with 4211 additions and 3300 deletions

View file

@ -192,7 +192,7 @@ impl std::fmt::Display for ParseErrorType {
ParseErrorType::ExpectedToken { found, expected } => {
write!(f, "Expected {expected}, found {found}",)
}
ParseErrorType::Lexical(ref lex_error) => write!(f, "{lex_error}"),
ParseErrorType::Lexical(lex_error) => write!(f, "{lex_error}"),
ParseErrorType::SimpleStatementsOnSameLine => {
f.write_str("Simple statements must be separated by newlines or semicolons")
}
@ -289,7 +289,7 @@ impl std::fmt::Display for ParseErrorType {
ParseErrorType::UnexpectedIpythonEscapeCommand => {
f.write_str("IPython escape commands are only allowed in `Mode::Ipython`")
}
ParseErrorType::FStringError(ref fstring_error) => {
ParseErrorType::FStringError(fstring_error) => {
write!(f, "f-string: {fstring_error}")
}
ParseErrorType::UnexpectedExpressionToken => {
@ -864,7 +864,9 @@ impl Display for UnsupportedSyntaxError {
) => "Cannot use unparenthesized assignment expression as an element in a set literal",
UnsupportedSyntaxErrorKind::UnparenthesizedNamedExpr(
UnparenthesizedNamedExprKind::SetComprehension,
) => "Cannot use unparenthesized assignment expression as an element in a set comprehension",
) => {
"Cannot use unparenthesized assignment expression as an element in a set comprehension"
}
UnsupportedSyntaxErrorKind::ParenthesizedKeywordArgumentName => {
"Cannot use parenthesized keyword argument name"
}
@ -894,7 +896,7 @@ impl Display for UnsupportedSyntaxError {
self.target_version,
changed = self.kind.changed_version(),
),
}
};
}
UnsupportedSyntaxErrorKind::PositionalOnlyParameter => {
"Cannot use positional-only parameter separator"

View file

@ -17,12 +17,12 @@ use ruff_python_ast::{Int, IpyEscapeKind, StringFlags};
use ruff_python_trivia::is_python_whitespace;
use ruff_text_size::{TextLen, TextRange, TextSize};
use crate::Mode;
use crate::error::{FStringErrorType, LexicalError, LexicalErrorType};
use crate::lexer::cursor::{Cursor, EOF_CHAR};
use crate::lexer::fstring::{FStringContext, FStrings, FStringsCheckpoint};
use crate::lexer::indentation::{Indentation, Indentations, IndentationsCheckpoint};
use crate::token::{TokenFlags, TokenKind, TokenValue};
use crate::Mode;
mod cursor;
mod fstring;
@ -281,7 +281,7 @@ impl<'src> Lexer<'src> {
}
fn handle_indentation(&mut self, indentation: Indentation) -> Option<TokenKind> {
let token = match self.indentations.current().try_compare(indentation) {
match self.indentations.current().try_compare(indentation) {
// Dedent
Ok(Ordering::Greater) => {
self.pending_indentation = Some(indentation);
@ -318,15 +318,11 @@ impl<'src> Lexer<'src> {
self.indentations.indent(indentation);
Some(TokenKind::Indent)
}
Err(_) => {
return Some(self.push_error(LexicalError::new(
LexicalErrorType::IndentationError,
self.token_range(),
)));
}
};
token
Err(_) => Some(self.push_error(LexicalError::new(
LexicalErrorType::IndentationError,
self.token_range(),
))),
}
}
fn skip_whitespace(&mut self) -> Result<(), LexicalError> {
@ -581,7 +577,7 @@ impl<'src> Lexer<'src> {
fstring.try_end_format_spec(self.nesting);
}
TokenKind::NonLogicalNewline
}
};
}
'\r' => {
self.cursor.eat_char('\n');
@ -1156,7 +1152,7 @@ impl<'src> Lexer<'src> {
return self.push_error(LexicalError::new(
LexicalErrorType::OtherError(format!("{err:?}").into_boxed_str()),
self.token_range(),
))
));
}
};
self.current_value = TokenValue::Int(value);
@ -1956,8 +1952,7 @@ def f(arg=%timeit a = b):
#[test]
fn test_numbers() {
let source =
"0x2f 0o12 0b1101 0 123 123_45_67_890 0.2 1e+2 2.1e3 2j 2.2j 000 0x995DC9BBDF1939FA 0x995DC9BBDF1939FA995DC9BBDF1939FA";
let source = "0x2f 0o12 0b1101 0 123 123_45_67_890 0.2 1e+2 2.1e3 2j 2.2j 000 0x995DC9BBDF1939FA 0x995DC9BBDF1939FA995DC9BBDF1939FA";
assert_snapshot!(lex_source(source));
}

View file

@ -13,8 +13,8 @@ use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use crate::error::{FStringKind, StarTupleKind, UnparenthesizedNamedExprKind};
use crate::parser::progress::ParserProgress;
use crate::parser::{helpers, FunctionKind, Parser};
use crate::string::{parse_fstring_literal_element, parse_string_literal, StringType};
use crate::parser::{FunctionKind, Parser, helpers};
use crate::string::{StringType, parse_fstring_literal_element, parse_string_literal};
use crate::token::{TokenKind, TokenValue};
use crate::token_set::TokenSet;
use crate::{

View file

@ -1,7 +1,7 @@
use ruff_python_ast::{self as ast, CmpOp, Expr, ExprContext, Number};
use ruff_text_size::{Ranged, TextRange};
use crate::{error::RelaxedDecoratorError, TokenKind};
use crate::{TokenKind, error::RelaxedDecoratorError};
/// Set the `ctx` for `Expr::Id`, `Expr::Attribute`, `Expr::Subscript`, `Expr::Starred`,
/// `Expr::Tuple` and `Expr::List`. If `expr` is either `Expr::Tuple` or `Expr::List`,
@ -58,7 +58,7 @@ pub(super) fn detect_invalid_pre_py39_decorator_node(
Expr::Name(_) => return None,
Expr::Attribute(attribute) => {
return detect_invalid_pre_py39_decorator_node(&attribute.value)
return detect_invalid_pre_py39_decorator_node(&attribute.value);
}
Expr::Call(_) => return Some((RelaxedDecoratorError::CallExpression, expr.range())),

View file

@ -2,11 +2,11 @@ use ruff_python_ast::name::Name;
use ruff_python_ast::{self as ast, Expr, ExprContext, Number, Operator, Pattern, Singleton};
use ruff_text_size::{Ranged, TextSize};
use crate::ParseErrorType;
use crate::parser::progress::ParserProgress;
use crate::parser::{recovery, Parser, RecoveryContextKind, SequenceMatchPatternParentheses};
use crate::parser::{Parser, RecoveryContextKind, SequenceMatchPatternParentheses, recovery};
use crate::token::{TokenKind, TokenValue};
use crate::token_set::TokenSet;
use crate::ParseErrorType;
use super::expression::ExpressionContext;

View file

@ -9,17 +9,17 @@ use ruff_python_ast::{
use ruff_text_size::{Ranged, TextRange, TextSize};
use crate::error::StarTupleKind;
use crate::parser::expression::{ParsedExpr, EXPR_SET};
use crate::parser::expression::{EXPR_SET, ParsedExpr};
use crate::parser::progress::ParserProgress;
use crate::parser::{
helpers, FunctionKind, Parser, RecoveryContext, RecoveryContextKind, WithItemKind,
FunctionKind, Parser, RecoveryContext, RecoveryContextKind, WithItemKind, helpers,
};
use crate::token::{TokenKind, TokenValue};
use crate::token_set::TokenSet;
use crate::{Mode, ParseErrorType, UnsupportedSyntaxErrorKind};
use super::expression::ExpressionContext;
use super::Parenthesized;
use super::expression::ExpressionContext;
/// Tokens that represent compound statements.
const COMPOUND_STMT_SET: TokenSet = TokenSet::new([

View file

@ -1,4 +1,4 @@
use crate::{parse, parse_expression, parse_module, Mode, ParseOptions};
use crate::{Mode, ParseOptions, parse, parse_expression, parse_module};
#[test]
fn test_modes() {

View file

@ -6,11 +6,10 @@
use std::fmt::Display;
use ruff_python_ast::{
self as ast,
comparable::ComparableExpr,
visitor::{walk_expr, Visitor},
Expr, ExprContext, IrrefutablePatternKind, Pattern, PythonVersion, Stmt, StmtExpr,
self as ast, Expr, ExprContext, IrrefutablePatternKind, Pattern, PythonVersion, Stmt, StmtExpr,
StmtImportFrom,
comparable::ComparableExpr,
visitor::{Visitor, walk_expr},
};
use ruff_text_size::{Ranged, TextRange, TextSize};
use rustc_hash::{FxBuildHasher, FxHashSet};
@ -845,7 +844,7 @@ impl SemanticSyntaxChecker {
if !ctx.in_sync_comprehension() {
return;
}
for generator in generators.iter().filter(|gen| gen.is_async) {
for generator in generators.iter().filter(|generator| generator.is_async) {
// test_ok nested_async_comprehension_py311
// # parse_options: {"target-version": "3.11"}
// async def f(): return [[x async for x in foo(n)] for n in range(3)] # list
@ -921,7 +920,10 @@ impl Display for SemanticSyntaxError {
SemanticSyntaxErrorKind::WriteToDebug(kind) => match kind {
WriteToDebugKind::Store => f.write_str("cannot assign to `__debug__`"),
WriteToDebugKind::Delete(python_version) => {
write!(f, "cannot delete `__debug__` on Python {python_version} (syntax was removed in 3.9)")
write!(
f,
"cannot delete `__debug__` on Python {python_version} (syntax was removed in 3.9)"
)
}
},
SemanticSyntaxErrorKind::InvalidExpression(kind, position) => {

View file

@ -125,7 +125,7 @@ impl StringParser {
return Err(LexicalError::new(
LexicalErrorType::UnicodeError,
TextRange::empty(self.position()),
))
));
}
}
}
@ -471,7 +471,7 @@ mod tests {
use ruff_python_ast::Suite;
use crate::error::LexicalErrorType;
use crate::{parse_module, FStringErrorType, ParseError, ParseErrorType, Parsed};
use crate::{FStringErrorType, ParseError, ParseErrorType, Parsed, parse_module};
const WINDOWS_EOL: &str = "\r\n";
const MAC_EOL: &str = "\r";

View file

@ -1,9 +1,9 @@
use ruff_text_size::{Ranged, TextRange, TextSize};
use crate::Mode;
use crate::error::LexicalError;
use crate::lexer::{Lexer, LexerCheckpoint};
use crate::token::{Token, TokenFlags, TokenKind, TokenValue};
use crate::Mode;
/// Token source for the parser that skips over any trivia tokens.
#[derive(Debug)]

View file

@ -4,7 +4,7 @@ use ruff_python_ast::relocate::relocate_expr;
use ruff_python_ast::{Expr, ExprStringLiteral, ModExpression, StringLiteral};
use ruff_text_size::Ranged;
use crate::{parse_expression, parse_string_annotation, ParseError, Parsed};
use crate::{ParseError, Parsed, parse_expression, parse_string_annotation};
type AnnotationParseResult = Result<ParsedAnnotation, ParseError>;