Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1645dce

Browse files
committedApr 12, 2025·
compiletest: Make diagnostic kind mandatory on line annotations
1 parent 7cd6e2f commit 1645dce

File tree

362 files changed

+2301
-2038
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

362 files changed

+2301
-2038
lines changed
 

‎src/tools/compiletest/src/errors.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,18 @@ impl ErrorKind {
3030

3131
/// Either the canonical uppercase string, or some additional versions for compatibility.
3232
/// FIXME: consider keeping only the canonical versions here.
33-
fn from_user_str(s: &str) -> Option<ErrorKind> {
34-
Some(match s {
33+
pub fn from_user_str(s: &str) -> ErrorKind {
34+
match s {
3535
"HELP" | "help" => ErrorKind::Help,
3636
"ERROR" | "error" => ErrorKind::Error,
3737
"NOTE" | "note" => ErrorKind::Note,
3838
"SUGGESTION" => ErrorKind::Suggestion,
3939
"WARN" | "WARNING" | "warn" | "warning" => ErrorKind::Warning,
40-
_ => return None,
41-
})
42-
}
43-
44-
pub fn expect_from_user_str(s: &str) -> ErrorKind {
45-
ErrorKind::from_user_str(s).unwrap_or_else(|| {
46-
panic!(
40+
_ => panic!(
4741
"unexpected diagnostic kind `{s}`, expected \
4842
`ERROR`, `WARN`, `NOTE`, `HELP` or `SUGGESTION`"
49-
)
50-
})
43+
),
44+
}
5145
}
5246
}
5347

@@ -67,8 +61,7 @@ impl fmt::Display for ErrorKind {
6761
pub struct Error {
6862
pub line_num: Option<usize>,
6963
/// What kind of message we expect (e.g., warning, error, suggestion).
70-
/// `None` if not specified or unknown message kind.
71-
pub kind: Option<ErrorKind>,
64+
pub kind: ErrorKind,
7265
pub msg: String,
7366
/// For some `Error`s, like secondary lines of multi-line diagnostics, line annotations
7467
/// are not mandatory, even if they would otherwise be mandatory for primary errors.
@@ -79,12 +72,7 @@ pub struct Error {
7972
impl Error {
8073
pub fn render_for_expected(&self) -> String {
8174
use colored::Colorize;
82-
format!(
83-
"{: <10}line {: >3}: {}",
84-
self.kind.map(|kind| kind.to_string()).unwrap_or_default(),
85-
self.line_num_str(),
86-
self.msg.cyan(),
87-
)
75+
format!("{: <10}line {: >3}: {}", self.kind, self.line_num_str(), self.msg.cyan())
8876
}
8977

9078
pub fn line_num_str(&self) -> String {
@@ -175,7 +163,7 @@ fn parse_expected(
175163
let rest = line[tag.end()..].trim_start();
176164
let (kind_str, _) = rest.split_once(|c: char| !c.is_ascii_alphabetic()).unwrap_or((rest, ""));
177165
let kind = ErrorKind::from_user_str(kind_str);
178-
let untrimmed_msg = if kind.is_some() { &rest[kind_str.len()..] } else { rest };
166+
let untrimmed_msg = &rest[kind_str.len()..];
179167
let msg = untrimmed_msg.strip_prefix(':').unwrap_or(untrimmed_msg).trim().to_owned();
180168

181169
let line_num_adjust = &captures["adjust"];

‎src/tools/compiletest/src/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl TestProps {
594594
config.parse_name_value_directive(ln, DONT_REQUIRE_ANNOTATIONS)
595595
{
596596
self.require_annotations
597-
.insert(ErrorKind::expect_from_user_str(&err_kind), false);
597+
.insert(ErrorKind::from_user_str(err_kind.trim()), false);
598598
}
599599
},
600600
);

0 commit comments

Comments
 (0)