Skip to content

Commit 140f2fa

Browse files
authored
Rollup merge of #143661 - Muscraft:other-suggestion-message, r=estebank
chore: Improve how the other suggestions message gets rendered Note: This change is part of my ongoing work to use `annotate-snippets` as `rustc`'s emitter This change started as a way to remove some specialty code paths from `annotate-snippets`, by making the "and {} other candidates" message get rendered like a secondary message with no level, but turned into a fix for the message's Unicode output. Before this change, when using the Unicode output, the other suggestions message would get rendered outside of the main suggestion block, making it feel disconnected from what it was referring to. This change makes it so that the message is on the last line of the block, aligning its rendering with other secondary messages, and making it clear what the message is referring to. Before: ``` error[E0433]: failed to resolve: use of undeclared type `IntoIter` ╭▸ $DIR/issue-82956.rs:28:24 │ LL │ let mut iter = IntoIter::new(self); │ ━━━━━━━━ use of undeclared type `IntoIter` ╰╴ help: consider importing one of these structs ╭╴ LL + use std::array::IntoIter; ├╴ LL + use std::collections::binary_heap::IntoIter; ├╴ LL + use std::collections::btree_map::IntoIter; ├╴ LL + use std::collections::btree_set::IntoIter; ╰╴ and 9 other candidates ``` After: ``` error[E0433]: failed to resolve: use of undeclared type `IntoIter` ╭▸ $DIR/issue-82956.rs:28:24 │ LL │ let mut iter = IntoIter::new(self); │ ━━━━━━━━ use of undeclared type `IntoIter` ╰╴ help: consider importing one of these structs ╭╴ LL + use std::array::IntoIter; ├╴ LL + use std::collections::binary_heap::IntoIter; ├╴ LL + use std::collections::btree_map::IntoIter; ├╴ LL + use std::collections::btree_set::IntoIter; │ ╰ and 9 other candidates ```
2 parents 2ffaa1e + d67bf60 commit 140f2fa

13 files changed

+301
-14
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,17 +2446,22 @@ impl HumanEmitter {
24462446
| DisplaySuggestion::Underline => row_num - 1,
24472447
DisplaySuggestion::None => row_num,
24482448
};
2449-
self.draw_col_separator_end(&mut buffer, row, max_line_num_len + 1);
2449+
if other_suggestions > 0 {
2450+
self.draw_col_separator_no_space(&mut buffer, row, max_line_num_len + 1);
2451+
} else {
2452+
self.draw_col_separator_end(&mut buffer, row, max_line_num_len + 1);
2453+
}
24502454
row_num = row + 1;
24512455
}
24522456
}
24532457
if other_suggestions > 0 {
2458+
self.draw_note_separator(&mut buffer, row_num, max_line_num_len + 1, false);
24542459
let msg = format!(
24552460
"and {} other candidate{}",
24562461
other_suggestions,
24572462
pluralize!(other_suggestions)
24582463
);
2459-
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
2464+
buffer.append(row_num, &msg, Style::NoStyle);
24602465
}
24612466

24622467
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;

tests/ui/associated-types/associated-types-in-ambiguous-context.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ LL + type X = <CString as Deref>::Target;
4242
LL - type X = std::ops::Deref::Target;
4343
LL + type X = <IoSlice<'_> as Deref>::Target;
4444
|
45-
and N other candidates
45+
= and N other candidates
4646

4747
error[E0223]: ambiguous associated type
4848
--> $DIR/associated-types-in-ambiguous-context.rs:13:23

tests/ui/const-generics/issues/issue-82956.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL + use std::collections::btree_map::IntoIter;
1414
|
1515
LL + use std::collections::btree_set::IntoIter;
1616
|
17-
and 9 other candidates
17+
= and 9 other candidates
1818

1919
error: aborting due to 1 previous error
2020

tests/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL + fn setup() -> Determine { Set }
1818
LL - fn setup() -> Set { Set }
1919
LL + fn setup() -> PutDown { Set }
2020
|
21-
and 3 other candidates
21+
= and 3 other candidates
2222

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

4141
error: aborting due to 2 previous errors
4242

tests/ui/impl-trait/call_method_without_import.no_import.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL + use std::fmt::Display;
3030
|
3131
LL + use std::fmt::LowerExp;
3232
|
33-
and 5 other candidates
33+
= and 5 other candidates
3434

3535
error: aborting due to 2 previous errors
3636

tests/ui/imports/issue-56125.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL + use ::issue_56125::issue_56125;
1818
LL - use empty::issue_56125;
1919
LL + use ::issue_56125::last_segment::issue_56125;
2020
|
21-
and 1 other candidate
21+
= and 1 other candidate
2222

2323
error[E0659]: `issue_56125` is ambiguous
2424
--> $DIR/issue-56125.rs:6:9

