Check for warnings after compilation (#772)

* Check for warnings after compilation

* Always catch errors first
This commit is contained in:
Bjerg 2022-01-07 15:53:36 +01:00 committed by GitHub
parent 24fd7e16fd
commit 21a4adea3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -531,11 +531,16 @@ pub struct CompilerOutput {
} }
impl CompilerOutput { impl CompilerOutput {
/// Whether the output contains an compiler error /// Whether the output contains a compiler error
pub fn has_error(&self) -> bool { pub fn has_error(&self) -> bool {
self.errors.iter().any(|err| err.severity.is_error()) self.errors.iter().any(|err| err.severity.is_error())
} }
/// Whether the output contains a compiler warning
pub fn has_warning(&self) -> bool {
self.errors.iter().any(|err| err.severity.is_warning())
}
pub fn diagnostics<'a>(&'a self, ignored_error_codes: &'a [u64]) -> OutputDiagnostics { pub fn diagnostics<'a>(&'a self, ignored_error_codes: &'a [u64]) -> OutputDiagnostics {
OutputDiagnostics { errors: &self.errors, ignored_error_codes } OutputDiagnostics { errors: &self.errors, ignored_error_codes }
} }
@ -687,11 +692,20 @@ impl<'a> OutputDiagnostics<'a> {
pub fn has_error(&self) -> bool { pub fn has_error(&self) -> bool {
self.errors.iter().any(|err| err.severity.is_error()) self.errors.iter().any(|err| err.severity.is_error())
} }
/// Returns true if there is at least one warning
pub fn has_warning(&self) -> bool {
self.errors.iter().any(|err| err.severity.is_warning())
}
} }
impl<'a> fmt::Display for OutputDiagnostics<'a> { impl<'a> fmt::Display for OutputDiagnostics<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if !self.has_error() { if self.has_error() {
f.write_str("Compiler run failed")?;
} else if self.has_warning() {
f.write_str("Compiler run successful (with warnings)")?;
} else {
f.write_str("Compiler run successful")?; f.write_str("Compiler run successful")?;
} }
for err in self.errors { for err in self.errors {