Skip to content

Commit 202aebf

Browse files
committed
Degeneralize TopLevel notes to be only about expected/found
1 parent 909bd69 commit 202aebf

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

src/librustc_errors/diagnostic.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,17 @@ impl Diagnostic {
9595
found_extra: &fmt::Display)
9696
-> &mut Self
9797
{
98-
// For now, just attach these as notes
99-
self.top_level_note(&format!("expected {} `{}`{}", label, expected, expected_extra));
100-
self.top_level_note(&format!(" found {} `{}`{}", label, found, found_extra));
98+
self.sub(Level::Expected,
99+
&format!("{} `{}`{}", label, expected, expected_extra),
100+
MultiSpan::new(),
101+
None);
102+
self.sub(Level::Found,
103+
&format!("{} `{}`{}", label, found, found_extra),
104+
MultiSpan::new(),
105+
None);
101106
self
102107
}
103108

104-
pub fn top_level_note(&mut self, msg: &str) -> &mut Self {
105-
self.sub(Level::TopLevel, msg, MultiSpan::new(), None);
106-
self
107-
}
108109

109110
pub fn note(&mut self, msg: &str) -> &mut Self {
110111
self.sub(Level::Note, msg, MultiSpan::new(), None);

src/librustc_errors/diagnostic_builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ impl<'a> DiagnosticBuilder<'a> {
9191
Level::Warning |
9292
Level::Note |
9393
Level::Help |
94-
Level::TopLevel |
94+
Level::Expected |
95+
Level::Found |
9596
Level::Cancelled => {
9697
}
9798
}

src/librustc_errors/emitter.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -720,18 +720,23 @@ impl EmitterWriter {
720720
}
721721
draw_note_separator(&mut buffer, 0, max_line_num_len + 1);
722722
match level {
723-
&Level::TopLevel => (),
723+
&Level::Expected => {
724+
buffer.append(0, &level.to_string(), Style::NoStyle);
725+
buffer.append(0, " ", Style::NoStyle);
726+
}
727+
&Level::Found => {
728+
buffer.append(0, " ", Style::NoStyle);
729+
buffer.append(0, &level.to_string(), Style::NoStyle);
730+
buffer.append(0, " ", Style::NoStyle);
731+
},
724732
_ => {
725733
buffer.append(0, &level.to_string(), Style::HeaderMsg);
726734
buffer.append(0, ": ", Style::NoStyle);
727735
}
728736
}
729737
buffer.append(0, msg, Style::NoStyle);
730738
} else {
731-
match level {
732-
&Level::TopLevel => (),
733-
_ => buffer.append(0, &level.to_string(), Style::Level(level.clone())),
734-
}
739+
buffer.append(0, &level.to_string(), Style::Level(level.clone()));
735740
match code {
736741
&Some(ref code) => {
737742
buffer.append(0, "[", Style::Level(level.clone()));

src/librustc_errors/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ pub enum Level {
496496
Note,
497497
Help,
498498
Cancelled,
499-
// A note without the `note: ` prefix in the presentation
500-
TopLevel,
499+
// Expected/Found type/struct/variant
500+
Expected,
501+
Found,
501502
}
502503

503504
impl fmt::Display for Level {
@@ -517,7 +518,7 @@ impl Level {
517518
term::color::YELLOW
518519
}
519520
}
520-
Note | TopLevel => term::color::BRIGHT_GREEN,
521+
Note | Expected | Found => term::color::BRIGHT_GREEN,
521522
Help => term::color::BRIGHT_CYAN,
522523
Cancelled => unreachable!(),
523524
}
@@ -529,7 +530,8 @@ impl Level {
529530
Fatal | PhaseFatal | Error => "error",
530531
Warning => "warning",
531532
Note => "note",
532-
TopLevel => "note",
533+
Expected => "expected",
534+
Found => "found",
533535
Help => "help",
534536
Cancelled => panic!("Shouldn't call on cancelled error"),
535537
}

0 commit comments

Comments
 (0)