about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-04 23:09:56 +0000
committerbors <bors@rust-lang.org>2023-09-04 23:09:56 +0000
commit04374cd74264b9d3b7d2d3df08ae38df8af4d020 (patch)
tree6e1eb39429f2567231705c6a6cfbe499234f28e5 /compiler/rustc_errors/src
parentec08a0337f3556212525dbf1d3b41e19bdf27621 (diff)
parent9190e960e1c6b2c2e73c23e85545656ab1577761 (diff)
downloadrust-04374cd74264b9d3b7d2d3df08ae38df8af4d020.tar.gz
rust-04374cd74264b9d3b7d2d3df08ae38df8af4d020.zip
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 https://github.com/rust-lang/rust/issues/114030
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs2
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs8
-rw-r--r--compiler/rustc_errors/src/lib.rs8
3 files changed, 14 insertions, 4 deletions
diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
index a88fba6dae6..d7a008f9a57 100644
--- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
+++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
@@ -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"),
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index a96e317df55..3fd087b1d5e 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -270,6 +270,7 @@ impl Diagnostic {
             | Level::Note
             | Level::OnceNote
             | Level::Help
+            | Level::OnceHelp
             | Level::Allow
             | Level::Expect(_) => false,
         }
@@ -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);
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 9bb1a6a2b14..55c4ec66cd9 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -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();
@@ -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),
@@ -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 => {}
@@ -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"),