tests/ui/lint/use_suggestion_json.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ mod foo {
419419
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
420420
\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
421421
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
422-
\u001b[0m and 9 other candidates\u001b[0m
422+
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0mand 9 other candidates\u001b[0m
423423

424424
"
425425
}

tests/ui/privacy/suggest-box-new.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LL - x: (),
6363
LL - })),
6464
LL + wtf: Some(Box::new_in(_, _)),
6565
|
66-
and 12 other candidates
66+
= and 12 other candidates
6767
help: consider using the `Default` trait
6868
|
6969
LL - wtf: Some(Box(U {
@@ -118,7 +118,7 @@ LL + let _ = Box::new_zeroed();
118118
LL - let _ = Box {};
119119
LL + let _ = Box::new_in(_, _);
120120
|
121-
and 12 other candidates
121+
= and 12 other candidates
122122
help: consider using the `Default` trait
123123
|
124124
LL - let _ = Box {};

tests/ui/rust-2018/issue-52202-use-suggestions.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL + use std::collections::hash_map::Drain;
1414
|
1515
LL + use std::collections::hash_set::Drain;
1616
|
17-
and 3 other candidates
17+
= and 3 other candidates
1818

1919
error: aborting due to 1 previous error
2020

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
2+
--> $DIR/multi-suggestion.rs:17:13
3+
|
4+
LL | let _ = std::collections::HashMap();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
7+
|
8+
= note: `std::collections::HashMap` defined here
9+
|
10+
help: you might have meant to use an associated function to build this type
11+
|
12+
LL | let _ = std::collections::HashMap::new();
13+
| +++++
14+
LL - let _ = std::collections::HashMap();
15+
LL + let _ = std::collections::HashMap::with_capacity(_);
16+
|
17+
LL - let _ = std::collections::HashMap();
18+
LL + let _ = std::collections::HashMap::with_hasher(_);
19+
|
20+
LL - let _ = std::collections::HashMap();
21+
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
22+
|
23+
help: consider using the `Default` trait
24+
|
25+
LL | let _ = <std::collections::HashMap as std::default::Default>::default();
26+
| + ++++++++++++++++++++++++++++++++++
27+
28+
error[E0423]: cannot initialize a tuple struct which contains private fields
29+
--> $DIR/multi-suggestion.rs:11:19
30+
|
31+
LL | wtf: Some(Box(U {
32+
| ^^^
33+
|
34+
note: constructor is not visible here due to private fields
35+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
36+
|
37+
= note: private field
38+
|
39+
= note: private field
40+
help: you might have meant to use an associated function to build this type
41+
|
42+
LL - wtf: Some(Box(U {
43+
LL - wtf: None,
44+
LL - x: (),
45+
LL - })),
46+
LL + wtf: Some(Box::new(_)),
47+
|
48+
LL - wtf: Some(Box(U {
49+
LL - wtf: None,
50+
LL - x: (),
51+
LL - })),
52+
LL + wtf: Some(Box::new_uninit()),
53+
|
54+
LL - wtf: Some(Box(U {
55+
LL - wtf: None,
56+
LL - x: (),
57+
LL - })),
58+
LL + wtf: Some(Box::new_zeroed()),
59+
|
60+
LL - wtf: Some(Box(U {
61+
LL - wtf: None,
62+
LL - x: (),
63+
LL - })),
64+
LL + wtf: Some(Box::new_in(_, _)),
65+
|
66+
= and 12 other candidates
67+
help: consider using the `Default` trait
68+
|
69+
LL - wtf: Some(Box(U {
70+
LL + wtf: Some(<Box as std::default::Default>::default()),
71+
|
72+
73+
error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
74+
--> $DIR/multi-suggestion.rs:19:13
75+
|
76+
LL | let _ = std::collections::HashMap {};
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
78+
|
79+
= note: private field `base` that was not provided
80+
help: you might have meant to use an associated function to build this type
81+
|
82+
LL - let _ = std::collections::HashMap {};
83+
LL + let _ = std::collections::HashMap::new();
84+
|
85+
LL - let _ = std::collections::HashMap {};
86+
LL + let _ = std::collections::HashMap::with_capacity(_);
87+
|
88+
LL - let _ = std::collections::HashMap {};
89+
LL + let _ = std::collections::HashMap::with_hasher(_);
90+
|
91+
LL - let _ = std::collections::HashMap {};
92+
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
93+
|
94+
help: consider using the `Default` trait
95+
|
96+
LL - let _ = std::collections::HashMap {};
97+
LL + let _ = <std::collections::HashMap as std::default::Default>::default();
98+
|
99+
100+
error: cannot construct `Box<_, _>` with struct literal syntax due to private fields
101+
--> $DIR/multi-suggestion.rs:21:13
102+
|
103+
LL | let _ = Box {};
104+
| ^^^
105+
|
106+
= note: private fields `0` and `1` that were not provided
107+
help: you might have meant to use an associated function to build this type
108+
|
109+
LL - let _ = Box {};
110+
LL + let _ = Box::new(_);
111+
|
112+
LL - let _ = Box {};
113+
LL + let _ = Box::new_uninit();
114+
|
115+
LL - let _ = Box {};
116+
LL + let _ = Box::new_zeroed();
117+
|
118+
LL - let _ = Box {};
119+
LL + let _ = Box::new_in(_, _);
120+
|
121+
= and 12 other candidates
122+
help: consider using the `Default` trait
123+
|
124+
LL - let _ = Box {};
125+
LL + let _ = <Box as std::default::Default>::default();
126+
|
127+
128+
error: aborting due to 4 previous errors
129+
130+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)