compiletest: Always preserve kind for compiler diagnostics
Those that didn't previously preserved kind are now marked as not requiring annotations to keep the previous behavior. Also, do not lose diagnostics with an empty message.
This commit is contained in:
parent
42048ea122
commit
b86b3fb640
5 changed files with 46 additions and 29 deletions
|
@ -53,6 +53,10 @@ pub struct Error {
|
||||||
/// `None` if not specified or unknown message kind.
|
/// `None` if not specified or unknown message kind.
|
||||||
pub kind: Option<ErrorKind>,
|
pub kind: Option<ErrorKind>,
|
||||||
pub msg: String,
|
pub msg: String,
|
||||||
|
/// For some `Error`s, like secondary lines of multi-line diagnostics, line annotations
|
||||||
|
/// are not mandatory, even if they would otherwise be mandatory for primary errors.
|
||||||
|
/// Only makes sense for "actual" errors, not for "expected" errors.
|
||||||
|
pub require_annotation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
@ -182,7 +186,7 @@ fn parse_expected(
|
||||||
kind,
|
kind,
|
||||||
msg
|
msg
|
||||||
);
|
);
|
||||||
Some((follow_prev, Error { line_num, kind, msg }))
|
Some((follow_prev, Error { line_num, kind, msg, require_annotation: true }))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -231,36 +231,42 @@ fn push_actual_errors(
|
||||||
// We expect to replace these with something more structured anyhow.
|
// We expect to replace these with something more structured anyhow.
|
||||||
let mut message_lines = diagnostic.message.lines();
|
let mut message_lines = diagnostic.message.lines();
|
||||||
let kind = ErrorKind::from_str(&diagnostic.level).ok();
|
let kind = ErrorKind::from_str(&diagnostic.level).ok();
|
||||||
if let Some(first_line) = message_lines.next() {
|
let first_line = message_lines.next().unwrap_or(&diagnostic.message);
|
||||||
let ignore = |s| {
|
if primary_spans.is_empty() {
|
||||||
static RE: OnceLock<Regex> = OnceLock::new();
|
static RE: OnceLock<Regex> = OnceLock::new();
|
||||||
RE.get_or_init(|| {
|
let re_init =
|
||||||
Regex::new(r"aborting due to \d+ previous errors?|\d+ warnings? emitted").unwrap()
|
|| Regex::new(r"aborting due to \d+ previous errors?|\d+ warnings? emitted").unwrap();
|
||||||
})
|
errors.push(Error {
|
||||||
.is_match(s)
|
line_num: None,
|
||||||
};
|
kind,
|
||||||
|
msg: with_code(None, first_line),
|
||||||
if primary_spans.is_empty() && !ignore(first_line) {
|
require_annotation: !RE.get_or_init(re_init).is_match(first_line),
|
||||||
errors.push(Error { line_num: None, kind, msg: with_code(None, first_line) });
|
});
|
||||||
|
} else {
|
||||||
|
for span in primary_spans {
|
||||||
|
errors.push(Error {
|
||||||
|
line_num: Some(span.line_start),
|
||||||
|
kind,
|
||||||
|
msg: with_code(Some(span), first_line),
|
||||||
|
require_annotation: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for next_line in message_lines {
|
||||||
|
if primary_spans.is_empty() {
|
||||||
|
errors.push(Error {
|
||||||
|
line_num: None,
|
||||||
|
kind,
|
||||||
|
msg: with_code(None, next_line),
|
||||||
|
require_annotation: false,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
for span in primary_spans {
|
for span in primary_spans {
|
||||||
errors.push(Error {
|
errors.push(Error {
|
||||||
line_num: Some(span.line_start),
|
line_num: Some(span.line_start),
|
||||||
kind,
|
kind,
|
||||||
msg: with_code(Some(span), first_line),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for next_line in message_lines {
|
|
||||||
if primary_spans.is_empty() {
|
|
||||||
errors.push(Error { line_num: None, kind: None, msg: with_code(None, next_line) });
|
|
||||||
} else {
|
|
||||||
for span in primary_spans {
|
|
||||||
errors.push(Error {
|
|
||||||
line_num: Some(span.line_start),
|
|
||||||
kind: None,
|
|
||||||
msg: with_code(Some(span), next_line),
|
msg: with_code(Some(span), next_line),
|
||||||
|
require_annotation: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,6 +280,7 @@ fn push_actual_errors(
|
||||||
line_num: Some(span.line_start + index),
|
line_num: Some(span.line_start + index),
|
||||||
kind: Some(ErrorKind::Suggestion),
|
kind: Some(ErrorKind::Suggestion),
|
||||||
msg: line.to_string(),
|
msg: line.to_string(),
|
||||||
|
require_annotation: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,6 +299,7 @@ fn push_actual_errors(
|
||||||
line_num: Some(span.line_start),
|
line_num: Some(span.line_start),
|
||||||
kind: Some(ErrorKind::Note),
|
kind: Some(ErrorKind::Note),
|
||||||
msg: span.label.clone().unwrap(),
|
msg: span.label.clone().unwrap(),
|
||||||
|
require_annotation: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,6 +319,7 @@ fn push_backtrace(
|
||||||
line_num: Some(expansion.span.line_start),
|
line_num: Some(expansion.span.line_start),
|
||||||
kind: Some(ErrorKind::Note),
|
kind: Some(ErrorKind::Note),
|
||||||
msg: format!("in this expansion of {}", expansion.macro_decl_name),
|
msg: format!("in this expansion of {}", expansion.macro_decl_name),
|
||||||
|
require_annotation: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -811,6 +811,7 @@ impl<'test> TestCx<'test> {
|
||||||
expect_note: bool,
|
expect_note: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
!actual_error.msg.is_empty()
|
!actual_error.msg.is_empty()
|
||||||
|
&& actual_error.require_annotation
|
||||||
&& match actual_error.kind {
|
&& match actual_error.kind {
|
||||||
Some(ErrorKind::Help) => expect_help,
|
Some(ErrorKind::Help) => expect_help,
|
||||||
Some(ErrorKind::Note) => expect_note,
|
Some(ErrorKind::Note) => expect_note,
|
||||||
|
|
|
@ -6,11 +6,14 @@ extern crate issue_91800_macro;
|
||||||
#[derive(MyTrait)]
|
#[derive(MyTrait)]
|
||||||
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
|
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
|
||||||
//~| ERROR proc-macro derive produced unparsable tokens
|
//~| ERROR proc-macro derive produced unparsable tokens
|
||||||
|
//~| ERROR
|
||||||
#[attribute_macro]
|
#[attribute_macro]
|
||||||
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
|
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
|
||||||
|
//~| ERROR
|
||||||
struct MyStruct;
|
struct MyStruct;
|
||||||
|
|
||||||
fn_macro! {}
|
fn_macro! {}
|
||||||
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
|
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
|
||||||
|
//~| ERROR
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -21,7 +21,7 @@ LL | #[derive(MyTrait)]
|
||||||
= note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: macros that expand to items must be delimited with braces or followed by a semicolon
|
error: macros that expand to items must be delimited with braces or followed by a semicolon
|
||||||
--> $DIR/issue-91800.rs:9:1
|
--> $DIR/issue-91800.rs:10:1
|
||||||
|
|
|
|
||||||
LL | #[attribute_macro]
|
LL | #[attribute_macro]
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -29,7 +29,7 @@ LL | #[attribute_macro]
|
||||||
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error:
|
error:
|
||||||
--> $DIR/issue-91800.rs:9:1
|
--> $DIR/issue-91800.rs:10:1
|
||||||
|
|
|
|
||||||
LL | #[attribute_macro]
|
LL | #[attribute_macro]
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -37,7 +37,7 @@ LL | #[attribute_macro]
|
||||||
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: macros that expand to items must be delimited with braces or followed by a semicolon
|
error: macros that expand to items must be delimited with braces or followed by a semicolon
|
||||||
--> $DIR/issue-91800.rs:13:1
|
--> $DIR/issue-91800.rs:15:1
|
||||||
|
|
|
|
||||||
LL | fn_macro! {}
|
LL | fn_macro! {}
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
@ -45,7 +45,7 @@ LL | fn_macro! {}
|
||||||
= note: this error originates in the macro `fn_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `fn_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error:
|
error:
|
||||||
--> $DIR/issue-91800.rs:13:1
|
--> $DIR/issue-91800.rs:15:1
|
||||||
|
|
|
|
||||||
LL | fn_macro! {}
|
LL | fn_macro! {}
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue