Skip to content

No source fixes #144864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 65 additions & 24 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ impl HumanEmitter {
max_line_num_len: usize,
is_secondary: bool,
is_cont: bool,
) -> io::Result<()> {
) -> io::Result<CodeWindowStatus> {
let mut buffer = StyledBuffer::new();

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

// Make sure our primary file comes first
let primary_span = msp.primary_span().unwrap_or_default();
let (Some(sm), false) = (self.sm.as_ref(), primary_span.is_dummy()) else {
// If we don't have span information, emit and exit
return emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message);
return emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)
.map(|_| code_window_status);
};
let primary_lo = sm.lookup_char_pos(primary_span.lo());
if let Ok(pos) =
Expand All @@ -1589,6 +1591,9 @@ impl HumanEmitter {
annotated_files.swap(0, pos);
}

// An end column separator should be emitted when a file with with a
// source, is followed by one without a source
let mut col_sep_before_no_show_source = false;
let annotated_files_len = annotated_files.len();
// Print out the annotate source lines that correspond with the error
for (file_idx, annotated_file) in annotated_files.into_iter().enumerate() {
Expand All @@ -1599,6 +1604,26 @@ impl HumanEmitter {
&annotated_file.file,
) {
if !self.short_message {
// Add an end column separator when a file without a source
// comes after one with a source
// ╭▸ $DIR/deriving-meta-unknown-trait.rs:1:10
// │
// LL │ #[derive(Eqr)]
// │ ━━━
// ╰╴ (<- It prints *this* line)
// ╭▸ $SRC_DIR/core/src/cmp.rs:356:0
// │
// ╰╴note: similarly named derive macro `Eq` defined here
if col_sep_before_no_show_source {
let buffer_msg_line_offset = buffer.num_lines();
self.draw_col_separator_end(
&mut buffer,
buffer_msg_line_offset,
max_line_num_len + 1,
);
}
col_sep_before_no_show_source = false;

// We'll just print an unannotated message.
for (annotation_id, line) in annotated_file.lines.iter().enumerate() {
let mut annotations = line.annotations.clone();
Expand Down Expand Up @@ -1639,29 +1664,42 @@ impl HumanEmitter {
}
line_idx += 1;
}
for (label, is_primary) in labels.into_iter() {
if is_cont
&& file_idx == annotated_files_len - 1
&& annotation_id == annotated_file.lines.len() - 1
&& !labels.is_empty()
{
code_window_status = CodeWindowStatus::Closed;
}
let labels_len = labels.len();
for (label_idx, (label, is_primary)) in labels.into_iter().enumerate() {
let style = if is_primary {
Style::LabelPrimary
} else {
Style::LabelSecondary
};
let pipe = self.col_separator();
buffer.prepend(line_idx, &format!(" {pipe}"), Style::LineNumber);
for _ in 0..max_line_num_len {
buffer.prepend(line_idx, " ", Style::NoStyle);
}
self.draw_col_separator_no_space(
&mut buffer,
line_idx,
max_line_num_len + 1,
);
line_idx += 1;
let chr = self.note_separator();
buffer.append(line_idx, &format!(" {chr} note: "), style);
for _ in 0..max_line_num_len {
buffer.prepend(line_idx, " ", Style::NoStyle);
}
self.draw_note_separator(
&mut buffer,
line_idx,
max_line_num_len + 1,
label_idx != labels_len - 1,
);
buffer.append(line_idx, "note", Style::MainHeaderMsg);
buffer.append(line_idx, ": ", Style::NoStyle);
buffer.append(line_idx, label, style);
line_idx += 1;
}
}
}
continue;
} else {
col_sep_before_no_show_source = true;
}

// print out the span ___location and spacer before we print the annotated source
Expand Down Expand Up @@ -1976,7 +2014,7 @@ impl HumanEmitter {
// final step: take our styled buffer, render it, then output it
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;

Ok(())
Ok(code_window_status)
}

fn column_width(&self, code_offset: usize) -> usize {
Expand Down Expand Up @@ -2491,7 +2529,7 @@ impl HumanEmitter {
!children.is_empty()
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden),
) {
Ok(()) => {
Ok(code_window_status) => {
if !children.is_empty()
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden)
{
Expand All @@ -2502,7 +2540,7 @@ impl HumanEmitter {
{
// We'll continue the vertical bar to point into the next note.
self.draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
} else {
} else if matches!(code_window_status, CodeWindowStatus::Open) {
// We'll close the vertical bar to visually end the code window.
self.draw_col_separator_end(&mut buffer, 0, max_line_num_len + 1);
}
Expand Down Expand Up @@ -2829,10 +2867,11 @@ impl HumanEmitter {
}
}

fn note_separator(&self) -> char {
fn note_separator(&self, is_cont: bool) -> &'static str {
match self.theme {
OutputTheme::Ascii => '=',
OutputTheme::Unicode => '╰',
OutputTheme::Ascii => "= ",
OutputTheme::Unicode if is_cont => "├ ",
OutputTheme::Unicode => "╰ ",
}
}

Expand Down Expand Up @@ -2945,11 +2984,7 @@ impl HumanEmitter {
col: usize,
is_cont: bool,
) {
let chr = match self.theme {
OutputTheme::Ascii => "= ",
OutputTheme::Unicode if is_cont => "├ ",
OutputTheme::Unicode => "╰ ",
};
let chr = self.note_separator(is_cont);
buffer.puts(line, col, chr, Style::LineNumber);
}

Expand Down Expand Up @@ -3050,6 +3085,12 @@ enum DisplaySuggestion {
Add,
}

#[derive(Clone, Copy, Debug)]
enum CodeWindowStatus {
Closed,
Open,
}

impl FileWithAnnotatedLines {
/// Preprocess all the annotations so that they are grouped by file and by line number
/// This helps us quickly iterate over the whole message (including secondary file spans)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ error[E0599]: no method named `poll` found for struct `Pin<&mut impl Future<Outp
|
LL | match fut.as_mut().poll(ctx) {
| ^^^^ method not found in `Pin<&mut impl Future<Output = ()>>`
|
--> $SRC_DIR/core/src/future/future.rs:LL:COL
|
= note: the method is available for `Pin<&mut impl Future<Output = ()>>` here
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/c-variadic/issue-86053-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ error[E0412]: cannot find type `F` in this scope
|
LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
| ^
|
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
|
help: a trait with a similar name exists
|
LL | self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/issue-78720.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ error[E0412]: cannot find type `F` in this scope
|
LL | _func: F,
| ^
|
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
|
help: a trait with a similar name exists
|
LL | _func: Fn,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/closures/issue-90871.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ error[E0412]: cannot find type `n` in this scope
|
LL | type_ascribe!(2, n([u8; || 1]))
| ^ help: a trait with a similar name exists: `Fn`
|
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ error[E0412]: cannot find type `F` in this scope
|
LL | let f: F = async { 1 };
| ^
|
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
|
help: a trait with a similar name exists
|
LL | let f: Fn = async { 1 };
Expand Down
1 change: 1 addition & 0 deletions tests/ui/consts/issue-89088.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | const FOO: &A = &A::Field(Cow::Borrowed("foo"));
...
LL | FOO => todo!(),
| ^^^ constant of non-structural type
|
--> $SRC_DIR/alloc/src/borrow.rs:LL:COL
|
= note: `Cow<'_, str>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/derives/deriving-meta-unknown-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ error: cannot find derive macro `Eqr` in this scope
|
LL | #[derive(Eqr)]
| ^^^ help: a derive macro with a similar name exists: `Eq`
|
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
= note: similarly named derive macro `Eq` defined here
Expand All @@ -12,6 +13,7 @@ error: cannot find derive macro `Eqr` in this scope
|
LL | #[derive(Eqr)]
| ^^^ help: a derive macro with a similar name exists: `Eq`
|
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
= note: similarly named derive macro `Eq` defined here
Expand Down
1 change: 1 addition & 0 deletions tests/ui/did_you_mean/println-typo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ error: cannot find macro `prinltn` in this scope
|
LL | prinltn!();
| ^^^^^^^ help: a macro with a similar name exists: `println`
|
--> $SRC_DIR/std/src/macros.rs:LL:COL
|
= note: similarly named macro `println` defined here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ error[E0599]: no method named `fmt` found for opaque type `impl Debug` in the cu
|
LL | x.fmt(f);
| ^^^ method not found in `impl Debug`
|
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
|
= note: the method is available for `impl Debug` here
Expand Down
1 change: 1 addition & 0 deletions tests/ui/impl-trait/impl-generic-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ error[E0643]: method `hash` has incompatible signature for trait
|
LL | fn hash(&self, hasher: &mut impl Hasher) {}
| ^^^^^^^^^^^ expected generic parameter, found `impl Trait`
|
--> $SRC_DIR/core/src/hash/mod.rs:LL:COL
|
= note: declaration in trait here
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/imports/suggest-remove-issue-121315.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ error: the item `TryFrom` is imported redundantly
|
LL | use std::convert::TryFrom;
| ^^^^^^^^^^^^^^^^^^^^^
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `TryFrom` is already defined here
|
note: the lint level is defined here
--> $DIR/suggest-remove-issue-121315.rs:2:25
|
Expand All @@ -18,6 +18,7 @@ error: the item `TryFrom` is imported redundantly
|
LL | use std::convert::{TryFrom, TryInto};
| ^^^^^^^
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `TryFrom` is already defined here
Expand All @@ -27,6 +28,7 @@ error: the item `TryInto` is imported redundantly
|
LL | use std::convert::{TryFrom, TryInto};
| ^^^^^^^
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `TryInto` is already defined here
Expand All @@ -48,6 +50,7 @@ error: the item `Into` is imported redundantly
|
LL | use std::convert::{AsMut, Into};
| ^^^^
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `Into` is already defined here
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-17546.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ error[E0573]: expected type, found variant `NoResult`
|
LL | fn new() -> NoResult<MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
--> $SRC_DIR/core/src/result.rs:LL:COL
|
= note: similarly named enum `Result` defined here
|
help: try using the variant's enum
|
LL - fn new() -> NoResult<MyEnum, String> {
Expand Down Expand Up @@ -57,10 +57,10 @@ error[E0573]: expected type, found variant `NoResult`
|
LL | fn newer() -> NoResult<foo::MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
--> $SRC_DIR/core/src/result.rs:LL:COL
|
= note: similarly named enum `Result` defined here
|
help: try using the variant's enum
|
LL - fn newer() -> NoResult<foo::MyEnum, String> {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/issues/issue-27033.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ error[E0530]: match bindings cannot shadow unit variants
|
LL | None @ _ => {}
| ^^^^ cannot be named the same as a unit variant
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the unit variant `None` is defined here
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/issues/issue-32655.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | #[derive_Clone]
...
LL | foo!();
| ------ in this macro invocation
|
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
= note: similarly named attribute macro `derive_const` defined here
Expand All @@ -17,6 +18,7 @@ error: cannot find attribute `derive_Clone` in this scope
|
LL | #[derive_Clone]
| ^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `derive_const`
|
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
= note: similarly named attribute macro `derive_const` defined here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ warning: the item `String` is imported redundantly
|
LL | use std::string::String;
| ^^^^^^^^^^^^^^^^^^^
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
= note: the item `String` is already defined here
|
note: the lint level is defined here
--> $DIR/use-redundant-issue-71450.rs:3:9
|
Expand Down
Loading
Loading