Skip to content

Commit

Permalink
Update to Rust 1.74 and use new clippy lints table (#8722)
Browse files Browse the repository at this point in the history
Update to [Rust
1.74](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html) and use
the new clippy lints table.

The update itself introduced a new clippy lint about superfluous hashes
in raw strings, which got removed.

I moved our lint config from `rustflags` to the newly stabilized
[workspace.lints](https://doc.rust-lang.org/stable/cargo/reference/workspaces.html#the-lints-table).
One consequence is that we have to `unsafe_code = "warn"` instead of
"forbid" because the latter now actually bans unsafe code:

```
error[E0453]: allow(unsafe_code) incompatible with previous forbid
  --> crates/ruff_source_file/src/newlines.rs:62:17
   |
62 |         #[allow(unsafe_code)]
   |                 ^^^^^^^^^^^ overruled by previous forbid
   |
   = note: `forbid` lint level was set on command line
```

---------

Co-authored-by: Charlie Marsh <[email protected]>
  • Loading branch information
konstin and charliermarsh authored Nov 16, 2023
1 parent 6d5d079 commit 14e65af
Show file tree
Hide file tree
Showing 71 changed files with 1,124 additions and 1,054 deletions.
34 changes: 0 additions & 34 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
[alias]
dev = "run --package ruff_dev --bin ruff_dev"
benchmark = "bench -p ruff_benchmark --bench linter --bench formatter --"

[target.'cfg(all())']
rustflags = [
# CLIPPY LINT SETTINGS
# This is a workaround to configure lints for the entire workspace, pending the ability to configure this via TOML.
# See: `https://github.com/rust-lang/cargo/issues/5034`
# `https://github.com/EmbarkStudios/rust-ecosystem/issues/22#issuecomment-947011395`
"-Dunsafe_code",
"-Wclippy::pedantic",
# Allowed pedantic lints
"-Wclippy::char_lit_as_u8",
"-Aclippy::collapsible_else_if",
"-Aclippy::collapsible_if",
"-Aclippy::implicit_hasher",
"-Aclippy::match_same_arms",
"-Aclippy::missing_errors_doc",
"-Aclippy::missing_panics_doc",
"-Aclippy::module_name_repetitions",
"-Aclippy::must_use_candidate",
"-Aclippy::similar_names",
"-Aclippy::too_many_lines",
# Disallowed restriction lints
"-Wclippy::print_stdout",
"-Wclippy::print_stderr",
"-Wclippy::dbg_macro",
"-Wclippy::empty_drop",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::exit",
"-Wclippy::get_unwrap",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wunreachable_pub"
]
32 changes: 32 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@ unicode-width = { version = "0.1.11" }
uuid = { version = "1.5.0", features = ["v4", "fast-rng", "macro-diagnostics", "js"] }
wsl = { version = "0.1.0" }

[workspace.lints.rust]
unsafe_code = "warn"
unreachable_pub = "warn"

[workspace.lints.clippy]
pedantic = { level = "warn", priority = -2 }
# Allowed pedantic lints
char_lit_as_u8 = "allow"
collapsible_else_if = "allow"
collapsible_if = "allow"
implicit_hasher = "allow"
match_same_arms = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
module_name_repetitions = "allow"
must_use_candidate = "allow"
similar_names = "allow"
too_many_lines = "allow"
# To allow `#[allow(clippy::all)]` in `crates/ruff_python_parser/src/python.rs`.
needless_raw_string_hashes = "allow"
# Disallowed restriction lints
print_stdout = "warn"
print_stderr = "warn"
dbg_macro = "warn"
empty_drop = "warn"
empty_structs_with_brackets = "warn"
exit = "warn"
get_unwrap = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
rest_pat_in_fully_bound_structs = "warn"

[profile.release]
lto = "fat"
codegen-units = 1
Expand Down
3 changes: 3 additions & 0 deletions crates/flake8_to_ruff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ toml = { workspace = true }

[dev-dependencies]
pretty_assertions = "1.3.0"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/ruff_benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ruff_python_formatter = { path = "../ruff_python_formatter" }
ruff_python_index = { path = "../ruff_python_index" }
ruff_python_parser = { path = "../ruff_python_parser" }

[lints]
workspace = true

[features]
codspeed = ["codspeed-criterion-compat"]

Expand Down
3 changes: 3 additions & 0 deletions crates/ruff_cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ seahash = "4.1.0"

[dev-dependencies]
ruff_macros = { path = "../ruff_macros" }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/ruff_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ mimalloc = "0.1.39"

[target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")))'.dependencies]
tikv-jemallocator = "0.5.0"

[lints]
workspace = true
4 changes: 2 additions & 2 deletions crates/ruff_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ fn lint_path(
match result {
Ok(inner) => inner,
Err(error) => {
let message = r#"This indicates a bug in Ruff. If you could open an issue at:
let message = r"This indicates a bug in Ruff. If you could open an issue at:
https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D
...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative!
"#;
";

error!(
"{}{}{} {message}\n{error}",
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,12 @@ impl Display for FormatCommandError {
}
}
Self::Panic(path, err) => {
let message = r#"This indicates a bug in Ruff. If you could open an issue at:
let message = r"This indicates a bug in Ruff. If you could open an issue at:
https://github.com/astral-sh/ruff/issues/new?title=%5BFormatter%20panic%5D
...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative!
"#;
";
if let Some(path) = path {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/commands/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn format_rule_text(rule: Rule) -> String {

if rule.is_preview() || rule.is_nursery() {
output.push_str(
r#"This rule is in preview and is not stable. The `--preview` flag is required for use."#,
r"This rule is in preview and is not stable. The `--preview` flag is required for use.",
);
output.push('\n');
output.push('\n');
Expand Down
12 changes: 6 additions & 6 deletions crates/ruff_cli/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ fn deprecated_options() -> Result<()> {
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
r"
tab-size = 2
"#,
",
)?;

insta::with_settings!({filters => vec![
Expand All @@ -407,10 +407,10 @@ tab-size = 2
.args(["format", "--config"])
.arg(&ruff_toml)
.arg("-")
.pass_stdin(r#"
.pass_stdin(r"
if True:
pass
"#), @r###"
"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -443,9 +443,9 @@ format = "json"
.args(["check", "--select", "F401", "--no-cache", "--config"])
.arg(&ruff_toml)
.arg("-")
.pass_stdin(r#"
.pass_stdin(r"
import os
"#), @r###"
"), @r###"
success: false
exit_code: 2
----- stdout -----
Expand Down
7 changes: 5 additions & 2 deletions crates/ruff_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ tracing-indicatif = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
imara-diff = "0.1.5"

[dev-dependencies]
indoc = "2.0.4"

[features]
# Turn off rayon for profiling
singlethreaded = []

[dev-dependencies]
indoc = "2.0.4"
[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/ruff_dev/src/generate_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) fn main(args: &Args) -> Result<()> {

if rule.is_preview() || rule.is_nursery() {
output.push_str(
r#"This rule is unstable and in [preview](../preview.md). The `--preview` flag is required for use."#,
r"This rule is unstable and in [preview](../preview.md). The `--preview` flag is required for use.",
);
output.push('\n');
output.push('\n');
Expand Down
3 changes: 3 additions & 0 deletions crates/ruff_formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ insta = { workspace = true }
[features]
serde = ["dep:serde", "ruff_text_size/serde"]
schemars = ["dep:schemars", "ruff_text_size/schemars"]

[lints]
workspace = true
8 changes: 4 additions & 4 deletions crates/ruff_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,14 +1711,14 @@ mod tests {
));

assert_eq!(
r#"a
"a
b
c
d
d
c
b
a"#,
a",
formatted.as_code()
);
}
Expand Down Expand Up @@ -2047,10 +2047,10 @@ two lines`,

assert_eq!(
printed.as_code(),
r#"Group with id-2
"Group with id-2
Group with id-1 does not fit on the line because it exceeds the line width of 80 characters by
Group 2 fits
Group 1 breaks"#
Group 1 breaks"
);
}

Expand Down
3 changes: 3 additions & 0 deletions crates/ruff_index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ ruff_macros = { path = "../ruff_macros" }

[dev-dependencies]
static_assertions = "1.1.0"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/ruff_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ default = []
schemars = ["dep:schemars"]
# Enables the UnreachableCode rule
unreachable-code = []

[lints]
workspace = true
34 changes: 17 additions & 17 deletions crates/ruff_linter/src/fix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ mod tests {

#[test]
fn empty_file() {
let locator = Locator::new(r#""#);
let locator = Locator::new(r"");
let diagnostics = create_diagnostics([]);
let FixResult {
code,
Expand Down Expand Up @@ -225,10 +225,10 @@ print("hello world")
#[test]
fn apply_one_replacement() {
let locator = Locator::new(
r#"
r"
class A(object):
...
"#
"
.trim(),
);
let diagnostics = create_diagnostics([Edit::replacement(
Expand All @@ -243,10 +243,10 @@ class A(object):
} = apply_fixes(diagnostics.iter(), &locator);
assert_eq!(
code,
r#"
r"
class A(Bar):
...
"#
"
.trim(),
);
assert_eq!(fixes.values().sum::<usize>(), 1);
Expand All @@ -262,10 +262,10 @@ class A(Bar):
#[test]
fn apply_one_removal() {
let locator = Locator::new(
r#"
r"
class A(object):
...
"#
"
.trim(),
);
let diagnostics = create_diagnostics([Edit::deletion(TextSize::new(7), TextSize::new(15))]);
Expand All @@ -276,10 +276,10 @@ class A(object):
} = apply_fixes(diagnostics.iter(), &locator);
assert_eq!(
code,
r#"
r"
class A:
...
"#
"
.trim()
);
assert_eq!(fixes.values().sum::<usize>(), 1);
Expand All @@ -295,10 +295,10 @@ class A:
#[test]
fn apply_two_removals() {
let locator = Locator::new(
r#"
r"
class A(object, object, object):
...
"#
"
.trim(),
);
let diagnostics = create_diagnostics([
Expand All @@ -313,10 +313,10 @@ class A(object, object, object):

assert_eq!(
code,
r#"
r"
class A(object):
...
"#
"
.trim()
);
assert_eq!(fixes.values().sum::<usize>(), 2);
Expand All @@ -334,10 +334,10 @@ class A(object):
#[test]
fn ignore_overlapping_fixes() {
let locator = Locator::new(
r#"
r"
class A(object):
...
"#
"
.trim(),
);
let diagnostics = create_diagnostics([
Expand All @@ -351,10 +351,10 @@ class A(object):
} = apply_fixes(diagnostics.iter(), &locator);
assert_eq!(
code,
r#"
r"
class A:
...
"#
"
.trim(),
);
assert_eq!(fixes.values().sum::<usize>(), 1);
Expand Down
Loading

0 comments on commit 14e65af

Please sign in to comment.