Skip to content

Commit

Permalink
Auto merge of #114089 - Urgau:allow-with-implied-by, r=petrochenkov
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 4, 2023
2 parents ec08a03 + 9190e96 commit 04374cd
Show file tree
Hide file tree
Showing 770 changed files with 871 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn annotation_type_for_level(level: Level) -> AnnotationType {
}
Level::Warning(_) => AnnotationType::Warning,
Level::Note | Level::OnceNote => AnnotationType::Note,
Level::Help => AnnotationType::Help,
Level::Help | Level::OnceHelp => AnnotationType::Help,
// FIXME(#59346): Not sure how to map this level
Level::FailureNote => AnnotationType::Error,
Level::Allow => panic!("Should not call with Allow"),
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ impl Diagnostic {
| Level::Note
| Level::OnceNote
| Level::Help
| Level::OnceHelp
| Level::Allow
| Level::Expect(_) => false,
}
Expand Down Expand Up @@ -532,6 +533,13 @@ impl Diagnostic {
self
}

/// Prints the span with a help above it.
/// This is like [`Diagnostic::help()`], but it gets its own span.
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
self.sub(Level::OnceHelp, msg, MultiSpan::new(), None);
self
}

/// Add a help message attached to this diagnostic with a customizable highlighted message.
pub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self {
self.sub_with_highlights(Level::Help, msg, MultiSpan::new(), None);
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ impl HandlerInner {
debug!(?self.emitted_diagnostics);
let already_emitted_sub = |sub: &mut SubDiagnostic| {
debug!(?sub);
if sub.level != Level::OnceNote {
if sub.level != Level::OnceNote && sub.level != Level::OnceHelp {
return false;
}
let mut hasher = StableHasher::new();
Expand Down Expand Up @@ -1792,6 +1792,8 @@ pub enum Level {
/// A note that is only emitted once.
OnceNote,
Help,
/// A help that is only emitted once.
OnceHelp,
FailureNote,
Allow,
Expect(LintExpectationId),
Expand All @@ -1816,7 +1818,7 @@ impl Level {
Note | OnceNote => {
spec.set_fg(Some(Color::Green)).set_intense(true);
}
Help => {
Help | OnceHelp => {
spec.set_fg(Some(Color::Cyan)).set_intense(true);
}
FailureNote => {}
Expand All @@ -1831,7 +1833,7 @@ impl Level {
Fatal | Error { .. } => "error",
Warning(_) => "warning",
Note | OnceNote => "note",
Help => "help",
Help | OnceHelp => "help",
FailureNote => "failure-note",
Allow => panic!("Shouldn't call on allowed error"),
Expect(_) => panic!("Shouldn't call on expected error"),
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ pub fn explain_lint_level_source(
err.note_once(format!(
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
));
err.help_once(format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
));
}
}
LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | std::f32::MAX;
| ^^^^^^^^^^^^^
|
= note: `-D clippy::absolute-paths` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]`

error: consider bringing this path into scope with the `use` keyword
--> $DIR/absolute_paths.rs:41:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | std::f32::MAX;
| ^^^^^^^^^^^^^
|
= note: `-D clippy::absolute-paths` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]`

error: consider bringing this path into scope with the `use` keyword
--> $DIR/absolute_paths.rs:41:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | println!("val='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]`
help: change this to
|
LL - println!("val='{}'", local_i32);
Expand All @@ -30,6 +31,7 @@ LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^
|
= note: `-D clippy::print-literal` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::print_literal)]`
help: try
|
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _ = Baz + Baz;
| ^^^^^^^^^
|
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`

error: arithmetic operation that can potentially result in unexpected side-effects
--> $DIR/arithmetic_side_effects_allowed.rs:80:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | const ABOVE: [u8; 11] = [0; 11];
| help: make this a static item: `static`
|
= note: `-D clippy::large-const-arrays` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]`

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

error: allocating a local array larger than 10 bytes
--> $DIR/array_size_threshold.rs:8:17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let _x = String::from("hello");
|
= note: strings are bad (from clippy.toml)
= note: `-D clippy::await-holding-invalid-type` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::await_holding_invalid_type)]`

error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml`
--> $DIR/await_holding_invalid_type.rs:10:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LL | fn cognitive_complexity() {
|
= help: you could split it up into multiple smaller functions
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]`

error: aborting due to previous error; 2 warnings emitted

1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::dbg-macro` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]`
help: remove the invocation before committing it to a version control system
|
LL | if let Some(n) = n.checked_sub(4) { n } else { n }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | println!("one");
| ^^^^^^^^^^^^^^^
|
= note: `-D clippy::disallowed-macros` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_macros)]`

error: use of a disallowed macro `std::println`
--> $DIR/disallowed_macros.rs:11:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let foo = "bar";
| ^^^
|
= note: `-D clippy::disallowed-names` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]`

error: use of a disallowed/placeholder name `ducks`
--> $DIR/disallowed_names.rs:7:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let ducks = ["quack", "quack"];
| ^^^^^
|
= note: `-D clippy::disallowed-names` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::doc-markdown` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]`
help: try
|
LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | /// OAuth and LaTeX are inside Clippy's default list.
| ^^^^^
|
= note: `-D clippy::doc-markdown` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]`
help: try
|
LL | /// `OAuth` and LaTeX are inside Clippy's default list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let w = { 3 };
|
= help: try refactoring your code to minimize nesting
= note: `-D clippy::excessive-nesting` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]`

