Skip to content

Commit 106d5fd

Browse files
authored
Rollup merge of #97504 - JohnTitor:cleanup-deps, r=davidtwco
Ensure source file present when calculating max line number Resubmission of #89268, fixes #71363 The behavior difference of `simulate-remapped-rust-src-base` is not something we should take into account here, so limiting targets to run the test makes sense, I think. r? `@davidtwco,` and `@estebank,` you might be interested in this change
2 parents 8fd9e24 + 5a4e936 commit 106d5fd

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

compiler/rustc_errors/src/emitter.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1261,16 +1261,23 @@ impl EmitterWriter {
12611261
return 0;
12621262
};
12631263

1264+
let will_be_emitted = |span: Span| {
1265+
!span.is_dummy() && {
1266+
let file = sm.lookup_source_file(span.hi());
1267+
sm.ensure_source_file_source_present(file)
1268+
}
1269+
};
1270+
12641271
let mut max = 0;
12651272
for primary_span in msp.primary_spans() {
1266-
if !primary_span.is_dummy() {
1273+
if will_be_emitted(*primary_span) {
12671274
let hi = sm.lookup_char_pos(primary_span.hi());
12681275
max = (hi.line).max(max);
12691276
}
12701277
}
12711278
if !self.short_message {
12721279
for span_label in msp.span_labels() {
1273-
if !span_label.span.is_dummy() {
1280+
if will_be_emitted(span_label.span) {
12741281
let hi = sm.lookup_char_pos(span_label.span.hi());
12751282
max = (hi.line).max(max);
12761283
}

src/test/ui/span/issue-71363.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -Z simulate-remapped-rust-src-base=/rustc/xyz -Z ui-testing=no
2+
// only-x86_64-unknown-linux-gnu
3+
//---^ Limiting target as the above unstable flags don't play well on some environment.
4+
5+
struct MyError;
6+
impl std::error::Error for MyError {}
7+
//~^ ERROR: `MyError` doesn't implement `std::fmt::Display`
8+
//~| ERROR: `MyError` doesn't implement `Debug`
9+
10+
fn main() {}

src/test/ui/span/issue-71363.stderr

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0277]: `MyError` doesn't implement `std::fmt::Display`
2+
--> $DIR/issue-71363.rs:6:6
3+
|
4+
6 | impl std::error::Error for MyError {}
5+
| ^^^^^^^^^^^^^^^^^ `MyError` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `MyError`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `std::error::Error`
10+
11+
error[E0277]: `MyError` doesn't implement `Debug`
12+
--> $DIR/issue-71363.rs:6:6
13+
|
14+
6 | impl std::error::Error for MyError {}
15+
| ^^^^^^^^^^^^^^^^^ `MyError` cannot be formatted using `{:?}`
16+
|
17+
= help: the trait `Debug` is not implemented for `MyError`
18+
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
19+
note: required by a bound in `std::error::Error`
20+
help: consider annotating `MyError` with `#[derive(Debug)]`
21+
|
22+
5 | #[derive(Debug)]
23+
|
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)