Skip to content

Commit 14e65af

Browse files
Update to Rust 1.74 and use new clippy lints table (#8722)
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]>
1 parent 6d5d079 commit 14e65af

File tree

71 files changed

+1124
-1054
lines changed

Some content is hidden

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

71 files changed

+1124
-1054
lines changed

.cargo/config.toml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
11
[alias]
22
dev = "run --package ruff_dev --bin ruff_dev"
33
benchmark = "bench -p ruff_benchmark --bench linter --bench formatter --"
4-
5-
[target.'cfg(all())']
6-
rustflags = [
7-
# CLIPPY LINT SETTINGS
8-
# This is a workaround to configure lints for the entire workspace, pending the ability to configure this via TOML.
9-
# See: `https://github.com/rust-lang/cargo/issues/5034`
10-
# `https://github.com/EmbarkStudios/rust-ecosystem/issues/22#issuecomment-947011395`
11-
"-Dunsafe_code",
12-
"-Wclippy::pedantic",
13-
# Allowed pedantic lints
14-
"-Wclippy::char_lit_as_u8",
15-
"-Aclippy::collapsible_else_if",
16-
"-Aclippy::collapsible_if",
17-
"-Aclippy::implicit_hasher",
18-
"-Aclippy::match_same_arms",
19-
"-Aclippy::missing_errors_doc",
20-
"-Aclippy::missing_panics_doc",
21-
"-Aclippy::module_name_repetitions",
22-
"-Aclippy::must_use_candidate",
23-
"-Aclippy::similar_names",
24-
"-Aclippy::too_many_lines",
25-
# Disallowed restriction lints
26-
"-Wclippy::print_stdout",
27-
"-Wclippy::print_stderr",
28-
"-Wclippy::dbg_macro",
29-
"-Wclippy::empty_drop",
30-
"-Wclippy::empty_structs_with_brackets",
31-
"-Wclippy::exit",
32-
"-Wclippy::get_unwrap",
33-
"-Wclippy::rc_buffer",
34-
"-Wclippy::rc_mutex",
35-
"-Wclippy::rest_pat_in_fully_bound_structs",
36-
"-Wunreachable_pub"
37-
]

Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@ unicode-width = { version = "0.1.11" }
5555
uuid = { version = "1.5.0", features = ["v4", "fast-rng", "macro-diagnostics", "js"] }
5656
wsl = { version = "0.1.0" }
5757

58+
[workspace.lints.rust]
59+
unsafe_code = "warn"
60+
unreachable_pub = "warn"
61+
62+
[workspace.lints.clippy]
63+
pedantic = { level = "warn", priority = -2 }
64+
# Allowed pedantic lints
65+
char_lit_as_u8 = "allow"
66+
collapsible_else_if = "allow"
67+
collapsible_if = "allow"
68+
implicit_hasher = "allow"
69+
match_same_arms = "allow"
70+
missing_errors_doc = "allow"
71+
missing_panics_doc = "allow"
72+
module_name_repetitions = "allow"
73+
must_use_candidate = "allow"
74+
similar_names = "allow"
75+
too_many_lines = "allow"
76+
# To allow `#[allow(clippy::all)]` in `crates/ruff_python_parser/src/python.rs`.
77+
needless_raw_string_hashes = "allow"
78+
# Disallowed restriction lints
79+
print_stdout = "warn"
80+
print_stderr = "warn"
81+
dbg_macro = "warn"
82+
empty_drop = "warn"
83+
empty_structs_with_brackets = "warn"
84+
exit = "warn"
85+
get_unwrap = "warn"
86+
rc_buffer = "warn"
87+
rc_mutex = "warn"
88+
rest_pat_in_fully_bound_structs = "warn"
89+
5890
[profile.release]
5991
lto = "fat"
6092
codegen-units = 1

crates/flake8_to_ruff/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ toml = { workspace = true }
3434

3535
[dev-dependencies]
3636
pretty_assertions = "1.3.0"
37+
38+
[lints]
39+
workspace = true

crates/ruff_benchmark/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ ruff_python_formatter = { path = "../ruff_python_formatter" }
4646
ruff_python_index = { path = "../ruff_python_index" }
4747
ruff_python_parser = { path = "../ruff_python_parser" }
4848

49+
[lints]
50+
workspace = true
51+
4952
[features]
5053
codspeed = ["codspeed-criterion-compat"]
5154

