@@ -120,14 +120,45 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
120
120
) ;
121
121
let filename = FileName :: cfg_spec_source_code ( & s) ;
122
122
123
+ const VISIT : & str =
124
+ "visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details" ;
125
+
123
126
macro_rules! error {
124
127
( $reason: expr) => {
125
128
#[ allow( rustc:: untranslatable_diagnostic) ]
126
129
#[ allow( rustc:: diagnostic_outside_of_impl) ]
127
- dcx. fatal( format!(
128
- concat!( "invalid `--check-cfg` argument: `{}` (" , $reason, ")" ) ,
129
- s
130
- ) )
130
+ {
131
+ let mut diag =
132
+ dcx. struct_fatal( format!( "invalid `--check-cfg` argument: `{s}`" ) ) ;
133
+ diag. note( $reason) ;
134
+ diag. note( VISIT ) ;
135
+ diag. emit( )
136
+ }
137
+ } ;
138
+ ( in $arg: expr, $reason: expr) => {
139
+ #[ allow( rustc:: untranslatable_diagnostic) ]
140
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
141
+ {
142
+ let mut diag =
143
+ dcx. struct_fatal( format!( "invalid `--check-cfg` argument: `{s}`" ) ) ;
144
+
145
+ let pparg = rustc_ast_pretty:: pprust:: meta_list_item_to_string( $arg) ;
146
+ if let Some ( lit) = $arg. lit( ) {
147
+ let ( lit_kind_article, lit_kind_descr) = {
148
+ let lit_kind = lit. as_token_lit( ) . kind;
149
+ ( lit_kind. article( ) , lit_kind. descr( ) )
150
+ } ;
151
+ diag. note( format!(
152
+ "`{pparg}` is {lit_kind_article} {lit_kind_descr} literal"
153
+ ) ) ;
154
+ } else {
155
+ diag. note( format!( "`{pparg}` is invalid" ) ) ;
156
+ }
157
+
158
+ diag. note( $reason) ;
159
+ diag. note( VISIT ) ;
160
+ diag. emit( )
161
+ }
131
162
} ;
132
163
}
133
164
@@ -183,7 +214,7 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
183
214
}
184
215
any_specified = true ;
185
216
if !args. is_empty ( ) {
186
- error ! ( "`any()` must be empty " ) ;
217
+ error ! ( in arg , "`any()` takes no argument " ) ;
187
218
}
188
219
} else if arg. has_name ( sym:: values)
189
220
&& let Some ( args) = arg. meta_item_list ( )
@@ -202,25 +233,25 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
202
233
&& let Some ( args) = arg. meta_item_list ( )
203
234
{
204
235
if values_any_specified {
205
- error ! ( "`any()` in `values()` cannot be specified multiple times" ) ;
236
+ error ! ( in arg , "`any()` in `values()` cannot be specified multiple times" ) ;
206
237
}
207
238
values_any_specified = true ;
208
239
if !args. is_empty ( ) {
209
- error ! ( "`any()` must be empty " ) ;
240
+ error ! ( in arg , "`any()` in `values()` takes no argument " ) ;
210
241
}
211
242
} else if arg. has_name ( sym:: none)
212
243
&& let Some ( args) = arg. meta_item_list ( )
213
244
{
214
245
values. insert ( None ) ;
215
246
if !args. is_empty ( ) {
216
- error ! ( "`none()` must be empty " ) ;
247
+ error ! ( in arg , "`none()` in `values()` takes no argument " ) ;
217
248
}
218
249
} else {
219
- error ! ( "`values()` arguments must be string literals, `none()` or `any()`" ) ;
250
+ error ! ( in arg , "`values()` arguments must be string literals, `none()` or `any()`" ) ;
220
251
}
221
252
}
222
253
} else {
223
- error ! ( "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`" ) ;
254
+ error ! ( in arg , "`cfg()` arguments must be simple identifiers, `any()` or `values(...)`" ) ;
224
255
}
225
256
}
226
257
0 commit comments