Skip to content

Commit 9ae698f

Browse files
authored
Switch to Rust 2024 edition (#18129)
1 parent e67b357 commit 9ae698f

File tree

1,082 files changed

+4193
-3282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,082 files changed

+4193
-3282
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ jobs:
495495
persist-credentials: false
496496
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
497497
- name: "Install Rust toolchain"
498-
run: rustup component add rustfmt
498+
run: rustup show
499499
# Run all code generation scripts, and verify that the current output is
500500
# already checked into git.
501501
- run: python crates/ruff_python_ast/generate.py
@@ -504,12 +504,10 @@ jobs:
504504
# Verify that adding a plugin or rule produces clean code.
505505
- run: ./scripts/add_rule.py --name DoTheThing --prefix F --code 999 --linter pyflakes
506506
- run: cargo check
507-
- run: cargo fmt --all --check
508507
- run: |
509508
./scripts/add_plugin.py test --url https://pypi.org/project/-test/0.1.0/ --prefix TST
510509
./scripts/add_rule.py --name FirstRule --prefix TST --code 001 --linter test
511510
- run: cargo check
512-
- run: cargo fmt --all --check
513511

514512
ecosystem:
515513
name: "ecosystem"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
edition = "2021"
6+
edition = "2024"
77
rust-version = "1.85"
88
homepage = "https://docs.astral.sh/ruff"
99
documentation = "https://docs.astral.sh/ruff"

crates/ruff/src/args.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::Arc;
88
use crate::commands::completions::config::{OptionString, OptionStringParser};
99
use anyhow::bail;
1010
use clap::builder::{TypedValueParser, ValueParserFactory};
11-
use clap::{command, Parser, Subcommand};
11+
use clap::{Parser, Subcommand, command};
1212
use colored::Colorize;
1313
use itertools::Itertools;
1414
use path_absolutize::path_dedot;
@@ -1126,10 +1126,10 @@ impl std::fmt::Display for FormatRangeParseError {
11261126
write!(
11271127
f,
11281128
"the start position '{start_invalid}' is greater than the end position '{end_invalid}'.\n {tip} Try switching start and end: '{end}-{start}'",
1129-
start_invalid=start.to_string().bold().yellow(),
1130-
end_invalid=end.to_string().bold().yellow(),
1131-
start=start.to_string().green().bold(),
1132-
end=end.to_string().green().bold()
1129+
start_invalid = start.to_string().bold().yellow(),
1130+
end_invalid = end.to_string().bold().yellow(),
1131+
start = start.to_string().green().bold(),
1132+
end = end.to_string().green().bold()
11331133
)
11341134
}
11351135
FormatRangeParseError::InvalidStart(inner) => inner.write(f, true),
@@ -1230,30 +1230,36 @@ impl LineColumnParseError {
12301230

12311231
match self {
12321232
LineColumnParseError::ColumnParseError(inner) => {
1233-
write!(f, "the {range}s column is not a valid number ({inner})'\n {tip} The format is 'line:column'.")
1233+
write!(
1234+
f,
1235+
"the {range}s column is not a valid number ({inner})'\n {tip} The format is 'line:column'."
1236+
)
12341237
}
12351238
LineColumnParseError::LineParseError(inner) => {
1236-
write!(f, "the {range} line is not a valid number ({inner})\n {tip} The format is 'line:column'.")
1239+
write!(
1240+
f,
1241+
"the {range} line is not a valid number ({inner})\n {tip} The format is 'line:column'."
1242+
)
12371243
}
12381244
LineColumnParseError::ZeroColumnIndex { line } => {
12391245
write!(
12401246
f,
12411247
"the {range} column is 0, but it should be 1 or greater.\n {tip} The column numbers start at 1.\n {tip} Try {suggestion} instead.",
1242-
suggestion=format!("{line}:1").green().bold()
1248+
suggestion = format!("{line}:1").green().bold()
12431249
)
12441250
}
12451251
LineColumnParseError::ZeroLineIndex { column } => {
12461252
write!(
12471253
f,
12481254
"the {range} line is 0, but it should be 1 or greater.\n {tip} The line numbers start at 1.\n {tip} Try {suggestion} instead.",
1249-
suggestion=format!("1:{column}").green().bold()
1255+
suggestion = format!("1:{column}").green().bold()
12501256
)
12511257
}
12521258
LineColumnParseError::ZeroLineAndColumnIndex => {
12531259
write!(
12541260
f,
12551261
"the {range} line and column are both 0, but they should be 1 or greater.\n {tip} The line and column numbers start at 1.\n {tip} Try {suggestion} instead.",
1256-
suggestion="1:1".to_string().green().bold()
1262+
suggestion = "1:1".to_string().green().bold()
12571263
)
12581264
}
12591265
}

crates/ruff/src/cache.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::fs::{self, File};
33
use std::hash::Hasher;
44
use std::io::{self, BufReader, Write};
55
use std::path::{Path, PathBuf};
6-
use std::sync::atomic::{AtomicU64, Ordering};
76
use std::sync::Mutex;
7+
use std::sync::atomic::{AtomicU64, Ordering};
88
use std::time::{Duration, SystemTime};
99

1010
use anyhow::{Context, Result};
@@ -22,13 +22,13 @@ use ruff_cache::{CacheKey, CacheKeyHasher};
2222
use ruff_diagnostics::Fix;
2323
use ruff_linter::message::{DiagnosticMessage, Message};
2424
use ruff_linter::package::PackageRoot;
25-
use ruff_linter::{warn_user, VERSION};
25+
use ruff_linter::{VERSION, warn_user};
2626
use ruff_macros::CacheKey;
2727
use ruff_notebook::NotebookIndex;
2828
use ruff_source_file::SourceFileBuilder;
2929
use ruff_text_size::{TextRange, TextSize};
30-
use ruff_workspace::resolver::Resolver;
3130
use ruff_workspace::Settings;
31+
use ruff_workspace::resolver::Resolver;
3232

3333
use crate::diagnostics::Diagnostics;
3434

@@ -597,7 +597,7 @@ mod tests {
597597
use std::time::SystemTime;
598598

599599
use anyhow::Result;
600-
use filetime::{set_file_mtime, FileTime};
600+
use filetime::{FileTime, set_file_mtime};
601601
use itertools::Itertools;
602602
use ruff_linter::settings::LinterSettings;
603603
use test_case::test_case;
@@ -612,8 +612,8 @@ mod tests {
612612

613613
use crate::cache::{self, FileCache, FileCacheData, FileCacheKey};
614614
use crate::cache::{Cache, RelativePathBuf};
615-
use crate::commands::format::{format_path, FormatCommandError, FormatMode, FormatResult};
616-
use crate::diagnostics::{lint_path, Diagnostics};
615+
use crate::commands::format::{FormatCommandError, FormatMode, FormatResult, format_path};
616+
use crate::diagnostics::{Diagnostics, lint_path};
617617

618618
#[test_case("../ruff_linter/resources/test/fixtures", "ruff_tests/cache_same_results_ruff_linter"; "ruff_linter_fixtures")]
619619
#[test_case("../ruff_notebook/resources/test/fixtures", "ruff_tests/cache_same_results_ruff_notebook"; "ruff_notebook_fixtures")]

crates/ruff/src/commands/add_noqa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ruff_linter::source_kind::SourceKind;
1111
use ruff_linter::warn_user_once;
1212
use ruff_python_ast::{PySourceType, SourceType};
1313
use ruff_workspace::resolver::{
14-
match_exclusion, python_files_in_path, PyprojectConfig, ResolvedFile,
14+
PyprojectConfig, ResolvedFile, match_exclusion, python_files_in_path,
1515
};
1616

1717
use crate::args::ConfigArguments;

crates/ruff/src/commands/analyze_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::args::{AnalyzeGraphArgs, ConfigArguments};
22
use crate::resolve::resolve;
3-
use crate::{resolve_default_files, ExitStatus};
3+
use crate::{ExitStatus, resolve_default_files};
44
use anyhow::Result;
55
use log::{debug, warn};
66
use path_absolutize::CWD;
@@ -9,7 +9,7 @@ use ruff_graph::{Direction, ImportMap, ModuleDb, ModuleImports};
99
use ruff_linter::package::PackageRoot;
1010
use ruff_linter::{warn_user, warn_user_once};
1111
use ruff_python_ast::{PySourceType, SourceType};
12-
use ruff_workspace::resolver::{match_exclusion, python_files_in_path, ResolvedFile};
12+
use ruff_workspace::resolver::{ResolvedFile, match_exclusion, python_files_in_path};
1313
use rustc_hash::FxHashMap;
1414
use std::io::Write;
1515
use std::path::{Path, PathBuf};

crates/ruff/src/commands/check.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ use ruff_linter::message::Message;
1717
use ruff_linter::package::PackageRoot;
1818
use ruff_linter::registry::Rule;
1919
use ruff_linter::settings::types::UnsafeFixes;
20-
use ruff_linter::settings::{flags, LinterSettings};
21-
use ruff_linter::{fs, warn_user_once, IOError};
20+
use ruff_linter::settings::{LinterSettings, flags};
21+
use ruff_linter::{IOError, fs, warn_user_once};
2222
use ruff_source_file::SourceFileBuilder;
2323
use ruff_text_size::{TextRange, TextSize};
2424
use ruff_workspace::resolver::{
25-
match_exclusion, python_files_in_path, PyprojectConfig, ResolvedFile,
25+
PyprojectConfig, ResolvedFile, match_exclusion, python_files_in_path,
2626
};
2727

2828
use crate::args::ConfigArguments;
@@ -228,9 +228,9 @@ mod test {
228228
use ruff_linter::message::{Emitter, EmitterContext, TextEmitter};
229229
use ruff_linter::registry::Rule;
230230
use ruff_linter::settings::types::UnsafeFixes;
231-
use ruff_linter::settings::{flags, LinterSettings};
232-
use ruff_workspace::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
231+
use ruff_linter::settings::{LinterSettings, flags};
233232
use ruff_workspace::Settings;
233+
use ruff_workspace::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
234234

235235
use crate::args::ConfigArguments;
236236

crates/ruff/src/commands/check_stdin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use anyhow::Result;
44
use ruff_linter::package::PackageRoot;
55
use ruff_linter::packaging;
66
use ruff_linter::settings::flags;
7-
use ruff_workspace::resolver::{match_exclusion, python_file_at_path, PyprojectConfig, Resolver};
7+
use ruff_workspace::resolver::{PyprojectConfig, Resolver, match_exclusion, python_file_at_path};
88

99
use crate::args::ConfigArguments;
10-
use crate::diagnostics::{lint_stdin, Diagnostics};
10+
use crate::diagnostics::{Diagnostics, lint_stdin};
1111
use crate::stdin::{parrot_stdin, read_from_stdin};
1212

1313
/// Run the linter over a single file, read from `stdin`.

crates/ruff/src/commands/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Result};
1+
use anyhow::{Result, anyhow};
22

33
use crate::args::HelpFormat;
44

0 commit comments

Comments
 (0)