Skip to content

Commit c97e79f

Browse files
committed
[WIP] [BROKEN] Move early buffered check-cfg lints to dyn lint diagnostics
1 parent 1a4e8e8 commit c97e79f

File tree

10 files changed

+434
-429
lines changed

10 files changed

+434
-429
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,50 @@ attr_parsing_stability_outside_std = stability attributes may not be used outsid
217217
attr_parsing_suffixed_literal_in_attribute = suffixed literals are not allowed in attributes
218218
.help = instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
219219
220+
attr_parsing_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_println}` to the top of the `build.rs`
221+
attr_parsing_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
222+
attr_parsing_unexpected_cfg_add_cargo_toml_lint_cfg = or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}
223+
attr_parsing_unexpected_cfg_add_cmdline_arg = to expect this configuration use `{$cmdline_arg}`
224+
attr_parsing_unexpected_cfg_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`
225+
226+
attr_parsing_unexpected_cfg_define_features = consider defining some features in `Cargo.toml`
227+
attr_parsing_unexpected_cfg_doc_cargo = see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
228+
attr_parsing_unexpected_cfg_doc_rustc = see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
229+
230+
attr_parsing_unexpected_cfg_from_external_macro_origin = using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate
231+
attr_parsing_unexpected_cfg_from_external_macro_refer = try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg
232+
attr_parsing_unexpected_cfg_name = unexpected `cfg` condition name: `{$name}`
233+
attr_parsing_unexpected_cfg_name_expected_names = expected names are: {$possibilities}{$and_more ->
234+
[0] {""}
235+
*[other] {" "}and {$and_more} more
236+
}
237+
attr_parsing_unexpected_cfg_name_expected_values = expected values for `{$best_match}` are: {$possibilities}
238+
attr_parsing_unexpected_cfg_name_similar_name = there is a config with a similar name
239+
attr_parsing_unexpected_cfg_name_similar_name_different_values = there is a config with a similar name and different values
240+
attr_parsing_unexpected_cfg_name_similar_name_no_value = there is a config with a similar name and no value
241+
attr_parsing_unexpected_cfg_name_similar_name_value = there is a config with a similar name and value
242+
attr_parsing_unexpected_cfg_name_version_syntax = there is a similar config predicate: `version("..")`
243+
attr_parsing_unexpected_cfg_name_with_similar_value = found config with similar value
244+
245+
attr_parsing_unexpected_cfg_value = unexpected `cfg` condition value: {$has_value ->
246+
[true] `{$value}`
247+
*[false] (none)
248+
}
249+
attr_parsing_unexpected_cfg_value_add_feature = consider adding `{$value}` as a feature in `Cargo.toml`
250+
attr_parsing_unexpected_cfg_value_expected_values = expected values for `{$name}` are: {$have_none_possibility ->
251+
[true] {"(none), "}
252+
*[false] {""}
253+
}{$possibilities}{$and_more ->
254+
[0] {""}
255+
*[other] {" "}and {$and_more} more
256+
}
257+
attr_parsing_unexpected_cfg_value_no_expected_value = no expected value for `{$name}`
258+
attr_parsing_unexpected_cfg_value_no_expected_values = no expected values for `{$name}`
259+
attr_parsing_unexpected_cfg_value_remove_condition = remove the condition
260+
attr_parsing_unexpected_cfg_value_remove_value = remove the value
261+
attr_parsing_unexpected_cfg_value_similar_name = there is a expected value with a similar name
262+
attr_parsing_unexpected_cfg_value_specify_value = specify a config value
263+
220264
attr_parsing_unknown_meta_item =
221265
unknown meta item '{$item}'
222266
.label = expected one of {$expected}

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use crate::{
1616
CfgMatchesLintEmitter, fluent_generated, parse_version, session_diagnostics, try_gate_cfg,
1717
};
1818

19+
// NOTE: Crate-public since it's also used in sibling module `cfg_old`.
20+
pub(crate) mod check_cfg;
21+
1922
pub const CFG_TEMPLATE: AttributeTemplate = template!(
2023
List: &["predicate"],
2124
"https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute"
@@ -234,35 +237,37 @@ pub fn eval_config_entry(
234237
EvalConfigResult::False { reason: cfg_entry.clone(), reason_span: *span }
235238
}
236239
}
237-
CfgEntry::NameValue { name, name_span, value, span } => {
240+
&CfgEntry::NameValue { name, name_span, value, span } => {
238241
if let ShouldEmit::ErrorsAndLints = emit_lints {
239-
match sess.psess.check_config.expecteds.get(name) {
242+
match sess.psess.check_config.expecteds.get(&name) {
240243
Some(ExpectedValues::Some(values))
241244
if !values.contains(&value.map(|(v, _)| v)) =>
242245
{
243246
id.emit_span_lint(
244247
sess,
245248
UNEXPECTED_CFGS,
246-
*span,
247-
BuiltinLintDiag::UnexpectedCfgValue((*name, *name_span), *value),
249+
span,
250+
// TODO: Do it lazily! Somehow pass a TyCtxt if possible
251+
check_cfg::unexpected_cfg_value(sess, None, (name, name_span), value),
248252
);
249253
}
250254
None if sess.psess.check_config.exhaustive_names => {
251255
id.emit_span_lint(
252256
sess,
253257
UNEXPECTED_CFGS,
254-
*span,
255-
BuiltinLintDiag::UnexpectedCfgName((*name, *name_span), *value),
258+
span,
259+
// TODO: Do it lazily! Somehow pass a TyCtxt if possible
260+
check_cfg::unexpected_cfg_name(sess, None, (name, name_span), value),
256261
);
257262
}
258263
_ => { /* not unexpected */ }
259264
}
260265
}
261266

262-
if sess.psess.config.contains(&(*name, value.map(|(v, _)| v))) {
267+
if sess.psess.config.contains(&(name, value.map(|(v, _)| v))) {
263268
EvalConfigResult::True
264269
} else {
265-
EvalConfigResult::False { reason: cfg_entry.clone(), reason_span: *span }
270+
EvalConfigResult::False { reason: cfg_entry.clone(), reason_span: span }
266271
}
267272
}
268273
CfgEntry::Version(min_version, version_span) => {

0 commit comments

Comments
 (0)