Skip to content

chore: Improve how the other suggestions message gets rendered #143661

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

Merged
merged 2 commits into from
Jul 12, 2025
Merged
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
9 changes: 7 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2446,17 +2446,22 @@ impl HumanEmitter {
| DisplaySuggestion::Underline => row_num - 1,
DisplaySuggestion::None => row_num,
};
self.draw_col_separator_end(&mut buffer, row, max_line_num_len + 1);
if other_suggestions > 0 {
self.draw_col_separator_no_space(&mut buffer, row, max_line_num_len + 1);
} else {
self.draw_col_separator_end(&mut buffer, row, max_line_num_len + 1);
}
row_num = row + 1;
}
}
if other_suggestions > 0 {
self.draw_note_separator(&mut buffer, row_num, max_line_num_len + 1, false);
let msg = format!(
"and {} other candidate{}",
other_suggestions,
pluralize!(other_suggestions)
);
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
buffer.append(row_num, &msg, Style::NoStyle);
}

emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LL + type X = <CString as Deref>::Target;
LL - type X = std::ops::Deref::Target;
LL + type X = <IoSlice<'_> as Deref>::Target;
|
and N other candidates
= and N other candidates

error[E0223]: ambiguous associated type
--> $DIR/associated-types-in-ambiguous-context.rs:13:23
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/issues/issue-82956.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LL + use std::collections::btree_map::IntoIter;
|
LL + use std::collections::btree_set::IntoIter;
|
and 9 other candidates
= and 9 other candidates

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LL + fn setup() -> Determine { Set }
LL - fn setup() -> Set { Set }
LL + fn setup() -> PutDown { Set }
|
and 3 other candidates
= and 3 other candidates

error[E0425]: cannot find value `Set` in this scope
--> $DIR/issue-56028-there-is-an-enum-variant.rs:9:21
Expand All @@ -36,7 +36,7 @@ LL + use Determine::Set;
|
LL + use PutDown::Set;
|
and 3 other candidates
= and 3 other candidates

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LL + use std::fmt::Display;
|
LL + use std::fmt::LowerExp;
|
and 5 other candidates
= and 5 other candidates

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/imports/issue-56125.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LL + use ::issue_56125::issue_56125;
LL - use empty::issue_56125;
LL + use ::issue_56125::last_segment::issue_56125;
|
and 1 other candidate
= and 1 other candidate

