Skip to content

Commit 214dd16

Browse files
committed
fix: Don't add an end column separator after a file with no source
1 parent 07b7dc9 commit 214dd16

15 files changed

+13
-23
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ impl HumanEmitter {
14621462
max_line_num_len: usize,
14631463
is_secondary: bool,
14641464
is_cont: bool,
1465-
) -> io::Result<()> {
1465+
) -> io::Result<Option<bool>> {
14661466
let mut buffer = StyledBuffer::new();
14671467

14681468
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
@@ -1580,7 +1580,8 @@ impl HumanEmitter {
15801580
let primary_span = msp.primary_span().unwrap_or_default();
15811581
let (Some(sm), false) = (self.sm.as_ref(), primary_span.is_dummy()) else {
15821582
// If we don't have span information, emit and exit
1583-
return emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message);
1583+
return emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)
1584+
.map(|_| None);
15841585
};
15851586
let primary_lo = sm.lookup_char_pos(primary_span.lo());
15861587
if let Ok(pos) =
@@ -1589,6 +1590,7 @@ impl HumanEmitter {
15891590
annotated_files.swap(0, pos);
15901591
}
15911592

1593+
let mut already_closed = None;
15921594
let annotated_files_len = annotated_files.len();
15931595
// Print out the annotate source lines that correspond with the error
15941596
for (file_idx, annotated_file) in annotated_files.into_iter().enumerate() {
@@ -1639,6 +1641,12 @@ impl HumanEmitter {
16391641
}
16401642
line_idx += 1;
16411643
}
1644+
if is_cont
1645+
&& file_idx == annotated_files_len - 1
1646+
&& annotation_id == annotated_file.lines.len() - 1
1647+
{
1648+
already_closed = Some(!labels.is_empty());
1649+
}
16421650
for (label, is_primary) in labels.into_iter() {
16431651
let style = if is_primary {
16441652
Style::LabelPrimary
@@ -1976,7 +1984,7 @@ impl HumanEmitter {
19761984
// final step: take our styled buffer, render it, then output it
19771985
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
19781986

1979-
Ok(())
1987+
Ok(already_closed)
19801988
}
19811989

19821990
fn column_width(&self, code_offset: usize) -> usize {
@@ -2491,7 +2499,7 @@ impl HumanEmitter {
24912499
!children.is_empty()
24922500
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden),
24932501
) {
2494-
Ok(()) => {
2502+
Ok(already_closed) => {
24952503
if !children.is_empty()
24962504
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden)
24972505
{
@@ -2502,7 +2510,7 @@ impl HumanEmitter {
25022510
{
25032511
// We'll continue the vertical bar to point into the next note.
25042512
self.draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
2505-
} else {
2513+
} else if !already_closed.is_some_and(|ac| ac) {
25062514
// We'll close the vertical bar to visually end the code window.
25072515
self.draw_col_separator_end(&mut buffer, 0, max_line_num_len + 1);
25082516
}

tests/ui/c-variadic/issue-86053-1.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize
6060
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
6161
|
6262
= note: similarly named trait `Fn` defined here
63-
|
6463
help: a trait with a similar name exists
6564
|
6665
LL | self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) {

tests/ui/closures/issue-78720.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ LL | _func: F,
1212
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
1313
|
1414
= note: similarly named trait `Fn` defined here
15-
|
1615
help: a trait with a similar name exists
1716
|
1817
LL | _func: Fn,

tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | let f: F = async { 1 };
66
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
77
|
88
= note: similarly named trait `Fn` defined here
9-
|
109
help: a trait with a similar name exists
1110
|
1211
LL | let f: Fn = async { 1 };

tests/ui/imports/suggest-remove-issue-121315.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | use std::convert::TryFrom;
66
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
77
|
88
= note: the item `TryFrom` is already defined here
9-
|
109
note: the lint level is defined here
1110
--> $DIR/suggest-remove-issue-121315.rs:2:25
1211
|

tests/ui/issues/issue-17546.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | fn new() -> NoResult<MyEnum, String> {
66
--> $SRC_DIR/core/src/result.rs:LL:COL
77
|
88
= note: similarly named enum `Result` defined here
9-
|
109
help: try using the variant's enum
1110
|
1211
LL - fn new() -> NoResult<MyEnum, String> {
@@ -60,7 +59,6 @@ LL | fn newer() -> NoResult<foo::MyEnum, String> {
6059
--> $SRC_DIR/core/src/result.rs:LL:COL
6160
|
6261
= note: similarly named enum `Result` defined here
63-
|
6462
help: try using the variant's enum
6563
|
6664
LL - fn newer() -> NoResult<foo::MyEnum, String> {

tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | use std::string::String;
66
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
77
|
88
= note: the item `String` is already defined here
9-
|
109
note: the lint level is defined here
1110
--> $DIR/use-redundant-issue-71450.rs:3:9
1211
|

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | use std::option::Option::Some;
66
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
77
|
88
= note: the item `Some` is already defined here
9-
|
109
note: the lint level is defined here
1110
--> $DIR/use-redundant-prelude-rust-2015.rs:3:9
1211
|

tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | use std::convert::TryFrom;
66
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
77
|
88
= note: the item `TryFrom` is already defined here
9-
|
109
note: the lint level is defined here
1110
--> $DIR/use-redundant-prelude-rust-2021.rs:3:9
1211
|

tests/ui/macros/missing-writer-issue-139830.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | let _ = write!(buf, "foo");
66
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
77
|
88
= note: the method is available for `String` here
9-
|
109
note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method
1110
--> $DIR/missing-writer-issue-139830.rs:7:20
1211
|

0 commit comments

Comments
 (0)