diff --git a/src/config.rs b/src/config.rs index c3837923..baa98bdb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,8 @@ use regex::bytes::Regex; -use crate::{dependencies::build_dependencies, CommandBuilder, Filter, Match, Mode, RustfixMode}; +use crate::{ + dependencies::build_dependencies, CommandBuilder, Filter, Level, Match, Mode, RustfixMode, +}; pub use color_eyre; use color_eyre::eyre::Result; use std::{ @@ -59,6 +61,9 @@ pub struct Config { pub run_only_ignored: bool, /// Filters must match exactly instead of just checking for substrings. pub filter_exact: bool, + /// If set, lower level annotations will still be checked but we won't go below + /// `forced_lowest_annotation_level`. + pub forced_lowest_annotation_level: Option, } impl Config { @@ -103,6 +108,7 @@ impl Config { list: false, run_only_ignored: false, filter_exact: false, + forced_lowest_annotation_level: None, } } diff --git a/src/lib.rs b/src/lib.rs index 95f553e1..a38f00db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ use dependencies::{Build, BuildManager}; use lazy_static::lazy_static; use parser::{ErrorMatch, MaybeSpanned, OptWithLine, Revisioned, Spanned}; use regex::bytes::{Captures, Regex}; -use rustc_stderr::{Level, Message}; +use rustc_stderr::Message; use spanned::Span; use status_emitter::{StatusEmitter, TestStatus}; use std::borrow::Cow; @@ -46,6 +46,7 @@ pub use cmd::*; pub use config::*; pub use error::*; pub use mode::*; +pub use rustc_stderr::Level; /// A filter's match rule. #[derive(Clone, Debug)] @@ -665,6 +666,7 @@ impl dyn TestStatus { status, &stdout, &stderr, + config.forced_lowest_annotation_level, )?; if let Mode::Run { .. } = *mode { @@ -990,6 +992,7 @@ fn check_test_result( status: ExitStatus, stdout: &[u8], stderr: &[u8], + forced_lowest_annotation_level: Option, ) -> Result { let mut errors = vec![]; errors.extend(mode.ok(status).err()); @@ -1013,6 +1016,7 @@ fn check_test_result( config, revision, comments, + forced_lowest_annotation_level, )?; if errors.is_empty() { Ok(command) @@ -1067,6 +1071,7 @@ fn check_annotations( config: &Config, revision: &str, comments: &Comments, + forced_lowest_annotation_level: Option, ) -> Result<(), Errored> { let error_patterns = comments .for_revision(revision) @@ -1094,7 +1099,7 @@ fn check_annotations( // The order on `Level` is such that `Error` is the highest level. // We will ensure that *all* diagnostics of level at least `lowest_annotation_level` // are matched. - let mut lowest_annotation_level = Level::Error; + let mut lowest_annotation_level = forced_lowest_annotation_level.unwrap_or(Level::Error); for &ErrorMatch { ref pattern, level, @@ -1107,7 +1112,11 @@ fn check_annotations( // If we found a diagnostic with a level annotation, make sure that all // diagnostics of that level have annotations, even if we don't end up finding a matching diagnostic // for this pattern. - if lowest_annotation_level > level { + if lowest_annotation_level > level + && forced_lowest_annotation_level + .map(|forced_minimum| forced_minimum <= level) + .unwrap_or(true) + { lowest_annotation_level = level; } diff --git a/src/rustc_stderr.rs b/src/rustc_stderr.rs index 0daa422b..c7d1488a 100644 --- a/src/rustc_stderr.rs +++ b/src/rustc_stderr.rs @@ -14,12 +14,18 @@ struct RustcMessage { children: Vec, } +/// Message level. #[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] -pub(crate) enum Level { +pub enum Level { + /// Internal compiler error. Ice = 5, + /// Compilation error. Error = 4, + /// Compilation warning. Warn = 3, + /// Help message. Help = 2, + /// Note message. Note = 1, /// Only used for "For more information about this error, try `rustc --explain EXXXX`". FailureNote = 0, diff --git a/src/tests.rs b/src/tests.rs index 137001df..5069b1d4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -43,6 +43,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -81,6 +82,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -108,6 +110,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -139,6 +142,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -180,6 +184,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -223,6 +228,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -277,6 +283,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] { @@ -341,6 +348,7 @@ fn main() { &config, "", &comments, + None, ) .unwrap(); match &errors[..] {