@@ -120,14 +120,45 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
120120 ) ;
121121 let filename = FileName :: cfg_spec_source_code ( & s) ;
122122
123+ const VISIT : & str =
124+ "visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details" ;
125+
123126 macro_rules! error {
124127 ( $reason: expr) => {
125128 #[ allow( rustc:: untranslatable_diagnostic) ]
126129 #[ 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+ }
131162 } ;
132163 }
133164
@@ -183,7 +214,7 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
183214 }
184215 any_specified = true ;
185216 if !args. is_empty ( ) {
186- error ! ( "`any()` must be empty " ) ;
217+ error ! ( in arg , "`any()` takes no argument " ) ;
187218 }
188219 } else if arg. has_name ( sym:: values)
189220 && let Some ( args) = arg. meta_item_list ( )
@@ -202,25 +233,25 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
202233 && let Some ( args) = arg. meta_item_list ( )
203234 {
204235 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" ) ;
206237 }
207238 values_any_specified = true ;
208239 if !args. is_empty ( ) {
209- error ! ( "`any()` must be empty " ) ;
240+ error ! ( in arg , "`any()` in `values()` takes no argument " ) ;
210241 }
211242 } else if arg. has_name ( sym:: none)
212243 && let Some ( args) = arg. meta_item_list ( )
213244 {
214245 values. insert ( None ) ;
215246 if !args. is_empty ( ) {
216- error ! ( "`none()` must be empty " ) ;
247+ error ! ( in arg , "`none()` in `values()` takes no argument " ) ;
217248 }
218249 } 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()`" ) ;
220251 }
221252 }
222253 } 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(...)`" ) ;
224255 }
225256 }
226257
0 commit comments