error[E0659]: `issue_56125` is ambiguous
--> $DIR/issue-56125.rs:6:9
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/use_suggestion_json.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ mod foo {
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
\u001b[0m\u001b[1m\u001b[38;5;12mLL\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[38;5;10m+ use std::collections::hash_map::Iter;\u001b[0m
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
\u001b[0m and 9 other candidates\u001b[0m
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0mand 9 other candidates\u001b[0m

"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/privacy/suggest-box-new.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ LL - x: (),
LL - })),
LL + wtf: Some(Box::new_in(_, _)),
|
and 12 other candidates
= and 12 other candidates
help: consider using the `Default` trait
|
LL - wtf: Some(Box(U {
Expand Down Expand Up @@ -118,7 +118,7 @@ LL + let _ = Box::new_zeroed();
LL - let _ = Box {};
LL + let _ = Box::new_in(_, _);
|
and 12 other candidates
= and 12 other candidates
help: consider using the `Default` trait
|
LL - let _ = Box {};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/rust-2018/issue-52202-use-suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LL + use std::collections::hash_map::Drain;
|
LL + use std::collections::hash_set::Drain;
|
and 3 other candidates
= and 3 other candidates

error: aborting due to 1 previous error

Expand Down
130 changes: 130 additions & 0 deletions tests/ui/suggestions/multi-suggestion.ascii.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
--> $DIR/multi-suggestion.rs:17:13
|
LL | let _ = std::collections::HashMap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
|
= note: `std::collections::HashMap` defined here
|
help: you might have meant to use an associated function to build this type
|
LL | let _ = std::collections::HashMap::new();
| +++++
LL - let _ = std::collections::HashMap();
LL + let _ = std::collections::HashMap::with_capacity(_);
|
LL - let _ = std::collections::HashMap();
LL + let _ = std::collections::HashMap::with_hasher(_);
|
LL - let _ = std::collections::HashMap();
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
|
help: consider using the `Default` trait
|
LL | let _ = <std::collections::HashMap as std::default::Default>::default();
| + ++++++++++++++++++++++++++++++++++

error[E0423]: cannot initialize a tuple struct which contains private fields
--> $DIR/multi-suggestion.rs:11:19
|
LL | wtf: Some(Box(U {
| ^^^
|
note: constructor is not visible here due to private fields
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
|
= note: private field
|
= note: private field
help: you might have meant to use an associated function to build this type
|
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new(_)),
|
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new_uninit()),
|
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new_zeroed()),
|
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new_in(_, _)),
|
= and 12 other candidates
help: consider using the `Default` trait
|
LL - wtf: Some(Box(U {
LL + wtf: Some(<Box as std::default::Default>::default()),
|

error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
--> $DIR/multi-suggestion.rs:19:13
|
LL | let _ = std::collections::HashMap {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: private field `base` that was not provided
help: you might have meant to use an associated function to build this type
|
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::new();
|
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::with_capacity(_);
|
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::with_hasher(_);
|
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
|
help: consider using the `Default` trait
|
LL - let _ = std::collections::HashMap {};
LL + let _ = <std::collections::HashMap as std::default::Default>::default();
|

error: cannot construct `Box<_, _>` with struct literal syntax due to private fields
--> $DIR/multi-suggestion.rs:21:13
|
LL | let _ = Box {};
| ^^^
|
= note: private fields `0` and `1` that were not provided
help: you might have meant to use an associated function to build this type
|
LL - let _ = Box {};
LL + let _ = Box::new(_);
|
LL - let _ = Box {};
LL + let _ = Box::new_uninit();
|
LL - let _ = Box {};
LL + let _ = Box::new_zeroed();
|
LL - let _ = Box {};
LL + let _ = Box::new_in(_, _);
|
= and 12 other candidates
help: consider using the `Default` trait
|
LL - let _ = Box {};
LL + let _ = <Box as std::default::Default>::default();
|

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0423`.
22 changes: 22 additions & 0 deletions tests/ui/suggestions/multi-suggestion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ revisions: ascii unicode
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode

#![allow(dead_code)]
struct U <T> {
wtf: Option<Box<U<T>>>,
x: T,
}
fn main() {
U {
wtf: Some(Box(U { //[ascii]~ ERROR cannot initialize a tuple struct which contains private fields
wtf: None,
x: (),
})),
x: ()
};
let _ = std::collections::HashMap();
//[ascii]~^ ERROR expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
let _ = std::collections::HashMap {};
//[ascii]~^ ERROR cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
let _ = Box {}; //[ascii]~ ERROR cannot construct `Box<_, _>` with struct literal syntax due to private fields
}
130 changes: 130 additions & 0 deletions tests/ui/suggestions/multi-suggestion.unicode.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
╭▸ $DIR/multi-suggestion.rs:17:13
LL │ let _ = std::collections::HashMap();
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━
╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
╰ note: `std::collections::HashMap` defined here
╰╴
help: you might have meant to use an associated function to build this type
Comment on lines +1 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This seems to be a mild render bug for the unicode output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this should have been

error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
   ╭▸ $DIR/multi-suggestion.rs:17:13
   │
LL │     let _ = std::collections::HashMap();
   ╰╴            ━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
   │
   ╰ note: `std::collections::HashMap` defined here
help: you might have meant to use an associated function to build this type

Pre-existing. The logic for "couldn't find span" predates the unicode output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct that the logic for "couldn't find span" is the cause of the odd output here. I have a commit locally that changes how it is rendered to resemble what you expected it to be.

╭╴
LL │ let _ = std::collections::HashMap::new();
├╴ +++++
LL - let _ = std::collections::HashMap();
LL + let _ = std::collections::HashMap::with_capacity(_);
├╴
LL - let _ = std::collections::HashMap();
LL + let _ = std::collections::HashMap::with_hasher(_);
├╴
LL - let _ = std::collections::HashMap();
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
╰╴
help: consider using the `Default` trait
╭╴
LL │ let _ = <std::collections::HashMap as std::default::Default>::default();
╰╴ + ++++++++++++++++++++++++++++++++++

error[E0423]: cannot initialize a tuple struct which contains private fields
╭▸ $DIR/multi-suggestion.rs:11:19
LL │ wtf: Some(Box(U {
│ ━━━
╰╴
note: constructor is not visible here due to private fields
╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL
╰ note: private field
╰ note: private field
help: you might have meant to use an associated function to build this type
╭╴
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new(_)),
├╴
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new_uninit()),
├╴
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new_zeroed()),
├╴
LL - wtf: Some(Box(U {
LL - wtf: None,
LL - x: (),
LL - })),
LL + wtf: Some(Box::new_in(_, _)),
╰ and 12 other candidates
help: consider using the `Default` trait
╭╴
LL - wtf: Some(Box(U {
LL + wtf: Some(<Box as std::default::Default>::default()),
╰╴

error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
╭▸ $DIR/multi-suggestion.rs:19:13
LL │ let _ = std::collections::HashMap {};
│ ━━━━━━━━━━━━━━━━━━━━━━━━━
╰ note: private field `base` that was not provided
help: you might have meant to use an associated function to build this type
╭╴
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::new();
├╴
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::with_capacity(_);
├╴
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::with_hasher(_);
├╴
LL - let _ = std::collections::HashMap {};
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
╰╴
help: consider using the `Default` trait
╭╴
LL - let _ = std::collections::HashMap {};
LL + let _ = <std::collections::HashMap as std::default::Default>::default();
╰╴

error: cannot construct `Box<_, _>` with struct literal syntax due to private fields
╭▸ $DIR/multi-suggestion.rs:21:13
LL │ let _ = Box {};
│ ━━━
╰ note: private fields `0` and `1` that were not provided
help: you might have meant to use an associated function to build this type
╭╴
LL - let _ = Box {};
LL + let _ = Box::new(_);
├╴
LL - let _ = Box {};
LL + let _ = Box::new_uninit();
├╴
LL - let _ = Box {};
LL + let _ = Box::new_zeroed();
├╴
LL - let _ = Box {};
LL + let _ = Box::new_in(_, _);
╰ and 12 other candidates
help: consider using the `Default` trait
╭╴
LL - let _ = Box {};
LL + let _ = <Box as std::default::Default>::default();
╰╴

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0423`.
Loading
Loading