Skip to content

Commit 1658047

Browse files
Move check_cfg to rustc_attr_parsing
1 parent a7b3715 commit 1658047

File tree

11 files changed

+370
-368
lines changed

11 files changed

+370
-368
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,7 @@ dependencies = [
34613461
"rustc_hir",
34623462
"rustc_lexer",
34633463
"rustc_macros",
3464+
"rustc_middle",
34643465
"rustc_parse",
34653466
"rustc_session",
34663467
"rustc_span",

compiler/rustc_attr_parsing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1414
rustc_hir = { path = "../rustc_hir" }
1515
rustc_lexer = { path = "../rustc_lexer" }
1616
rustc_macros = { path = "../rustc_macros" }
17+
rustc_middle = { path = "../rustc_middle" }
1718
rustc_parse = { path = "../rustc_parse" }
1819
rustc_session = { path = "../rustc_session" }
1920
rustc_span = { path = "../rustc_span" }

compiler/rustc_attr_parsing/messages.ftl

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

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub(crate) mod check_cfg;
2+
13
use rustc_ast::token::Delimiter;
24
use rustc_ast::tokenstream::DelimSpan;
35
use rustc_ast::{AttrItem, Attribute, CRATE_NODE_ID, LitKind, NodeId, ast, token};

compiler/rustc_lint/src/early/diagnostics/check_cfg.rs renamed to compiler/rustc_attr_parsing/src/attributes/cfg/check_cfg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_session::config::ExpectedValues;
66
use rustc_span::edit_distance::find_best_match_for_name;
77
use rustc_span::{ExpnKind, Ident, Span, Symbol, sym};
88

9-
use crate::lints;
9+
use crate::session_diagnostics as lints;
1010

1111
const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35;
1212

@@ -109,7 +109,7 @@ fn cargo_macro_help(
109109
}
110110
}
111111

112-
pub(super) fn unexpected_cfg_name(
112+
pub fn unexpected_cfg_name(
113113
sess: &Session,
114114
tcx: Option<TyCtxt<'_>>,
115115
(name, name_span): (Symbol, Span),
@@ -266,7 +266,7 @@ pub(super) fn unexpected_cfg_name(
266266
lints::UnexpectedCfgName { code_sugg, invocation_help, name }
267267
}
268268

269-
pub(super) fn unexpected_cfg_value(
269+
pub fn unexpected_cfg_value(
270270
sess: &Session,
271271
tcx: Option<TyCtxt<'_>>,
272272
(name, name_span): (Symbol, Span),
@@ -353,7 +353,7 @@ pub(super) fn unexpected_cfg_value(
353353
// basic heuristic, we use the "cheat" unstable feature enable method and the
354354
// non-ui-testing enabled option.
355355
|| (matches!(sess.psess.unstable_features, rustc_feature::UnstableFeatures::Cheat)
356-
&& !sess.opts.unstable_opts.ui_testing);
356+
&& !sess.opts.unstable_opts.ui_testing);
357357

358358
let inst = |escape_quotes| {
359359
to_check_cfg_arg(Ident::new(name, name_span), value.map(|(v, _s)| v), escape_quotes)

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ mod session_diagnostics;
102102
mod target_checking;
103103
pub mod validate_attr;
104104

105+
pub use attributes::cfg::check_cfg::{unexpected_cfg_name, unexpected_cfg_value};
105106
pub use attributes::cfg::{
106107
CFG_TEMPLATE, EvalConfigResult, eval_config_entry, parse_cfg, parse_cfg_attr, parse_cfg_entry,
107108
};

0 commit comments

Comments
 (0)