error: this block is too nested
--> $DIR/excessive_nesting.rs:67:17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let _ = opt.expect("");
|
= note: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::expect_used)]`

error: used `expect()` on a `Result` value
--> $DIR/expect_used.rs:12:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | fn g(_: bool, _: bool) {}
|
= help: consider refactoring bools into two-variant enums
= note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::fn_params_excessive_bools)]`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LL | | }
| |_^
|
= note: `-D clippy::too-many-lines` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]`

error: this function has too many lines (4/1)
--> $DIR/test.rs:25:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ note: same as this
LL | if x.get() {
| ^^^^^^^
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | should_warn().await;
| ^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(should_warn())`
|
= note: `-D clippy::large-futures` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_futures)]`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
|
= note: the configuration allows a maximum size of 600 bytes
= note: `-D clippy::large-include-file` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_include_file)]`
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: attempted to include a large file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _fail1 = 100_200_300.123456789;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.123_456_789`
|
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]`

error: long literal lacking separators
--> $DIR/test.rs:22:18
Expand All @@ -13,6 +14,7 @@ LL | let _fail2 = 100200300.300200100;
| ^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.300_200_100`
|
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | use extern_types::Aaa;
| ^^^
|
= note: `-D clippy::min-ident-chars` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]`

error: this ident is too short (3 <= 3)
--> $DIR/min_ident_chars.rs:10:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _: Option<u64> = Some(&16).map(|b| *b);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `Some(&16).cloned()`
|
= note: `-D clippy::map-clone` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::map_clone)]`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | use std::process::{exit as wrong_exit, Child as Kid};
| ^^^^^^^^^^^^^^^^^^ help: try: `exit as goodbye`
|
= note: `-D clippy::missing-enforced-import-renames` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::missing_enforced_import_renames)]`

error: this import should be renamed
--> $DIR/conf_missing_enforced_import_rename.rs:6:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | | }
| |_________^
|
= note: `-D clippy::module-inception` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::module_inception)]`

error: module has the same name as its containing module
--> $DIR/module_inception.rs:11:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _ = vec! {1, 2, 3};
| ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]`
|
= note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::nonstandard_macro_braces)]`

error: use of irregular braces for `format!` macro
--> $DIR/conf_nonstandard_macro_braces.rs:44:13
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui-toml/print_macro/print_macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | print!("{n}");
| ^^^^^^^^^^^^^
|
= note: `-D clippy::print-stdout` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::print_stdout)]`

error: use of `eprint!`
--> $DIR/print_macro.rs:7:5
Expand All @@ -13,6 +14,7 @@ LL | eprint!("{n}");
| ^^^^^^^^^^^^^^
|
= note: `-D clippy::print-stderr` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::print_stderr)]`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | pub(crate) fn crate_no_docs() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]`

error: missing documentation for a function
--> $DIR/pub_crate_missing_doc.rs:15:5
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | { unit_fn_block(); }
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::semicolon-outside-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]`
help: put the `;` here
|
LL - { unit_fn_block(); }
Expand Down Expand Up @@ -33,6 +34,7 @@ LL | | };
| |______^
|
= note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]`
help: put the `;` here
|
LL ~ unit_fn_block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LL | | };
| |______^
|
= note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]`
help: put the `;` here
|
LL ~ unit_fn_block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | { unit_fn_block(); }
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::semicolon-outside-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]`
help: put the `;` here
|
LL - { unit_fn_block(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LL | rc_is_not_send: Rc<String>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use a thread-safe type that implements `Send`
= note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]`

error: some fields in `MultiField<T>` are not safe to be sent to another thread
--> $DIR/test.rs:19:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LL | | }
|
= help: consider using a state machine or refactoring bools into two-variant enums
= note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]`

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LL | x[index];
|
= help: consider using `.get(n)` or `.get_mut(n)` instead
= note: `-D clippy::indexing-slicing` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]`

error: indexing may panic
--> $DIR/test.rs:46:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | fn test(toto: ()) {}
| ^^^^
|
= note: `-D clippy::disallowed-names` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]`

error: use of a disallowed/placeholder name `toto`
--> $DIR/conf_french_disallowed_name.rs:9:9
Expand Down
Loading

0 comments on commit 04374cd

Please sign in to comment.