Skip to content

Commit 04374cd

Browse files
committed
Auto merge of #114089 - Urgau:allow-with-implied-by, r=petrochenkov
Add an allow attribute suggestion along with the implied by suggestion This PR adds an `#[allow(...)]` attribute hep suggestion along with the implied by suggestion: ```diff note: `-W dead-code` implied by `-W unused` + help: to override `-W unused` add `#[allow(dead_code)]` ``` This PR also adds the `OnceHelp` lint level (similar to `OnceNote`) to only put the help message one time, like the implied note. Related to #114030
2 parents ec08a03 + 9190e96 commit 04374cd

File tree

770 files changed

+871
-5
lines changed

Some content is hidden

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

770 files changed

+871
-5
lines changed

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn annotation_type_for_level(level: Level) -> AnnotationType {
9191
}
9292
Level::Warning(_) => AnnotationType::Warning,
9393
Level::Note | Level::OnceNote => AnnotationType::Note,
94-
Level::Help => AnnotationType::Help,
94+
Level::Help | Level::OnceHelp => AnnotationType::Help,
9595
// FIXME(#59346): Not sure how to map this level
9696
Level::FailureNote => AnnotationType::Error,
9797
Level::Allow => panic!("Should not call with Allow"),

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ impl Diagnostic {
270270
| Level::Note
271271
| Level::OnceNote
272272
| Level::Help
273+
| Level::OnceHelp
273274
| Level::Allow
274275
| Level::Expect(_) => false,
275276
}
@@ -532,6 +533,13 @@ impl Diagnostic {
532533
self
533534
}
534535

536+
/// Prints the span with a help above it.
537+
/// This is like [`Diagnostic::help()`], but it gets its own span.
538+
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
539+
self.sub(Level::OnceHelp, msg, MultiSpan::new(), None);
540+
self
541+
}
542+
535543
/// Add a help message attached to this diagnostic with a customizable highlighted message.
536544
pub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self {
537545
self.sub_with_highlights(Level::Help, msg, MultiSpan::new(), None);

compiler/rustc_errors/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ impl HandlerInner {
13901390
debug!(?self.emitted_diagnostics);
13911391
let already_emitted_sub = |sub: &mut SubDiagnostic| {
13921392
debug!(?sub);
1393-
if sub.level != Level::OnceNote {
1393+
if sub.level != Level::OnceNote && sub.level != Level::OnceHelp {
13941394
return false;
13951395
}
13961396
let mut hasher = StableHasher::new();
@@ -1792,6 +1792,8 @@ pub enum Level {
17921792
/// A note that is only emitted once.
17931793
OnceNote,
17941794
Help,
1795+
/// A help that is only emitted once.
1796+
OnceHelp,
17951797
FailureNote,
17961798
Allow,
17971799
Expect(LintExpectationId),
@@ -1816,7 +1818,7 @@ impl Level {
18161818
Note | OnceNote => {
18171819
spec.set_fg(Some(Color::Green)).set_intense(true);
18181820
}
1819-
Help => {
1821+
Help | OnceHelp => {
18201822
spec.set_fg(Some(Color::Cyan)).set_intense(true);
18211823
}
18221824
FailureNote => {}
@@ -1831,7 +1833,7 @@ impl Level {
18311833
Fatal | Error { .. } => "error",
18321834
Warning(_) => "warning",
18331835
Note | OnceNote => "note",
1834-
Help => "help",
1836+
Help | OnceHelp => "help",
18351837
FailureNote => "failure-note",
18361838
Allow => panic!("Shouldn't call on allowed error"),
18371839
Expect(_) => panic!("Shouldn't call on expected error"),

compiler/rustc_middle/src/lint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ pub fn explain_lint_level_source(
225225
err.note_once(format!(
226226
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
227227
));
228+
err.help_once(format!(
229+
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
230+
));
228231
}
229232
}
230233
LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {

src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | std::f32::MAX;
55
| ^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::absolute-paths` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]`
89

910
error: consider bringing this path into scope with the `use` keyword
1011
--> $DIR/absolute_paths.rs:41:5

src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | std::f32::MAX;
55
| ^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::absolute-paths` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]`
89

910
error: consider bringing this path into scope with the `use` keyword
1011
--> $DIR/absolute_paths.rs:41:5

src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | println!("val='{}'", local_i32);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]`
89
help: change this to
910
|
1011
LL - println!("val='{}'", local_i32);
@@ -30,6 +31,7 @@ LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
3031
| ^^^
3132
|
3233
= note: `-D clippy::print-literal` implied by `-D warnings`
34+
= help: to override `-D warnings` add `#[allow(clippy::print_literal)]`
3335
help: try
3436
|
3537
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);

src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let _ = Baz + Baz;
55
| ^^^^^^^^^
66
|
77
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
89

910
error: arithmetic operation that can potentially result in unexpected side-effects
1011
--> $DIR/arithmetic_side_effects_allowed.rs:80:13

src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | const ABOVE: [u8; 11] = [0; 11];
77
| help: make this a static item: `static`
88
|
99
= note: `-D clippy::large-const-arrays` implied by `-D warnings`
10+
= help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]`
1011

1112
error: allocating a local array larger than 10 bytes
1213
--> $DIR/array_size_threshold.rs:4:25
@@ -16,6 +17,7 @@ LL | const ABOVE: [u8; 11] = [0; 11];
1617
|
1718
= help: consider allocating on the heap with `vec![0; 11].into_boxed_slice()`
1819
= note: `-D clippy::large-stack-arrays` implied by `-D warnings`
20+
= help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]`
1921

2022
error: allocating a local array larger than 10 bytes
2123
--> $DIR/array_size_threshold.rs:8:17

src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | let _x = String::from("hello");
66
|
77
= note: strings are bad (from clippy.toml)
88
= note: `-D clippy::await-holding-invalid-type` implied by `-D warnings`
9+
= help: to override `-D warnings` add `#[allow(clippy::await_holding_invalid_type)]`
910

1011
error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml`
1112
--> $DIR/await_holding_invalid_type.rs:10:9

0 commit comments

Comments
 (0)