Add line numbers and columns to error messages spanning multiple files#47780
Add line numbers and columns to error messages spanning multiple files#47780bors merged 3 commits intorust-lang:masterfrom
Conversation
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).
|
(rust_highfive has picked a reviewer for you, use r? to override) |
| 18 | _ | ||
| | ^ | ||
| | | ||
| ::: $DIR/main.rs:15:5 |
| | -------- in this macro invocation (#1) | ||
| | | ||
| ::: <deep macros> | ||
| ::: <deep macros>:1:1 |
There was a problem hiding this comment.
this doesn't really feel like a win here... but I guess it's ok? Is an actual file line reflected here?
There was a problem hiding this comment.
We could check if annotated_file.file.name is FileName::Real(path_buf) to present the line and col, but honestly in reality I don't think it is going to be that much of a problem, and actually beneficial in real, verbose, macros.
There was a problem hiding this comment.
Yeah, I was ambivalent about this case: since it didn't seem to be decreasing readability, I decided not to special case it here. The line number is relative to the start of the macro, rather than the file in this case. It's also behind a -Z flag, so I thought it would affect people minimally regardless.
src/librustc_errors/emitter.rs
Outdated
| 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() }; |
There was a problem hiding this comment.
Can you leave the empty string on it's own line? It is easier to skip the code if the blocks are consistent.
| | -------- in this macro invocation (#1) | ||
| | | ||
| ::: <deep macros> | ||
| ::: <deep macros>:1:1 |
There was a problem hiding this comment.
We could check if annotated_file.file.name is FileName::Real(path_buf) to present the line and col, but honestly in reality I don't think it is going to be that much of a problem, and actually beneficial in real, verbose, macros.
|
@bors r+ rollup |
|
📌 Commit a21b7b3 has been approved by |
…r=estebank 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).
…r=estebank 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).
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).