Skip to content

Commit 8f6b525

Browse files
committed
Add emit_for function in diagnostic
When emmitting a note, previously it was not known if the note was for an error or a warning. If it was for a warning, then with `-Awarnings` it should not have been print. The `emit_for` function allows someone to specify which level should determine its visibility.
1 parent 242ed0b commit 8f6b525

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ impl Handler {
207207
if lvl == Warning && !self.can_emit_warnings { return }
208208
self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl);
209209
}
210+
pub fn emit_for(&self,
211+
cmsp: Option<(&codemap::CodeMap, Span)>,
212+
msg: &str,
213+
lvl: Level,
214+
for_lvl: Level) {
215+
if for_lvl == Warning && !self.can_emit_warnings { return }
216+
self.emit.borrow_mut().emit(cmsp, msg, None, lvl);
217+
}
210218
pub fn custom_emit(&self, cm: &codemap::CodeMap,
211219
sp: RenderSpan, msg: &str, lvl: Level) {
212220
if lvl == Warning && !self.can_emit_warnings { return }

src/libsyntax/parse/obsolete.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use codemap::Span;
1818
use parse::parser;
1919
use parse::token;
2020
use ptr::P;
21+
use diagnostic::{Warning, Error, Note};
2122

2223
/// The specific types of unsupported syntax
2324
#[derive(Copy, PartialEq, Eq, Hash)]
@@ -87,10 +88,11 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
8788
}
8889

8990
if !self.obsolete_set.contains(&kind) {
91+
let for_level = if error { Error } else { Warning };
9092
self.sess
9193
.span_diagnostic
9294
.handler()
93-
.note(&format!("{}", desc));
95+
.emit_for(None, &format!("{}", desc), Note, for_level);
9496
self.obsolete_set.insert(kind);
9597
}
9698
}

0 commit comments

Comments
 (0)