Skip to content

Commit 10b75cb

Browse files
committed
Start emitting labels even if their pointed to file is not available locally
1 parent 19d7dce commit 10b75cb

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ impl EmitterWriter {
773773
draw_col_separator_no_space(buffer, line_offset, width_offset - 2);
774774
}
775775

776+
#[instrument(level = "trace", skip(self), ret)]
776777
fn render_source_line(
777778
&self,
778779
buffer: &mut StyledBuffer,
@@ -804,6 +805,7 @@ impl EmitterWriter {
804805
Some(s) => normalize_whitespace(&s),
805806
None => return Vec::new(),
806807
};
808+
trace!(?source_string);
807809

808810
let line_offset = buffer.num_lines();
809811

@@ -1323,6 +1325,7 @@ impl EmitterWriter {
13231325
}
13241326
}
13251327

1328+
#[instrument(level = "trace", skip(self, args), ret)]
13261329
fn emit_message_default(
13271330
&mut self,
13281331
msp: &MultiSpan,
@@ -1384,6 +1387,7 @@ impl EmitterWriter {
13841387
}
13851388
}
13861389
let mut annotated_files = FileWithAnnotatedLines::collect_annotations(self, args, msp);
1390+
trace!("{annotated_files:#?}");
13871391

13881392
// Make sure our primary file comes first
13891393
let primary_span = msp.primary_span().unwrap_or_default();
@@ -1402,6 +1406,42 @@ impl EmitterWriter {
14021406
for annotated_file in annotated_files {
14031407
// we can't annotate anything if the source is unavailable.
14041408
if !sm.ensure_source_file_source_present(annotated_file.file.clone()) {
1409+
if !self.short_message {
1410+
// We'll just print an unannotated message.
1411+
for line in annotated_file.lines {
1412+
let mut annotations = line.annotations.clone();
1413+
annotations.sort_by_key(|a| Reverse(a.start_col));
1414+
let mut line_idx = buffer.num_lines();
1415+
buffer.append(
1416+
line_idx,
1417+
&format!(
1418+
"{}:{}:{}",
1419+
sm.filename_for_diagnostics(&annotated_file.file.name),
1420+
sm.doctest_offset_line(&annotated_file.file.name, line.line_index),
1421+
annotations[0].start_col + 1,
1422+
),
1423+
Style::LineAndColumn,
1424+
);
1425+
let prefix = if annotations.len() > 1 {
1426+
buffer.prepend(line_idx, "--> ", Style::LineNumber);
1427+
line_idx += 1;
1428+
"note: "
1429+
} else {
1430+
": "
1431+
};
1432+
for (i, annotation) in annotations.into_iter().enumerate() {
1433+
if let Some(label) = &annotation.label {
1434+
let style = if annotation.is_primary {
1435+
Style::LabelPrimary
1436+
} else {
1437+
Style::LabelSecondary
1438+
};
1439+
buffer.append(line_idx + i, prefix, style);
1440+
buffer.append(line_idx + i, label, style);
1441+
}
1442+
}
1443+
}
1444+
}
14051445
continue;
14061446
}
14071447

@@ -1648,6 +1688,7 @@ impl EmitterWriter {
16481688
multilines.extend(&to_add);
16491689
}
16501690
}
1691+
trace!("buffer: {:#?}", buffer.render());
16511692
}
16521693

16531694
if let Some(tracked) = emitted_at {
@@ -1971,6 +2012,7 @@ impl EmitterWriter {
19712012
Ok(())
19722013
}
19732014

2015+
#[instrument(level = "trace", skip(self, args, code, children, suggestions))]
19742016
fn emit_messages_default(
19752017
&mut self,
19762018
level: &Level,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// compile-flags: -Z simulate-remapped-rust-src-base=/rustc/xyz -Z translate-remapped-path-to-local-path=no
2+
3+
#![feature(const_swap)]
4+
#![feature(const_mut_refs)]
5+
use std::{
6+
mem::{self, MaybeUninit},
7+
ptr,
8+
};
9+
10+
const X: () = {
11+
let mut ptr1 = &1;
12+
let mut ptr2 = &2;
13+
14+
// Swap them, bytewise.
15+
unsafe {
16+
ptr::swap_nonoverlapping(
17+
&mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
18+
&mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
19+
mem::size_of::<&i32>(),
20+
);
21+
}
22+
};
23+
24+
fn main() {
25+
X
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0080]: evaluation of constant value failed
2+
/rustc/xyz/library/core/src/ptr/mod.rs:929:14: inside `swap_nonoverlapping::<MaybeUninit<u8>>` at /rustc/xyz/library/core/src/ptr/mod.rs:929:14
3+
/rustc/xyz/library/core/src/ptr/mod.rs:948:9: inside `ptr::swap_nonoverlapping_simple_untyped::<MaybeUninit<u8>>` at /rustc/xyz/library/core/src/ptr/mod.rs:948:9
4+
--> /rustc/xyz/library/core/src/ptr/mod.rs:1139:9
5+
note: unable to copy parts of a pointer from memory at alloc6+0x1
6+
note: inside `std::ptr::read::<MaybeUninit<MaybeUninit<u8>>>` at /rustc/xyz/library/core/src/ptr/mod.rs:1139:9
7+
/rustc/xyz/library/core/src/mem/mod.rs:776:17: inside `mem::swap_simple::<MaybeUninit<MaybeUninit<u8>>>` at /rustc/xyz/library/core/src/mem/mod.rs:776:17
8+
|
9+
::: $DIR/missing_span_in_backtrace.rs:16:9
10+
|
11+
LL | / ptr::swap_nonoverlapping(
12+
LL | | &mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
13+
LL | | &mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
14+
LL | | mem::size_of::<&i32>(),
15+
LL | | );
16+
| |_________- inside `X` at $DIR/missing_span_in_backtrace.rs:16:9
17+
|
18+
= help: this code performed an operation that depends on the underlying bytes representing a pointer
19+
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
20+
21+
error: aborting due to previous error
22+
23+
For more information about this error, try `rustc --explain E0080`.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ error[E0277]: `MyError` doesn't implement `std::fmt::Display`
77
= help: the trait `std::fmt::Display` is not implemented for `MyError`
88
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
99
note: required by a bound in `std::error::Error`
10+
/rustc/xyz/library/core/src/error.rs:31:26: required by this bound in `std::error::Error`
1011

1112
error[E0277]: `MyError` doesn't implement `Debug`
1213
--> $DIR/issue-71363.rs:4:6
@@ -17,6 +18,7 @@ error[E0277]: `MyError` doesn't implement `Debug`
1718
= help: the trait `Debug` is not implemented for `MyError`
1819
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
1920
note: required by a bound in `std::error::Error`
21+
/rustc/xyz/library/core/src/error.rs:31:18: required by this bound in `std::error::Error`
2022
help: consider annotating `MyError` with `#[derive(Debug)]`
2123
|
2224
3 | #[derive(Debug)]

0 commit comments

Comments
 (0)