Skip to content

Commit c66d469

Browse files
committed
check-cfg: only print the list of expected names once
1 parent 074c547 commit c66d469

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

compiler/rustc_errors/src/diagnostic_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
659659
msg: impl Into<SubdiagnosticMessage>,
660660
) -> &mut Self);
661661
forward!(pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self);
662+
forward!(pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self);
662663
forward!(pub fn span_help(
663664
&mut self,
664665
sp: impl Into<MultiSpan>,

compiler/rustc_lint/src/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,11 @@ pub trait LintContext: Sized {
759759

760760
if !possibilities.is_empty() {
761761
let possibilities = possibilities.join("`, `");
762-
db.help(format!("expected names are: `{possibilities}`"));
762+
// The list of expected names can be long (even by default) and
763+
// so the diagnostic produced can take a lot of space. To avoid
764+
// cloging the user output we only want to print that diagnostic
765+
// once.
766+
db.help_once(format!("expected names are: `{possibilities}`"));
763767
}
764768
}
765769
},

tests/ui/check-cfg/mix.stderr

-24
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,18 @@ warning: unexpected `cfg` condition name: `xxx`
7373
|
7474
LL | cfg!(xxx = "foo");
7575
| ^^^^^^^^^^^
76-
|
77-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
7876

7977
warning: unexpected `cfg` condition name: `xxx`
8078
--> $DIR/mix.rs:48:10
8179
|
8280
LL | cfg!(xxx);
8381
| ^^^
84-
|
85-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
8682

8783
warning: unexpected `cfg` condition name: `xxx`
8884
--> $DIR/mix.rs:50:14
8985
|
9086
LL | cfg!(any(xxx, windows));
9187
| ^^^
92-
|
93-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
9488

9589
warning: unexpected `cfg` condition value: `bad`
9690
--> $DIR/mix.rs:52:14
@@ -105,48 +99,36 @@ warning: unexpected `cfg` condition name: `xxx`
10599
|
106100
LL | cfg!(any(windows, xxx));
107101
| ^^^
108-
|
109-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
110102

111103
warning: unexpected `cfg` condition name: `xxx`
112104
--> $DIR/mix.rs:56:20
113105
|
114106
LL | cfg!(all(unix, xxx));
115107
| ^^^
116-
|
117-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
118108

119109
warning: unexpected `cfg` condition name: `aa`
120110
--> $DIR/mix.rs:58:14
121111
|
122112
LL | cfg!(all(aa, bb));
123113
| ^^
124-
|
125-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
126114

127115
warning: unexpected `cfg` condition name: `bb`
128116
--> $DIR/mix.rs:58:18
129117
|
130118
LL | cfg!(all(aa, bb));
131119
| ^^
132-
|
133-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
134120

135121
warning: unexpected `cfg` condition name: `aa`
136122
--> $DIR/mix.rs:61:14
137123
|
138124
LL | cfg!(any(aa, bb));
139125
| ^^
140-
|
141-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
142126

143127
warning: unexpected `cfg` condition name: `bb`
144128
--> $DIR/mix.rs:61:18
145129
|
146130
LL | cfg!(any(aa, bb));
147131
| ^^
148-
|
149-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
150132

151133
warning: unexpected `cfg` condition value: `zebra`
152134
--> $DIR/mix.rs:64:20
@@ -161,8 +143,6 @@ warning: unexpected `cfg` condition name: `xxx`
161143
|
162144
LL | cfg!(any(xxx, feature = "zebra"));
163145
| ^^^
164-
|
165-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
166146

167147
warning: unexpected `cfg` condition value: `zebra`
168148
--> $DIR/mix.rs:66:19
@@ -177,16 +157,12 @@ warning: unexpected `cfg` condition name: `xxx`
177157
|
178158
LL | cfg!(any(xxx, unix, xxx));
179159
| ^^^
180-
|
181-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
182160

183161
warning: unexpected `cfg` condition name: `xxx`
184162
--> $DIR/mix.rs:69:25
185163
|
186164
LL | cfg!(any(xxx, unix, xxx));
187165
| ^^^
188-
|
189-
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
190166

191167
warning: unexpected `cfg` condition value: `zebra`
192168
--> $DIR/mix.rs:72:14

0 commit comments

Comments
 (0)