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

@ -1,11 +1,11 @@
use ruff_formatter::{write, FormatContext};
use ruff_formatter::{FormatContext, write};
use ruff_python_ast::{ArgOrKeyword, Arguments, Expr, StringFlags, StringLike};
use ruff_python_trivia::{PythonWhitespace, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use crate::expression::expr_generator::GeneratorExpParentheses;
use crate::expression::is_expression_huggable;
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
use crate::expression::parentheses::{Parentheses, empty_parenthesized, parenthesized};
use crate::other::commas;
use crate::prelude::*;
use crate::string::StringLikeExtensions;

View file

@ -2,8 +2,8 @@ use ruff_formatter::FormatContext;
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::TextRange;
use crate::prelude::*;
use crate::MagicTrailingComma;
use crate::prelude::*;
/// Returns `true` if the range ends with a magic trailing comma (and the magic trailing comma
/// should be respected).

View file

@ -1,6 +1,6 @@
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_formatter::{Buffer, FormatResult, format_args, write};
use ruff_python_ast::{Comprehension, Expr};
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
use ruff_python_trivia::{SimpleTokenKind, find_only_token_in_range};
use ruff_text_size::{Ranged, TextRange};
use crate::comments::{leading_comments, trailing_comments};

View file

@ -1,11 +1,11 @@
use ruff_formatter::write;
use ruff_formatter::FormatRuleWithOptions;
use ruff_formatter::write;
use ruff_python_ast::ExceptHandlerExceptHandler;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::statement::clause::{ClauseHeader, clause_body, clause_header};
use crate::statement::suite::SuiteKind;
#[derive(Copy, Clone, Default)]

View file

@ -1,6 +1,6 @@
use std::borrow::Cow;
use ruff_formatter::{format_args, write, Buffer, RemoveSoftLinesBuffer};
use ruff_formatter::{Buffer, RemoveSoftLinesBuffer, format_args, write};
use ruff_python_ast::{
AnyStringFlags, ConversionFlag, Expr, FStringElement, FStringExpressionElement,
FStringLiteralElement, StringFlags,

View file

@ -1,11 +1,11 @@
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_formatter::{FormatRuleWithOptions, format_args, write};
use ruff_python_ast::MatchCase;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::pattern::maybe_parenthesize_pattern;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::statement::clause::{ClauseHeader, clause_body, clause_header};
use crate::statement::suite::SuiteKind;
#[derive(Default)]

View file

@ -38,20 +38,26 @@ impl FormatNodeRule<ParameterWithDefault> for FormatParameterWithDefault {
// ```
let needs_line_break_trailing = f.context().comments().has_trailing(parameter);
let default_first_comment = f.context().comments().leading(default.as_ref()).first();
let needs_line_break_leading = default_first_comment.is_some_and(|default_leading_comment| {
let mut tokenizer = SimpleTokenizer::new(
f.context().source(),
TextRange::new(parameter.end(), default_leading_comment.start()),
)
.skip_trivia()
.skip_while(|token| token.kind == SimpleTokenKind::RParen);
let equals = tokenizer.next();
debug_assert!(equals.is_some_and(|token| token.kind == SimpleTokenKind::Equals));
let lparens = tokenizer.next();
debug_assert!(lparens
.as_ref().is_none_or(|token| token.kind == SimpleTokenKind::LParen));
lparens.is_none()
});
let needs_line_break_leading =
default_first_comment.is_some_and(|default_leading_comment| {
let mut tokenizer = SimpleTokenizer::new(
f.context().source(),
TextRange::new(parameter.end(), default_leading_comment.start()),
)
.skip_trivia()
.skip_while(|token| token.kind == SimpleTokenKind::RParen);
let equals = tokenizer.next();
debug_assert!(
equals.is_some_and(|token| token.kind == SimpleTokenKind::Equals)
);
let lparens = tokenizer.next();
debug_assert!(
lparens
.as_ref()
.is_none_or(|token| token.kind == SimpleTokenKind::LParen)
);
lparens.is_none()
});
let needs_line_break = needs_line_break_trailing || needs_line_break_leading;
write!(

View file

@ -1,11 +1,11 @@
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_formatter::{FormatRuleWithOptions, format_args, write};
use ruff_python_ast::{AnyNodeRef, Parameters};
use ruff_python_trivia::{CommentLinePosition, SimpleToken, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange, TextSize};
use crate::comments::{
dangling_comments, dangling_open_parenthesis_comments, leading_comments, leading_node_comments,
trailing_comments, SourceComment,
SourceComment, dangling_comments, dangling_open_parenthesis_comments, leading_comments,
leading_node_comments, trailing_comments,
};
use crate::context::{NodeLevel, WithNodeLevel};
use crate::expression::parentheses::empty_parenthesized;
@ -670,10 +670,28 @@ fn has_trailing_comma(
// The slash lacks its own node
if ends_with_pos_only_argument_separator {
let comma = tokens.next();
assert!(matches!(comma, Some(SimpleToken { kind: SimpleTokenKind::Comma, .. })), "The last positional only argument must be separated by a `,` from the positional only parameters separator `/` but found '{comma:?}'.");
assert!(
matches!(
comma,
Some(SimpleToken {
kind: SimpleTokenKind::Comma,
..
})
),
"The last positional only argument must be separated by a `,` from the positional only parameters separator `/` but found '{comma:?}'."
);
let slash = tokens.next();
assert!(matches!(slash, Some(SimpleToken { kind: SimpleTokenKind::Slash, .. })), "The positional argument separator must be present for a function that has positional only parameters but found '{slash:?}'.");
assert!(
matches!(
slash,
Some(SimpleToken {
kind: SimpleTokenKind::Slash,
..
})
),
"The positional argument separator must be present for a function that has positional only parameters but found '{slash:?}'."
);
}
tokens

View file

@ -1,9 +1,9 @@
use ruff_formatter::FormatRuleWithOptions;
use ruff_python_ast::StringLiteral;
use crate::prelude::*;
use crate::string::{docstring, StringNormalizer};
use crate::QuoteStyle;
use crate::prelude::*;
use crate::string::{StringNormalizer, docstring};
#[derive(Default)]
pub struct FormatStringLiteral {

View file

@ -1,9 +1,9 @@
use ruff_formatter::{write, FormatRuleWithOptions};
use ruff_formatter::{FormatRuleWithOptions, write};
use ruff_python_ast::WithItem;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::{
is_expression_parenthesized, parenthesized, Parentheses, Parenthesize,
Parentheses, Parenthesize, is_expression_parenthesized, parenthesized,
};
use crate::prelude::*;