@@ -41,6 +41,15 @@ fn check_cfg_expected_note(
41
41
note
42
42
}
43
43
44
+ fn to_check_cfg_arg ( name : Symbol , value : Option < ( Symbol , Span ) > , with_quotes : bool ) -> String {
45
+ if let Some ( ( value, _value_span) ) = value {
46
+ let pre = if with_quotes { "\\ " } else { "" } ;
47
+ format ! ( "cfg({name}, values({pre}\" {value}{pre}\" ))" )
48
+ } else {
49
+ format ! ( "cfg({name})" )
50
+ }
51
+ }
52
+
44
53
pub ( super ) fn unexpected_cfg_name (
45
54
sess : & Session ,
46
55
diag : & mut Diag < ' _ , ( ) > ,
@@ -155,21 +164,17 @@ pub(super) fn unexpected_cfg_name(
155
164
}
156
165
}
157
166
158
- let inst = if let Some ( ( value, _value_span) ) = value {
159
- let pre = if is_from_cargo { "\\ " } else { "" } ;
160
- format ! ( "cfg({name}, values({pre}\" {value}{pre}\" ))" )
161
- } else {
162
- format ! ( "cfg({name})" )
163
- } ;
167
+ let inst = |with_quotes| to_check_cfg_arg ( name, value, with_quotes) ;
164
168
165
169
if is_from_cargo {
166
170
if !is_feature_cfg {
167
171
diag. help ( format ! ( "consider using a Cargo feature instead" ) ) ;
168
- diag. help ( format ! ( "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \" warn\" , check-cfg = [\" {inst} \" ] }}" ) ) ;
169
- diag. help ( format ! ( "or consider adding `println!(\" cargo::rustc-check-cfg={inst }\" );` to the top of the `build.rs`" ) ) ;
172
+ diag. help ( format ! ( "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \" warn\" , check-cfg = ['{}' ] }}" , inst ( /*with_quotes:*/ false ) ) ) ;
173
+ diag. help ( format ! ( "or consider adding `println!(\" cargo::rustc-check-cfg={}\" );` to the top of the `build.rs`" , inst ( /*with_quotes:*/ true ) ) ) ;
170
174
}
171
175
} else {
172
- diag. help ( format ! ( "to expect this configuration use `--check-cfg={inst}`" ) ) ;
176
+ let inst = inst ( /*with_quotes:*/ false ) ;
177
+ diag. help ( format ! ( "to expect this configuration use `--check-cfg={inst}`" , ) ) ;
173
178
}
174
179
diag. note ( "see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration" ) ;
175
180
}
@@ -252,12 +257,7 @@ pub(super) fn unexpected_cfg_value(
252
257
// do it if they want, but should not encourage them.
253
258
let is_cfg_a_well_know_name = sess. psess . check_config . well_known_names . contains ( & name) ;
254
259
255
- let inst = if let Some ( ( value, _value_span) ) = value {
256
- let pre = if is_from_cargo { "\\ " } else { "" } ;
257
- format ! ( "cfg({name}, values({pre}\" {value}{pre}\" ))" )
258
- } else {
259
- format ! ( "cfg({name})" )
260
- } ;
260
+ let inst = |with_quotes| to_check_cfg_arg ( name, value, with_quotes) ;
261
261
262
262
if is_from_cargo {
263
263
if name == sym:: feature {
@@ -268,12 +268,13 @@ pub(super) fn unexpected_cfg_value(
268
268
}
269
269
} else if !is_cfg_a_well_know_name {
270
270
diag. help ( format ! ( "consider using a Cargo feature instead" ) ) ;
271
- diag. help ( format ! ( "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \" warn\" , check-cfg = [\" {inst} \" ] }}" ) ) ;
272
- diag. help ( format ! ( "or consider adding `println!(\" cargo::rustc-check-cfg={inst }\" );` to the top of the `build.rs`" ) ) ;
271
+ diag. help ( format ! ( "or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \" warn\" , check-cfg = ['{}' ] }}" , inst ( /*with_quotes:*/ false ) ) ) ;
272
+ diag. help ( format ! ( "or consider adding `println!(\" cargo::rustc-check-cfg={}\" );` to the top of the `build.rs`" , inst ( /*with_quotes:*/ true ) ) ) ;
273
273
}
274
274
} else {
275
275
if !is_cfg_a_well_know_name {
276
- diag. help ( format ! ( "to expect this configuration use `--check-cfg={inst}`" ) ) ;
276
+ let inst = inst ( /*with_quotes:*/ false ) ;
277
+ diag. help ( format ! ( "to expect this configuration use `--check-cfg={inst}`" , ) ) ;
277
278
}
278
279
}
279
280
diag. note ( "see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration" ) ;
0 commit comments