Skip to content

Commit 776730e

Browse files
committed
WIP
1 parent 6acd815 commit 776730e

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

src/tools/compiletest/src/errors.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl fmt::Display for ErrorKind {
7272
#[derive(Debug)]
7373
pub struct Error {
7474
pub line_num: Option<usize>,
75+
pub column_num: Option<usize>,
7576
/// What kind of message we expect (e.g., warning, error, suggestion).
7677
pub kind: ErrorKind,
7778
pub msg: String,
@@ -81,12 +82,6 @@ pub struct Error {
8182
pub require_annotation: bool,
8283
}
8384

84-
impl Error {
85-
pub fn line_num_str(&self) -> String {
86-
self.line_num.map_or("?".to_string(), |line_num| line_num.to_string())
87-
}
88-
}
89-
9085
/// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE"
9186
/// The former is a "follow" that inherits its target from the preceding line;
9287
/// the latter is an "adjusts" that goes that many lines up.
@@ -186,6 +181,7 @@ fn parse_expected(
186181
} else {
187182
(false, Some(line_num - line_num_adjust.len()))
188183
};
184+
let column_num = Some(tag.start() + 1);
189185

190186
debug!(
191187
"line={:?} tag={:?} follow_prev={:?} kind={:?} msg={:?}",
@@ -195,7 +191,7 @@ fn parse_expected(
195191
kind,
196192
msg
197193
);
198-
Some((follow_prev, Error { line_num, kind, msg, require_annotation: true }))
194+
Some((follow_prev, Error { line_num, column_num, kind, msg, require_annotation: true }))
199195
}
200196

201197
#[cfg(test)]

src/tools/compiletest/src/json.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ struct UnusedExternNotification {
3636
struct DiagnosticSpan {
3737
file_name: String,
3838
line_start: usize,
39-
line_end: usize,
4039
column_start: usize,
41-
column_end: usize,
4240
is_primary: bool,
4341
label: Option<String>,
4442
suggested_replacement: Option<String>,
@@ -148,6 +146,7 @@ pub fn parse_output(file_name: &str, output: &str) -> Vec<Error> {
148146
Ok(diagnostic) => push_actual_errors(&mut errors, &diagnostic, &[], file_name),
149147
Err(_) => errors.push(Error {
150148
line_num: None,
149+
column_num: None,
151150
kind: ErrorKind::Raw,
152151
msg: line.to_string(),
153152
require_annotation: false,
@@ -193,25 +192,9 @@ fn push_actual_errors(
193192
// also ensure that `//~ ERROR E123` *always* works. The
194193
// assumption is that these multi-line error messages are on their
195194
// way out anyhow.
196-
let with_code = |span: Option<&DiagnosticSpan>, text: &str| {
197-
// FIXME(#33000) -- it'd be better to use a dedicated
198-
// UI harness than to include the line/col number like
199-
// this, but some current tests rely on it.
200-
//
201-
// Note: Do NOT include the filename. These can easily
202-
// cause false matches where the expected message
203-
// appears in the filename, and hence the message
204-
// changes but the test still passes.
205-
let span_str = match span {
206-
Some(DiagnosticSpan { line_start, column_start, line_end, column_end, .. }) => {
207-
format!("{line_start}:{column_start}: {line_end}:{column_end}")
208-
}
209-
None => format!("?:?: ?:?"),
210-
};
211-
match &diagnostic.code {
212-
Some(code) => format!("{span_str}: {text} [{}]", code.code),
213-
None => format!("{span_str}: {text}"),
214-
}
195+
let with_code = |text| match &diagnostic.code {
196+
Some(code) => format!("{text} [{}]", code.code),
197+
None => format!("{text}"),
215198
};
216199

217200
// Convert multi-line messages into multiple errors.
@@ -225,17 +208,19 @@ fn push_actual_errors(
225208
|| Regex::new(r"aborting due to \d+ previous errors?|\d+ warnings? emitted").unwrap();
226209
errors.push(Error {
227210
line_num: None,
211+
column_num: None,
228212
kind,
229-
msg: with_code(None, first_line),
213+
msg: with_code(first_line),
230214
require_annotation: diagnostic.level != "failure-note"
231215
&& !RE.get_or_init(re_init).is_match(first_line),
232216
});
233217
} else {
234218
for span in primary_spans {
235219
errors.push(Error {
236220
line_num: Some(span.line_start),
221+
column_num: Some(span.column_start),
237222
kind,
238-
msg: with_code(Some(span), first_line),
223+
msg: with_code(first_line),
239224
require_annotation: true,
240225
});
241226
}
@@ -244,16 +229,18 @@ fn push_actual_errors(
244229
if primary_spans.is_empty() {
245230
errors.push(Error {
246231
line_num: None,
232+
column_num: None,
247233
kind,
248-
msg: with_code(None, next_line),
234+
msg: with_code(next_line),
249235
require_annotation: false,
250236
});
251237
} else {
252238
for span in primary_spans {
253239
errors.push(Error {
254240
line_num: Some(span.line_start),
241+
column_num: Some(span.column_start),
255242
kind,
256-
msg: with_code(Some(span), next_line),
243+
msg: with_code(next_line),
257244
require_annotation: false,
258245
});
259246
}
@@ -266,6 +253,7 @@ fn push_actual_errors(
266253
for (index, line) in suggested_replacement.lines().enumerate() {
267254
errors.push(Error {
268255
line_num: Some(span.line_start + index),
256+
column_num: Some(span.column_start),
269257
kind: ErrorKind::Suggestion,
270258
msg: line.to_string(),
271259
// Empty suggestions (suggestions to remove something) are common
@@ -288,6 +276,7 @@ fn push_actual_errors(
288276
if let Some(label) = &span.label {
289277
errors.push(Error {
290278
line_num: Some(span.line_start),
279+
column_num: Some(span.column_start),
291280
kind: ErrorKind::Note,
292281
msg: label.clone(),
293282
// Empty labels (only underlining spans) are common and do not need annotations.
@@ -310,6 +299,7 @@ fn push_backtrace(
310299
if Path::new(&expansion.span.file_name) == Path::new(&file_name) {
311300
errors.push(Error {
312301
line_num: Some(expansion.span.line_start),
302+
column_num: Some(expansion.span.column_start),
313303
kind: ErrorKind::Note,
314304
msg: format!("in this expansion of {}", expansion.macro_decl_name),
315305
require_annotation: true,

src/tools/compiletest/src/runtest.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,13 @@ impl<'test> TestCx<'test> {
762762
not_found.len()
763763
));
764764
let print = |e: &Error| {
765-
println!("{file_name}:{}: {}: {}", e.line_num_str(), e.kind, e.msg.cyan())
765+
let line_num = e.line_num.map_or("?".to_string(), |line_num| line_num.to_string());
766+
// `file:?:NUM` may be confusing to editors and unclickable.
767+
let opt_col_num = match e.column_num {
768+
Some(col_num) if line_num != "?" => format!("{col_num}:"),
769+
_ => "".to_string(),
770+
};
771+
println!("{file_name}:{line_num}:{opt_col_num} {}: {}", e.kind, e.msg.cyan())
766772
};
767773
// Fuzzy matching quality:
768774
// - message and line / message and kind - great, suggested

tests/ui/compiletest-self-test/line-annotation-mismatches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ should-fail
1+
// should-fail
22

33
// The warning is reported with unknown line
44
//@ compile-flags: -D raw_pointer_derive

0 commit comments

Comments
 (0)