mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-25 06:03:16 +00:00
Add line numbers and columns to error messages spanning multiple files
If an error message is emitted that spans several files, only the primary file currently has line and column data attached. This is useful information, even in files other than the one in which the error occurs. We can often work out which line and column the error corresponds to in other files — in this case it is helpful to add them (in the case of ambiguity, the first relevant line/column is picked, which is still helpful than none).
This commit is contained in:
parent
a0dcecff90
commit
0ac465924e
@ -1013,8 +1013,19 @@ impl EmitterWriter {
|
||||
|
||||
// Then, the secondary file indicator
|
||||
buffer.prepend(buffer_msg_line_offset + 1, "::: ", Style::LineNumber);
|
||||
let loc = if let Some(first_line) = annotated_file.lines.first() {
|
||||
let col = if let Some(first_annotation) = first_line.annotations.first() {
|
||||
format!(":{}", first_annotation.start_col + 1)
|
||||
} else { "".to_string() };
|
||||
format!("{}:{}{}",
|
||||
annotated_file.file.name,
|
||||
cm.doctest_offset_line(first_line.line_index),
|
||||
col)
|
||||
} else {
|
||||
annotated_file.file.name.to_string()
|
||||
};
|
||||
buffer.append(buffer_msg_line_offset + 1,
|
||||
&annotated_file.file.name.to_string(),
|
||||
&loc,
|
||||
Style::LineAndColumn);
|
||||
for _ in 0..max_line_num_len {
|
||||
buffer.prepend(buffer_msg_line_offset + 1, " ", Style::NoStyle);
|
||||
|
@ -27,7 +27,8 @@ pub struct FileInfo {
|
||||
|
||||
/// The "primary file", if any, gets a `-->` marker instead of
|
||||
/// `>>>`, and has a line-number/column printed and not just a
|
||||
/// filename. It appears first in the listing. It is known to
|
||||
/// filename (other files are not guaranteed to have line numbers
|
||||
/// or columns). It appears first in the listing. It is known to
|
||||
/// contain at least one primary span, though primary spans (which
|
||||
/// are designated with `^^^`) may also occur in other files.
|
||||
primary_span: Option<Span>,
|
||||
|
16
src/test/ui/cross-file-errors/main.rs
Normal file
16
src/test/ui/cross-file-errors/main.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[macro_use]
|
||||
mod underscore;
|
||||
|
||||
fn main() {
|
||||
underscore!();
|
||||
}
|
11
src/test/ui/cross-file-errors/main.stderr
Normal file
11
src/test/ui/cross-file-errors/main.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error: expected expression, found `_`
|
||||
--> $DIR/underscore.rs:18:9
|
||||
|
|
||||
18 | _
|
||||
| ^
|
||||
|
|
||||
::: $DIR/main.rs:15:5
|
||||
|
|
||||
15 | underscore!();
|
||||
| -------------- in this macro invocation
|
||||
|
20
src/test/ui/cross-file-errors/underscore.rs
Normal file
20
src/test/ui/cross-file-errors/underscore.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// We want this file only so we can test cross-file error
|
||||
// messages, but we don't want it in an external crate.
|
||||
// ignore-test
|
||||
#![crate_type = "lib"]
|
||||
|
||||
macro_rules! underscore {
|
||||
() => (
|
||||
_
|
||||
)
|
||||
}
|
@ -1402,7 +1402,7 @@ impl<'test> TestCx<'test> {
|
||||
}
|
||||
|
||||
/// For each `aux-build: foo/bar` annotation, we check to find the
|
||||
/// file in a `aux` directory relative to the test itself.
|
||||
/// file in a `auxiliary` directory relative to the test itself.
|
||||
fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths {
|
||||
let test_ab = self.testpaths
|
||||
.file
|
||||
|
Loading…
Reference in New Issue
Block a user