Skip to content

Commit eba5b44

Browse files
committed
Add OnceHelp lint level (same as OnceNote, except for help)
1 parent bf1e3f3 commit eba5b44

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+1-1
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

+8
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

+5-3
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"),

0 commit comments

Comments
 (0)