crates/ruff_cache/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ seahash = "4.1.0"
2020

2121
[dev-dependencies]
2222
ruff_macros = { path = "../ruff_macros" }
23+
24+
[lints]
25+
workspace = true

crates/ruff_cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ mimalloc = "0.1.39"
7676

7777
[target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")))'.dependencies]
7878
tikv-jemallocator = "0.5.0"
79+
80+
[lints]
81+
workspace = true

crates/ruff_cli/src/commands/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ fn lint_path(
202202
match result {
203203
Ok(inner) => inner,
204204
Err(error) => {
205-
let message = r#"This indicates a bug in Ruff. If you could open an issue at:
205+
let message = r"This indicates a bug in Ruff. If you could open an issue at:
206206
207207
https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D
208208
209209
...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative!
210-
"#;
210+
";
211211

212212
error!(
213213
"{}{}{} {message}\n{error}",

crates/ruff_cli/src/commands/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,12 @@ impl Display for FormatCommandError {
660660
}
661661
}
662662
Self::Panic(path, err) => {
663-
let message = r#"This indicates a bug in Ruff. If you could open an issue at:
663+
let message = r"This indicates a bug in Ruff. If you could open an issue at:
664664
665665
https://github.com/astral-sh/ruff/issues/new?title=%5BFormatter%20panic%5D
666666
667667
...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative!
668-
"#;
668+
";
669669
if let Some(path) = path {
670670
write!(
671671
f,

crates/ruff_cli/src/commands/rule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn format_rule_text(rule: Rule) -> String {
6363

6464
if rule.is_preview() || rule.is_nursery() {
6565
output.push_str(
66-
r#"This rule is in preview and is not stable. The `--preview` flag is required for use."#,
66+
r"This rule is in preview and is not stable. The `--preview` flag is required for use.",
6767
);
6868
output.push('\n');
6969
output.push('\n');

crates/ruff_cli/tests/format.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ fn deprecated_options() -> Result<()> {
395395
let ruff_toml = tempdir.path().join("ruff.toml");
396396
fs::write(
397397
&ruff_toml,
398-
r#"
398+
r"
399399
tab-size = 2
400-
"#,
400+
",
401401
)?;
402402

403403
insta::with_settings!({filters => vec![
@@ -407,10 +407,10 @@ tab-size = 2
407407
.args(["format", "--config"])
408408
.arg(&ruff_toml)
409409
.arg("-")
410-
.pass_stdin(r#"
410+
.pass_stdin(r"
411411
if True:
412412
pass
413-
"#), @r###"
413+
"), @r###"
414414
success: true
415415
exit_code: 0
416416
----- stdout -----
@@ -443,9 +443,9 @@ format = "json"
443443
.args(["check", "--select", "F401", "--no-cache", "--config"])
444444
.arg(&ruff_toml)
445445
.arg("-")
446-
.pass_stdin(r#"
446+
.pass_stdin(r"
447447
import os
448-
"#), @r###"
448+
"), @r###"
449449
success: false
450450
exit_code: 2
451451
----- stdout -----

crates/ruff_dev/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ tracing-indicatif = { workspace = true }
4848
tracing-subscriber = { workspace = true, features = ["env-filter"] }
4949
imara-diff = "0.1.5"
5050

51+
[dev-dependencies]
52+
indoc = "2.0.4"
53+
5154
[features]
5255
# Turn off rayon for profiling
5356
singlethreaded = []
5457

55-
[dev-dependencies]
56-
indoc = "2.0.4"
58+
[lints]
59+
workspace = true

crates/ruff_dev/src/generate_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub(crate) fn main(args: &Args) -> Result<()> {
4949

5050
if rule.is_preview() || rule.is_nursery() {
5151
output.push_str(
52-
r#"This rule is unstable and in [preview](../preview.md). The `--preview` flag is required for use."#,
52+
r"This rule is unstable and in [preview](../preview.md). The `--preview` flag is required for use.",
5353
);
5454
output.push('\n');
5555
output.push('\n');

crates/ruff_formatter/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ insta = { workspace = true }
2929
[features]
3030
serde = ["dep:serde", "ruff_text_size/serde"]
3131
schemars = ["dep:schemars", "ruff_text_size/schemars"]
32+
33+
[lints]
34+
workspace = true

crates/ruff_formatter/src/printer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,14 +1711,14 @@ mod tests {
17111711
));
17121712

17131713
assert_eq!(
1714-
r#"a
1714+
"a
17151715
b
17161716
c
17171717
d
17181718
d
17191719
c
17201720
b
1721-
a"#,
1721+
a",
17221722
formatted.as_code()
17231723
);
17241724
}
@@ -2047,10 +2047,10 @@ two lines`,
20472047

20482048
assert_eq!(
20492049
printed.as_code(),
2050-
r#"Group with id-2
2050+
"Group with id-2
20512051
Group with id-1 does not fit on the line because it exceeds the line width of 80 characters by
20522052
Group 2 fits
2053-
Group 1 breaks"#
2053+
Group 1 breaks"
20542054
);
20552055
}
20562056

crates/ruff_index/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ ruff_macros = { path = "../ruff_macros" }
1717

1818
[dev-dependencies]
1919
static_assertions = "1.1.0"
20+
21+
[lints]
22+
workspace = true

crates/ruff_linter/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ default = []
8686
schemars = ["dep:schemars"]
8787
# Enables the UnreachableCode rule
8888
unreachable-code = []
89+
90+
[lints]
91+
workspace = true

crates/ruff_linter/src/fix/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mod tests {
171171

172172
#[test]
173173
fn empty_file() {
174-
let locator = Locator::new(r#""#);
174+
let locator = Locator::new(r"");
175175
let diagnostics = create_diagnostics([]);
176176
let FixResult {
177177
code,
@@ -225,10 +225,10 @@ print("hello world")
225225
#[test]
226226
fn apply_one_replacement() {
227227
let locator = Locator::new(
228-
r#"
228+
r"
229229
class A(object):
230230
...
231-
"#
231+
"
232232
.trim(),
233233
);
234234
let diagnostics = create_diagnostics([Edit::replacement(
@@ -243,10 +243,10 @@ class A(object):
243243
} = apply_fixes(diagnostics.iter(), &locator);
244244
assert_eq!(
245245
code,
246-
r#"
246+
r"
247247
class A(Bar):
248248
...
249-
"#
249+
"
250250
.trim(),
251251
);
252252
assert_eq!(fixes.values().sum::<usize>(), 1);
@@ -262,10 +262,10 @@ class A(Bar):
262262
#[test]
263263
fn apply_one_removal() {
264264
let locator = Locator::new(
265-
r#"
265+
r"
266266
class A(object):
267267
...
268-
"#
268+
"
269269
.trim(),
270270
);
271271
let diagnostics = create_diagnostics([Edit::deletion(TextSize::new(7), TextSize::new(15))]);
@@ -276,10 +276,10 @@ class A(object):
276276
} = apply_fixes(diagnostics.iter(), &locator);
277277
assert_eq!(
278278
code,
279-
r#"
279+
r"
280280
class A:
281281
...
282-
"#
282+
"
283283
.trim()
284284
);
285285
assert_eq!(fixes.values().sum::<usize>(), 1);
@@ -295,10 +295,10 @@ class A:
295295
#[test]
296296
fn apply_two_removals() {
297297
let locator = Locator::new(
298-
r#"
298+
r"
299299
class A(object, object, object):
300300
...
301-
"#
301+
"
302302
.trim(),
303303
);
304304
let diagnostics = create_diagnostics([
@@ -313,10 +313,10 @@ class A(object, object, object):
313313

314314
assert_eq!(
315315
code,
316-
r#"
316+
r"
317317
class A(object):
318318
...
319-
"#
319+
"
320320
.trim()
321321
);
322322
assert_eq!(fixes.values().sum::<usize>(), 2);
@@ -334,10 +334,10 @@ class A(object):
334334
#[test]
335335
fn ignore_overlapping_fixes() {
336336
let locator = Locator::new(
337-
r#"
337+
r"
338338
class A(object):
339339
...
340-
"#
340+
"
341341
.trim(),
342342
);
343343
let diagnostics = create_diagnostics([
@@ -351,10 +351,10 @@ class A(object):
351351
} = apply_fixes(diagnostics.iter(), &locator);
352352
assert_eq!(
353353
code,
354-
r#"
354+
r"
355355
class A:
356356
...
357-
"#
357+
"
358358
.trim(),
359359
);
360360
assert_eq!(fixes.values().sum::<usize>(), 1);

0 commit comments

Comments
 (0)