Skip to content

Commit 8ffb3d9

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

15 files changed

+20
-23
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 20 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<CodeWindowStatus> {
14661466
let mut buffer = StyledBuffer::new();
14671467

14681468
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
@@ -1575,12 +1575,14 @@ impl HumanEmitter {
15751575
}
15761576
let mut annotated_files = FileWithAnnotatedLines::collect_annotations(self, args, msp);
15771577
trace!("{annotated_files:#?}");
1578+
let mut code_window_status = CodeWindowStatus::Open;
15781579

15791580
// Make sure our primary file comes first
15801581
let primary_span = msp.primary_span().unwrap_or_default();
15811582
let (Some(sm), false) = (self.sm.as_ref(), primary_span.is_dummy()) else {
15821583
// If we don't have span information, emit and exit
1583-
return emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message);
1584+
return emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)
1585+
.map(|_| code_window_status);
15841586
};
15851587
let primary_lo = sm.lookup_char_pos(primary_span.lo());
15861588
if let Ok(pos) =
@@ -1639,6 +1641,13 @@ 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+
&& !labels.is_empty()
1648+
{
1649+
code_window_status = CodeWindowStatus::Closed;
1650+
}
16421651
for (label, is_primary) in labels.into_iter() {
16431652
let style = if is_primary {
16441653
Style::LabelPrimary
@@ -1976,7 +1985,7 @@ impl HumanEmitter {
19761985
// final step: take our styled buffer, render it, then output it
19771986
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
19781987

1979-
Ok(())
1988+
Ok(code_window_status)
19801989
}
19811990

19821991
fn column_width(&self, code_offset: usize) -> usize {
@@ -2491,7 +2500,7 @@ impl HumanEmitter {
24912500
!children.is_empty()
24922501
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden),
24932502
) {
2494-
Ok(()) => {
2503+
Ok(code_window_status) => {
24952504
if !children.is_empty()
24962505
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden)
24972506
{
@@ -2502,7 +2511,7 @@ impl HumanEmitter {
25022511
{
25032512
// We'll continue the vertical bar to point into the next note.
25042513
self.draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
2505-
} else {
2514+
} else if matches!(code_window_status, CodeWindowStatus::Open) {
25062515
// We'll close the vertical bar to visually end the code window.
25072516
self.draw_col_separator_end(&mut buffer, 0, max_line_num_len + 1);
25082517
}
@@ -3050,6 +3059,12 @@ enum DisplaySuggestion {
30503059
Add,
30513060
}
30523061

3062+
#[derive(Clone, Copy, Debug)]
3063+
enum CodeWindowStatus {
3064+
Closed,
3065+
Open,
3066+
}
3067+
30533068
impl FileWithAnnotatedLines {
30543069
/// Preprocess all the annotations so that they are grouped by file and by line number
30553070
/// This helps us quickly iterate over the whole message (including secondary file spans)

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)