From fe4cabf1250f1dca43d279135cb97e43139b13d5 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Fri, 17 Oct 2025 00:42:21 +0800 Subject: [PATCH 1/6] Emit error when using path-segment keyword as cfg pred --- .../rustc_attr_parsing/src/attributes/cfg.rs | 5 +- .../src/attributes/cfg_old.rs | 5 +- compiler/rustc_interface/src/interface.rs | 55 +- tests/codegen-llvm/cf-protection.rs | 10 +- tests/ui/cfg/cmdline-false.rs | 2 +- ...th-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr | 2 + ...ath-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr | 2 + ...w-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr | 2 + ...cfg-pred-cli-cfg.cfg_raw_self_lower.stderr | 2 + ...cfg-pred-cli-cfg.cfg_raw_self_upper.stderr | 2 + ...w-as-cfg-pred-cli-cfg.cfg_raw_super.stderr | 2 + ...cfg-pred-cli-cfg.cfg_raw_underscore.stderr | 2 + ...-as-cfg-pred-cli-cfg.cfg_self_lower.stderr | 2 + ...-as-cfg-pred-cli-cfg.cfg_self_upper.stderr | 2 + ...h-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr | 2 + ...th-kw-as-cfg-pred-cli-cfg.cfg_super.stderr | 2 + ...-as-cfg-pred-cli-cfg.cfg_underscore.stderr | 2 + tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.rs | 24 + ...-pred-cli-check-cfg.check_cfg_crate.stderr | 5 + ...g-pred-cli-check-cfg.check_cfg_priv.stderr | 5 + ...d-cli-check-cfg.check_cfg_raw_crate.stderr | 5 + ...-check-cfg.check_cfg_raw_self_lower.stderr | 5 + ...-check-cfg.check_cfg_raw_self_upper.stderr | 5 + ...d-cli-check-cfg.check_cfg_raw_super.stderr | 5 + ...-check-cfg.check_cfg_raw_underscore.stderr | 5 + ...-cli-check-cfg.check_cfg_self_lower.stderr | 5 + ...-cli-check-cfg.check_cfg_self_upper.stderr | 5 + ...pred-cli-check-cfg.check_cfg_struct.stderr | 5 + ...-pred-cli-check-cfg.check_cfg_super.stderr | 5 + ...-cli-check-cfg.check_cfg_underscore.stderr | 5 + .../cfg/path-kw-as-cfg-pred-cli-check-cfg.rs | 25 + .../cfg/path-kw-as-cfg-pred-cli-raw-allow.rs | 6 + tests/ui/cfg/path-kw-as-cfg-pred.rs | 129 +++++ tests/ui/cfg/path-kw-as-cfg-pred.stderr | 529 ++++++++++++++++++ tests/ui/cfg/raw-true-false.rs | 6 +- tests/ui/check-cfg/raw-keywords.rs | 2 +- ...tderr => ctfe-id-unlimited.return_.stderr} | 12 +- .../explicit-tail-calls/ctfe-id-unlimited.rs | 10 +- 38 files changed, 875 insertions(+), 29 deletions(-) create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.rs create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred-cli-raw-allow.rs create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred.rs create mode 100644 tests/ui/cfg/path-kw-as-cfg-pred.stderr rename tests/ui/explicit-tail-calls/{ctfe-id-unlimited.return.stderr => ctfe-id-unlimited.return_.stderr} (59%) diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index af94e8acaf68e..d0d83c0f535b1 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -83,7 +83,8 @@ pub(crate) fn parse_cfg_entry( } }, a @ (ArgParser::NoArgs | ArgParser::NameValue(_)) => { - let Some(name) = meta.path().word_sym() else { + let Some(name) = meta.path().word_sym().filter(|s| !s.is_path_segment_keyword()) + else { cx.expected_identifier(meta.path().span()); return None; }; @@ -160,7 +161,7 @@ fn parse_cfg_entry_target( }; // Then, parse it as a name-value item - let Some(name) = sub_item.path().word_sym() else { + let Some(name) = sub_item.path().word_sym().filter(|s| !s.is_path_segment_keyword()) else { cx.expected_identifier(sub_item.path().span()); return None; }; diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg_old.rs b/compiler/rustc_attr_parsing/src/attributes/cfg_old.rs index 3257d898eccbc..70228d1e15101 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg_old.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg_old.rs @@ -220,7 +220,10 @@ pub fn eval_condition( } } } - MetaItemKind::Word | MetaItemKind::NameValue(..) if cfg.path.segments.len() != 1 => { + MetaItemKind::Word | MetaItemKind::NameValue(..) + if cfg.path.segments.len() != 1 + || cfg.path.segments[0].ident.is_path_segment_keyword() => + { dcx.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span }); true } diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index b52c5b4cd663b..ca9cfe4b83612 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -63,8 +63,8 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] dcx.fatal(format!( - concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), - s + concat!("invalid `--cfg` argument: `{}` ({})"), + s, $reason, )); }; } @@ -83,6 +83,19 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { } MetaItemKind::NameValue(..) | MetaItemKind::Word => { let ident = meta_item.ident().expect("multi-segment cfg key"); + + if ident.is_reserved() { + if !ident.name.can_be_raw() { + if s.trim().starts_with(&format!("r#{}", ident.as_str())) { + error!(format!("argument key must be an identifier, but `{}` cannot be a raw identifier", ident.name)); + } else { + error!(format!("argument key must be an identifier but found keyword `{}`", ident.name)); + } + } else if !s.trim().starts_with(&ident.to_string()) { + error!(format!("argument key must be an identifier but found keyword `{}`, escape it using `{}`", ident.as_str(), ident)); + } + } + return (ident.name, meta_item.value_str()); } } @@ -91,7 +104,7 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { Err(err) => err.cancel(), }, Err(errs) => errs.into_iter().for_each(|err| err.cancel()), - } + }; // If the user tried to use a key="value" flag, but is missing the quotes, provide // a hint about how to resolve this. @@ -202,6 +215,13 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch let mut values_specified = false; let mut values_any_specified = false; + let arg_strs = s + .trim() + .trim_start_matches("cfg(") + .trim_end_matches(')') + .split(',') + .collect::>(); + for arg in args { if arg.is_word() && let Some(ident) = arg.ident() @@ -209,11 +229,40 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch if values_specified { error!("`cfg()` names cannot be after values"); } + + if ident.is_reserved() { + if !ident.name.can_be_raw() { + if arg_strs[names.len()].starts_with(&format!("r#{}", ident.as_str())) { + error!(format!( + "argument key must be an identifier, but `{}` cannot be a raw identifier", + ident.name + )); + } else { + error!(format!( + "argument key must be an identifier but found keyword `{}`", + ident.name + )); + } + } else if !arg_strs[names.len()].starts_with(&ident.to_string()) { + error!(format!( + "argument key must be an identifier but found keyword `{}`, escape it using `{}`", + ident.as_str(), + ident + )); + } + } + names.push(ident); } else if let Some(boolean) = arg.boolean_literal() { if values_specified { error!("`cfg()` names cannot be after values"); } + + let lit_str = arg_strs[names.len()]; + if !lit_str.starts_with("r#") { + error!(in arg, format!("`cfg()` names must be identifiers but found keyword `{lit_str}`, escape it using `r#{lit_str}`")); + } + names.push(rustc_span::Ident::new( if boolean { rustc_span::kw::True } else { rustc_span::kw::False }, arg.span(), diff --git a/tests/codegen-llvm/cf-protection.rs b/tests/codegen-llvm/cf-protection.rs index 9efadb599322a..0ecfdd5eea55b 100644 --- a/tests/codegen-llvm/cf-protection.rs +++ b/tests/codegen-llvm/cf-protection.rs @@ -1,12 +1,12 @@ // Test that the correct module flags are emitted with different control-flow protection flags. //@ add-core-stubs -//@ revisions: undefined none branch return full +//@ revisions: undefined none branch return_ full //@ needs-llvm-components: x86 // [undefined] no extra compile-flags //@ [none] compile-flags: -Z cf-protection=none //@ [branch] compile-flags: -Z cf-protection=branch -//@ [return] compile-flags: -Z cf-protection=return +//@ [return_] compile-flags: -Z cf-protection=return //@ [full] compile-flags: -Z cf-protection=full //@ compile-flags: --target x86_64-unknown-linux-gnu @@ -30,9 +30,9 @@ pub fn test() {} // branch: !"cf-protection-branch", i32 1 // branch-NOT: !"cf-protection-return" -// return-NOT: !"cf-protection-branch" -// return: !"cf-protection-return", i32 1 -// return-NOT: !"cf-protection-branch" +// return_-NOT: !"cf-protection-branch" +// return_: !"cf-protection-return", i32 1 +// return_-NOT: !"cf-protection-branch" // full: !"cf-protection-branch", i32 1 // full: !"cf-protection-return", i32 1 diff --git a/tests/ui/cfg/cmdline-false.rs b/tests/ui/cfg/cmdline-false.rs index d4b7d3bbfdca2..917679e2e424b 100644 --- a/tests/ui/cfg/cmdline-false.rs +++ b/tests/ui/cfg/cmdline-false.rs @@ -1,5 +1,5 @@ /// Test that `--cfg false` doesn't cause `cfg(false)` to evaluate to `true` -//@ compile-flags: --cfg false +//@ compile-flags: --cfg r#false #[cfg(false)] fn foo() {} diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr new file mode 100644 index 0000000000000..73ef4320ff684 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `crate` (argument key must be an identifier but found keyword `crate`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr new file mode 100644 index 0000000000000..6b5d0517c6530 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `priv` (argument key must be an identifier but found keyword `priv`, escape it using `r#priv`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr new file mode 100644 index 0000000000000..7758aaa4dd5c0 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `r#crate` (argument key must be an identifier, but `crate` cannot be a raw identifier) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr new file mode 100644 index 0000000000000..8bdef6d2ba729 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `r#self` (argument key must be an identifier, but `self` cannot be a raw identifier) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr new file mode 100644 index 0000000000000..27ea45726cadd --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `r#Self` (argument key must be an identifier, but `Self` cannot be a raw identifier) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr new file mode 100644 index 0000000000000..af109d92baa1a --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `r#super` (argument key must be an identifier, but `super` cannot be a raw identifier) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr new file mode 100644 index 0000000000000..4699a125cb317 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `r#_` (argument key must be an identifier, but `_` cannot be a raw identifier) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr new file mode 100644 index 0000000000000..cd5bbf73d05c4 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `self` (argument key must be an identifier but found keyword `self`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr new file mode 100644 index 0000000000000..08dabe0980227 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `Self` (argument key must be an identifier but found keyword `Self`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr new file mode 100644 index 0000000000000..f4d16eba5e0b5 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `struct` (argument key must be an identifier but found keyword `struct`, escape it using `r#struct`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr new file mode 100644 index 0000000000000..7647f116d1553 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `super` (argument key must be an identifier but found keyword `super`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr new file mode 100644 index 0000000000000..e62f06b0d11e7 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `_` (argument key must be an identifier but found keyword `_`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.rs b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.rs new file mode 100644 index 0000000000000..b50b8216ca47b --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.rs @@ -0,0 +1,24 @@ +//@ edition: 2024 + +//@ revisions: cfg_crate cfg_super cfg_self_lower cfg_self_upper +//@ revisions: cfg_raw_crate cfg_raw_super cfg_raw_self_lower cfg_raw_self_upper +//@ revisions: cfg_struct cfg_priv cfg_underscore cfg_raw_underscore + +//@ [cfg_crate]compile-flags: --cfg crate +//@ [cfg_super]compile-flags: --cfg super +//@ [cfg_self_lower]compile-flags: --cfg self +//@ [cfg_self_upper]compile-flags: --cfg Self + +//@ [cfg_raw_crate]compile-flags: --cfg r#crate +//@ [cfg_raw_super]compile-flags: --cfg r#super +//@ [cfg_raw_self_lower]compile-flags: --cfg r#self +//@ [cfg_raw_self_upper]compile-flags: --cfg r#Self + +//@ [cfg_struct]compile-flags: --cfg struct +//@ [cfg_priv]compile-flags: --cfg priv +//@ [cfg_underscore]compile-flags: --cfg _ +//@ [cfg_raw_underscore]compile-flags: --cfg r#_ + +fn main() {} + +//~? ERROR invalid `--cfg` argument diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr new file mode 100644 index 0000000000000..ccb738525b1e3 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(crate)` + | + = note: argument key must be an identifier but found keyword `crate` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr new file mode 100644 index 0000000000000..6d7a09abc81af --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(priv)` + | + = note: argument key must be an identifier but found keyword `priv`, escape it using `r#priv` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr new file mode 100644 index 0000000000000..4894758250fe6 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(r#crate)` + | + = note: argument key must be an identifier, but `crate` cannot be a raw identifier + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr new file mode 100644 index 0000000000000..03fb62ffdf724 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(r#self)` + | + = note: argument key must be an identifier, but `self` cannot be a raw identifier + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr new file mode 100644 index 0000000000000..8908571345126 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(r#Self)` + | + = note: argument key must be an identifier, but `Self` cannot be a raw identifier + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr new file mode 100644 index 0000000000000..7559805ac76b4 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(r#super)` + | + = note: argument key must be an identifier, but `super` cannot be a raw identifier + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr new file mode 100644 index 0000000000000..e530cf8d1bc45 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(r#_)` + | + = note: argument key must be an identifier, but `_` cannot be a raw identifier + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr new file mode 100644 index 0000000000000..b626f3a77f4cb --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(self)` + | + = note: argument key must be an identifier but found keyword `self` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr new file mode 100644 index 0000000000000..2f2cbf96c9a8c --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(Self)` + | + = note: argument key must be an identifier but found keyword `Self` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr new file mode 100644 index 0000000000000..c327242a9f2fb --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(struct)` + | + = note: argument key must be an identifier but found keyword `struct`, escape it using `r#struct` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr new file mode 100644 index 0000000000000..454599a00e7ce --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(super)` + | + = note: argument key must be an identifier but found keyword `super` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr new file mode 100644 index 0000000000000..3928b127e32dd --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(_)` + | + = note: argument key must be an identifier but found keyword `_` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs new file mode 100644 index 0000000000000..aae4f12dc4517 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs @@ -0,0 +1,25 @@ +//@ edition: 2024 + +//@ revisions: check_cfg_crate check_cfg_super check_cfg_self_lower check_cfg_self_upper +//@ revisions: check_cfg_raw_crate check_cfg_raw_super check_cfg_raw_self_lower +//@ revisions: check_cfg_raw_self_upper +//@ revisions: check_cfg_struct check_cfg_priv check_cfg_underscore check_cfg_raw_underscore + +//@ [check_cfg_crate]compile-flags: --check-cfg 'cfg(crate)' +//@ [check_cfg_super]compile-flags: --check-cfg 'cfg(super)' +//@ [check_cfg_self_lower]compile-flags: --check-cfg 'cfg(self)' +//@ [check_cfg_self_upper]compile-flags: --check-cfg 'cfg(Self)' + +//@ [check_cfg_raw_crate]compile-flags: --check-cfg 'cfg(r#crate)' +//@ [check_cfg_raw_super]compile-flags: --check-cfg 'cfg(r#super)' +//@ [check_cfg_raw_self_lower]compile-flags: --check-cfg 'cfg(r#self)' +//@ [check_cfg_raw_self_upper]compile-flags: --check-cfg 'cfg(r#Self)' + +//@ [check_cfg_struct]compile-flags: --check-cfg 'cfg(struct)' +//@ [check_cfg_priv]compile-flags: --check-cfg 'cfg(priv)' +//@ [check_cfg_underscore]compile-flags: --check-cfg 'cfg(_)' +//@ [check_cfg_raw_underscore]compile-flags: --check-cfg 'cfg(r#_)' + +fn main() {} + +//~? ERROR invalid `--check-cfg` argument diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-raw-allow.rs b/tests/ui/cfg/path-kw-as-cfg-pred-cli-raw-allow.rs new file mode 100644 index 0000000000000..2f603baf28bd3 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-raw-allow.rs @@ -0,0 +1,6 @@ +//@ edition: 2024 +//@ check-pass +//@ compile-flags: --cfg r#struct --cfg r#priv +//@ compile-flags: --check-cfg 'cfg(r#struct)' --check-cfg 'cfg(r#priv)' + +fn main() {} diff --git a/tests/ui/cfg/path-kw-as-cfg-pred.rs b/tests/ui/cfg/path-kw-as-cfg-pred.rs new file mode 100644 index 0000000000000..0f54d2ee0df0c --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred.rs @@ -0,0 +1,129 @@ +//@ edition: 2024 + +#![allow(unexpected_cfgs)] + +macro_rules! foo { + () => { + #[cfg($crate)] //~ ERROR malformed `cfg` attribute input + mod _cfg_dollar_crate {} + #[cfg_attr($crate, path = "foo")] //~ ERROR malformed `cfg_attr` attribute input + mod _cfg_attr_dollar_crate {} + #[cfg_attr(true, cfg($crate))] //~ ERROR malformed `cfg` attribute input + mod _cfg_attr_true_cfg_crate {} + + cfg!($crate); //~ ERROR `cfg` predicate key must be an identifier + }; +} + +#[cfg(crate)] //~ ERROR malformed `cfg` attribute input +mod _cfg_crate {} +#[cfg(super)] //~ ERROR malformed `cfg` attribute input +mod _cfg_super {} +#[cfg(self)] //~ ERROR malformed `cfg` attribute input +mod _cfg_self_lower {} +#[cfg(Self)] //~ ERROR malformed `cfg` attribute input +mod _cfg_self_upper {} +#[cfg_attr(crate, path = "foo")] //~ ERROR malformed `cfg_attr` attribute input +mod _cfg_attr_crate {} +#[cfg_attr(super, path = "foo")] //~ ERROR malformed `cfg_attr` attribute input +mod _cfg_attr_super {} +#[cfg_attr(self, path = "foo")] //~ ERROR malformed `cfg_attr` attribute input +mod _cfg_attr_self_lower {} +#[cfg_attr(Self, path = "foo")] //~ ERROR malformed `cfg_attr` attribute input +mod _cfg_attr_self_upper {} +#[cfg_attr(true, cfg(crate))] //~ ERROR malformed `cfg` attribute input +mod _cfg_attr_true_cfg_crate {} +#[cfg_attr(true, cfg(super))] //~ ERROR malformed `cfg` attribute input +mod _cfg_attr_true_cfg_super {} +#[cfg_attr(true, cfg(self))] //~ ERROR malformed `cfg` attribute input +mod _cfg_attr_true_cfg_self_lower {} +#[cfg_attr(true, cfg(Self))] //~ ERROR malformed `cfg` attribute input +mod _cfg_attr_true_cfg_self_upper {} + +#[cfg(struct)] //~ ERROR expected identifier, found keyword +mod _cfg_struct {} +#[cfg(priv)] //~ ERROR expected identifier, found reserved keyword `priv` +mod _cfg_priv {} +#[cfg(_)] //~ ERROR expected identifier, found reserved identifier `_` +mod _cfg_underscore {} +#[cfg_attr(struct, path = "foo")] //~ ERROR expected identifier, found keyword +mod _cfg_attr_struct {} +#[cfg_attr(priv, path = "foo")] //~ ERROR expected identifier, found reserved keyword `priv` +mod _cfg_attr_priv {} +#[cfg_attr(_, path = "foo")] //~ ERROR expected identifier, found reserved identifier `_` +mod _cfg_attr_underscore {} +#[cfg_attr(true, cfg(struct))] //~ ERROR expected identifier, found keyword +mod _cfg_attr_true_cfg_struct {} +#[cfg_attr(true, cfg(priv))] //~ ERROR expected identifier, found reserved keyword `priv` +mod _cfg_attr_true_cfg_priv {} +#[cfg_attr(true, cfg(_))] //~ ERROR expected identifier, found reserved identifier `_` +mod _cfg_attr_true_cfg_underscore {} + +fn main() { + foo!(); + + cfg!(crate); //~ ERROR `cfg` predicate key must be an identifier + cfg!(super); //~ ERROR `cfg` predicate key must be an identifier + cfg!(self); //~ ERROR `cfg` predicate key must be an identifier + cfg!(Self); //~ ERROR `cfg` predicate key must be an identifier + + cfg!(r#crate); //~ ERROR `crate` cannot be a raw identifier + //~^ ERROR `cfg` predicate key must be an identifier + cfg!(r#super); //~ ERROR `super` cannot be a raw identifier + //~^ ERROR `cfg` predicate key must be an identifier + cfg!(r#self); //~ ERROR `self` cannot be a raw identifier + //~^ ERROR `cfg` predicate key must be an identifier + cfg!(r#Self); //~ ERROR `Self` cannot be a raw identifier + //~^ ERROR `cfg` predicate key must be an identifier + + cfg!(struct); //~ ERROR expected identifier, found keyword + cfg!(priv); //~ ERROR expected identifier, found reserved keyword `priv` + cfg!(_); //~ ERROR expected identifier, found reserved identifier `_` + + cfg!(r#struct); // Ok + cfg!(r#priv); // Ok + cfg!(r#_); //~ ERROR `_` cannot be a raw identifier +} + +#[cfg(r#crate)] //~ ERROR malformed `cfg` attribute input +//~^ ERROR `crate` cannot be a raw identifier +mod _cfg_r_crate {} +#[cfg(r#super)] //~ ERROR malformed `cfg` attribute input +//~^ ERROR `super` cannot be a raw identifier +mod _cfg_r_super {} +#[cfg(r#self)] //~ ERROR malformed `cfg` attribute input +//~^ ERROR `self` cannot be a raw identifier +mod _cfg_r_self_lower {} +#[cfg(r#Self)] //~ ERROR malformed `cfg` attribute input +//~^ ERROR `Self` cannot be a raw identifier +mod _cfg_r_self_upper {} +#[cfg_attr(r#crate, cfg(r#crate))] //~ ERROR malformed `cfg_attr` attribute input +//~^ ERROR `crate` cannot be a raw identifier +//~^^ ERROR `crate` cannot be a raw identifier +mod _cfg_attr_r_crate {} +#[cfg_attr(r#super, cfg(r#super))] //~ ERROR malformed `cfg_attr` attribute input +//~^ ERROR `super` cannot be a raw identifier +//~^^ ERROR `super` cannot be a raw identifier +mod _cfg_attr_r_super {} +#[cfg_attr(r#self, cfg(r#self))] //~ ERROR malformed `cfg_attr` attribute input +//~^ ERROR `self` cannot be a raw identifier +//~^^ ERROR `self` cannot be a raw identifier +mod _cfg_attr_r_self_lower {} +#[cfg_attr(r#Self, cfg(r#Self))] //~ ERROR malformed `cfg_attr` attribute input +//~^ ERROR `Self` cannot be a raw identifier +//~^^ ERROR `Self` cannot be a raw identifier +mod _cfg_attr_r_self_upper {} + +#[cfg(r#struct)] // Ok +mod _cfg_r_struct {} +#[cfg(r#priv)] // Ok +mod _cfg_r_priv {} +#[cfg(r#_)] //~ ERROR `_` cannot be a raw identifier +mod _cfg_r_underscore {} +#[cfg_attr(r#struct, cfg(r#struct))] // Ok +mod _cfg_attr_r_struct {} +#[cfg_attr(r#priv, cfg(r#priv))] // Ok +mod _cfg_attr_r_priv {} +#[cfg_attr(r#_, cfg(r#_))] //~ ERROR `_` cannot be a raw identifier +//~^ ERROR `_` cannot be a raw identifier +mod _cfg_attr_r_underscore {} diff --git a/tests/ui/cfg/path-kw-as-cfg-pred.stderr b/tests/ui/cfg/path-kw-as-cfg-pred.stderr new file mode 100644 index 0000000000000..4277b1e4b8c78 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred.stderr @@ -0,0 +1,529 @@ +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:70:10 + | +LL | cfg!(r#crate); + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:72:10 + | +LL | cfg!(r#super); + | ^^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:74:10 + | +LL | cfg!(r#self); + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:76:10 + | +LL | cfg!(r#Self); + | ^^^^^^ + +error: `_` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:85:10 + | +LL | cfg!(r#_); + | ^^^ + +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:88:7 + | +LL | #[cfg(r#crate)] + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:91:7 + | +LL | #[cfg(r#super)] + | ^^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:94:7 + | +LL | #[cfg(r#self)] + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:97:7 + | +LL | #[cfg(r#Self)] + | ^^^^^^ + +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:100:12 + | +LL | #[cfg_attr(r#crate, cfg(r#crate))] + | ^^^^^^^ + +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:100:25 + | +LL | #[cfg_attr(r#crate, cfg(r#crate))] + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:104:12 + | +LL | #[cfg_attr(r#super, cfg(r#super))] + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:104:25 + | +LL | #[cfg_attr(r#super, cfg(r#super))] + | ^^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:108:12 + | +LL | #[cfg_attr(r#self, cfg(r#self))] + | ^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:108:24 + | +LL | #[cfg_attr(r#self, cfg(r#self))] + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:112:12 + | +LL | #[cfg_attr(r#Self, cfg(r#Self))] + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:112:24 + | +LL | #[cfg_attr(r#Self, cfg(r#Self))] + | ^^^^^^ + +error: `_` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:121:7 + | +LL | #[cfg(r#_)] + | ^^^ + +error: `_` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:127:12 + | +LL | #[cfg_attr(r#_, cfg(r#_))] + | ^^^ + +error: `_` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:127:21 + | +LL | #[cfg_attr(r#_, cfg(r#_))] + | ^^^ + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:18:1 + | +LL | #[cfg(crate)] + | ^^^^^^-----^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:20:1 + | +LL | #[cfg(super)] + | ^^^^^^-----^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:22:1 + | +LL | #[cfg(self)] + | ^^^^^^----^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:24:1 + | +LL | #[cfg(Self)] + | ^^^^^^----^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:26:1 + | +LL | #[cfg_attr(crate, path = "foo")] + | ^^^^^^^^^^^-----^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:28:1 + | +LL | #[cfg_attr(super, path = "foo")] + | ^^^^^^^^^^^-----^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:30:1 + | +LL | #[cfg_attr(self, path = "foo")] + | ^^^^^^^^^^^----^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:32:1 + | +LL | #[cfg_attr(Self, path = "foo")] + | ^^^^^^^^^^^----^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:34:18 + | +LL | #[cfg_attr(true, cfg(crate))] + | ^^^^-----^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:36:18 + | +LL | #[cfg_attr(true, cfg(super))] + | ^^^^-----^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:38:18 + | +LL | #[cfg_attr(true, cfg(self))] + | ^^^^----^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:40:18 + | +LL | #[cfg_attr(true, cfg(Self))] + | ^^^^----^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:43:7 + | +LL | #[cfg(struct)] + | ^^^^^^ expected identifier, found keyword + +error: expected identifier, found reserved keyword `priv` + --> $DIR/path-kw-as-cfg-pred.rs:45:7 + | +LL | #[cfg(priv)] + | ^^^^ expected identifier, found reserved keyword + +error: expected identifier, found reserved identifier `_` + --> $DIR/path-kw-as-cfg-pred.rs:47:7 + | +LL | #[cfg(_)] + | ^ expected identifier, found reserved identifier + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:49:12 + | +LL | #[cfg_attr(struct, path = "foo")] + | ^^^^^^ expected identifier, found keyword + | +help: escape `struct` to use it as an identifier + | +LL | #[cfg_attr(r#struct, path = "foo")] + | ++ + +error: expected identifier, found reserved keyword `priv` + --> $DIR/path-kw-as-cfg-pred.rs:51:12 + | +LL | #[cfg_attr(priv, path = "foo")] + | ^^^^ expected identifier, found reserved keyword + | +help: escape `priv` to use it as an identifier + | +LL | #[cfg_attr(r#priv, path = "foo")] + | ++ + +error: expected identifier, found reserved identifier `_` + --> $DIR/path-kw-as-cfg-pred.rs:53:12 + | +LL | #[cfg_attr(_, path = "foo")] + | ^ expected identifier, found reserved identifier + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:55:22 + | +LL | #[cfg_attr(true, cfg(struct))] + | ^^^^^^ expected identifier, found keyword + +error: expected identifier, found reserved keyword `priv` + --> $DIR/path-kw-as-cfg-pred.rs:57:22 + | +LL | #[cfg_attr(true, cfg(priv))] + | ^^^^ expected identifier, found reserved keyword + +error: expected identifier, found reserved identifier `_` + --> $DIR/path-kw-as-cfg-pred.rs:59:22 + | +LL | #[cfg_attr(true, cfg(_))] + | ^ expected identifier, found reserved identifier + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:88:1 + | +LL | #[cfg(r#crate)] + | ^^^^^^-------^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:91:1 + | +LL | #[cfg(r#super)] + | ^^^^^^-------^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:94:1 + | +LL | #[cfg(r#self)] + | ^^^^^^------^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:97:1 + | +LL | #[cfg(r#Self)] + | ^^^^^^------^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:100:1 + | +LL | #[cfg_attr(r#crate, cfg(r#crate))] + | ^^^^^^^^^^^-------^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:104:1 + | +LL | #[cfg_attr(r#super, cfg(r#super))] + | ^^^^^^^^^^^-------^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:108:1 + | +LL | #[cfg_attr(r#self, cfg(r#self))] + | ^^^^^^^^^^^------^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:112:1 + | +LL | #[cfg_attr(r#Self, cfg(r#Self))] + | ^^^^^^^^^^^------^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | + = note: for more information, visit + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:7:9 + | +LL | #[cfg($crate)] + | ^^^^^^------^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` +... +LL | foo!(); + | ------ in this macro invocation + | + = note: for more information, visit + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:9:9 + | +LL | #[cfg_attr($crate, path = "foo")] + | ^^^^^^^^^^^------^^^^^^^^^^^^^^^^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` +... +LL | foo!(); + | ------ in this macro invocation + | + = note: for more information, visit + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0539]: malformed `cfg` attribute input + --> $DIR/path-kw-as-cfg-pred.rs:11:26 + | +LL | #[cfg_attr(true, cfg($crate))] + | ^^^^------^ + | | | + | | expected a valid identifier here + | help: must be of the form: `#[cfg(predicate)]` +... +LL | foo!(); + | ------ in this macro invocation + | + = note: for more information, visit + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:14:14 + | +LL | cfg!($crate); + | ^^^^^^ +... +LL | foo!(); + | ------ in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:65:10 + | +LL | cfg!(crate); + | ^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:66:10 + | +LL | cfg!(super); + | ^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:67:10 + | +LL | cfg!(self); + | ^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:68:10 + | +LL | cfg!(Self); + | ^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:70:10 + | +LL | cfg!(r#crate); + | ^^^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:72:10 + | +LL | cfg!(r#super); + | ^^^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:74:10 + | +LL | cfg!(r#self); + | ^^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/path-kw-as-cfg-pred.rs:76:10 + | +LL | cfg!(r#Self); + | ^^^^^^ + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:79:10 + | +LL | cfg!(struct); + | ^^^^^^ expected identifier, found keyword + +error: expected identifier, found reserved keyword `priv` + --> $DIR/path-kw-as-cfg-pred.rs:80:10 + | +LL | cfg!(priv); + | ^^^^ expected identifier, found reserved keyword + +error: expected identifier, found reserved identifier `_` + --> $DIR/path-kw-as-cfg-pred.rs:81:10 + | +LL | cfg!(_); + | ^ expected identifier, found reserved identifier + +error: aborting due to 64 previous errors + +For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/cfg/raw-true-false.rs b/tests/ui/cfg/raw-true-false.rs index c92672fc144e3..9f4c6c1fcd42f 100644 --- a/tests/ui/cfg/raw-true-false.rs +++ b/tests/ui/cfg/raw-true-false.rs @@ -1,9 +1,5 @@ //@ check-pass -//@ revisions: r0x0 r0x1 r1x0 r1x1 -//@[r0x0] compile-flags: --cfg false --check-cfg=cfg(false) -//@[r0x1] compile-flags: --cfg false --check-cfg=cfg(r#false) -//@[r1x0] compile-flags: --cfg r#false --check-cfg=cfg(false) -//@[r1x1] compile-flags: --cfg r#false --check-cfg=cfg(r#false) +//@ compile-flags: --cfg r#false --check-cfg=cfg(r#false) #![deny(unexpected_cfgs)] fn main() { #[cfg(not(r#false))] diff --git a/tests/ui/check-cfg/raw-keywords.rs b/tests/ui/check-cfg/raw-keywords.rs index b82eb5a64e9a1..07daf564f6d8d 100644 --- a/tests/ui/check-cfg/raw-keywords.rs +++ b/tests/ui/check-cfg/raw-keywords.rs @@ -3,7 +3,7 @@ // //@ check-pass //@ no-auto-check-cfg -//@ compile-flags: --cfg=true --cfg=async --check-cfg=cfg(r#true,r#async,edition2015,edition2021) +//@ compile-flags: --cfg=r#true --cfg=r#async --check-cfg=cfg(r#true,r#async,edition2015,edition2021) // //@ revisions: edition2015 edition2021 //@ [edition2015] edition: 2015 diff --git a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return_.stderr similarity index 59% rename from tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr rename to tests/ui/explicit-tail-calls/ctfe-id-unlimited.return_.stderr index 25e30397c8322..5102f278f0273 100644 --- a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr +++ b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return_.stderr @@ -10,15 +10,15 @@ note: inside `rec_id` LL | inner(0, n) | ^^^^^^^^^^^ note: [... 125 additional calls inside `inner` ...] - --> $DIR/ctfe-id-unlimited.rs:17:42 + --> $DIR/ctfe-id-unlimited.rs:17:41 | -LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), - | ^^^^^^^^^^^^^^^^^^^^^ +LL | #[cfg(return_)] _ => return inner(acc + 1, n - 1), + | ^^^^^^^^^^^^^^^^^^^^^ note: inside `inner` - --> $DIR/ctfe-id-unlimited.rs:17:42 + --> $DIR/ctfe-id-unlimited.rs:17:41 | -LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), - | ^^^^^^^^^^^^^^^^^^^^^ the failure occurred here +LL | #[cfg(return_)] _ => return inner(acc + 1, n - 1), + | ^^^^^^^^^^^^^^^^^^^^^ the failure occurred here error: aborting due to 1 previous error diff --git a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs index 53cccb38e2b88..0efd8967f8bd9 100644 --- a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs +++ b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs @@ -1,5 +1,5 @@ -//@ revisions: become return -//@ [become] run-pass +//@ revisions: become_ return_ +//@ [become_] run-pass #![expect(incomplete_features)] #![feature(explicit_tail_calls)] @@ -13,8 +13,8 @@ const fn rec_id(n: u32) -> u32 { const fn inner(acc: u32, n: u32) -> u32 { match n { 0 => acc, - #[cfg(r#become)] _ => become inner(acc + 1, n - 1), - #[cfg(r#return)] _ => return inner(acc + 1, n - 1), + #[cfg(become_)] _ => become inner(acc + 1, n - 1), + #[cfg(return_)] _ => return inner(acc + 1, n - 1), } } @@ -25,7 +25,7 @@ const fn rec_id(n: u32) -> u32 { const ORIGINAL: u32 = 12345; // Original number, but with identity function applied // (this is the same, but requires execution of the recursion) -const ID_ED: u32 = rec_id(ORIGINAL); //[return]~ ERROR: reached the configured maximum number of stack frames +const ID_ED: u32 = rec_id(ORIGINAL); //[return_]~ ERROR: reached the configured maximum number of stack frames // Assert to make absolutely sure the computation actually happens const ASSERT: () = assert!(ORIGINAL == ID_ED); From d63734ff2c7b367868865bb621a8ef752c6be461 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Fri, 17 Oct 2025 23:47:11 +0800 Subject: [PATCH 2/6] Emit errors during parsing when calling interface::parse_cfg/parse_check_cfg --- compiler/rustc_errors/src/emitter.rs | 22 ++--- compiler/rustc_interface/src/interface.rs | 98 +++++++------------ compiler/rustc_parse/src/parser/mod.rs | 2 +- compiler/rustc_session/src/parse.rs | 13 +-- .../cfg-frontmatter.stderr | 6 ++ .../multiline-args-value/cfg-shebang.stderr | 5 + .../check-cfg-frontmatter.stderr | 6 ++ .../check-cfg-shebang.stderr | 5 + ...th-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr | 2 +- ...ath-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr | 6 +- ...w-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr | 4 + ...cfg-pred-cli-cfg.cfg_raw_self_lower.stderr | 4 + ...cfg-pred-cli-cfg.cfg_raw_self_upper.stderr | 4 + ...w-as-cfg-pred-cli-cfg.cfg_raw_super.stderr | 4 + ...cfg-pred-cli-cfg.cfg_raw_underscore.stderr | 4 + ...-as-cfg-pred-cli-cfg.cfg_self_lower.stderr | 2 +- ...-as-cfg-pred-cli-cfg.cfg_self_upper.stderr | 2 +- ...h-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr | 6 +- ...th-kw-as-cfg-pred-cli-cfg.cfg_super.stderr | 2 +- ...-as-cfg-pred-cli-cfg.cfg_underscore.stderr | 6 +- ...-pred-cli-check-cfg.check_cfg_crate.stderr | 2 +- ...g-pred-cli-check-cfg.check_cfg_priv.stderr | 6 +- ...d-cli-check-cfg.check_cfg_raw_crate.stderr | 4 + ...-check-cfg.check_cfg_raw_self_lower.stderr | 4 + ...-check-cfg.check_cfg_raw_self_upper.stderr | 4 + ...d-cli-check-cfg.check_cfg_raw_super.stderr | 4 + ...-check-cfg.check_cfg_raw_underscore.stderr | 4 + ...-cli-check-cfg.check_cfg_self_lower.stderr | 2 +- ...-cli-check-cfg.check_cfg_self_upper.stderr | 2 +- ...pred-cli-check-cfg.check_cfg_struct.stderr | 6 +- ...-pred-cli-check-cfg.check_cfg_super.stderr | 2 +- ...-cli-check-cfg.check_cfg_underscore.stderr | 6 +- .../cfg/path-kw-as-cfg-pred-cli-check-cfg.rs | 2 +- .../invalid-arguments.anything_else.stderr | 4 + .../invalid-arguments.giberich.stderr | 4 + .../invalid-arguments.unsafe_attr.stderr | 4 + .../invalid-arguments.unterminated.stderr | 4 + .../cfg-arg-invalid-1.stderr | 4 + .../cfg-arg-invalid-6.stderr | 4 + .../cfg-arg-invalid-8.stderr | 4 + .../cfg-arg-invalid-9.stderr | 4 + .../cfg-empty-codemap.stderr | 4 + 42 files changed, 190 insertions(+), 97 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 0d10f29d31d64..8b3e85e3ca680 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -534,30 +534,28 @@ impl Emitter for HumanEmitter { } } -/// An emitter that does nothing when emitting a non-fatal diagnostic. -/// Fatal diagnostics are forwarded to `fatal_emitter` to avoid silent +/// An emitter that does nothing when emitting a non-error diagnostic. +/// Error diagnostics are forwarded to `error_emitter` to avoid silent /// failures of rustc, as witnessed e.g. in issue #89358. -pub struct FatalOnlyEmitter { - pub fatal_emitter: Box, - pub fatal_note: Option, +pub struct ErrorOnlyEmitter { + pub error_emitter: Box, + pub error_note: String, } -impl Emitter for FatalOnlyEmitter { +impl Emitter for ErrorOnlyEmitter { fn source_map(&self) -> Option<&SourceMap> { None } fn emit_diagnostic(&mut self, mut diag: DiagInner, registry: &Registry) { - if diag.level == Level::Fatal { - if let Some(fatal_note) = &self.fatal_note { - diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new()); - } - self.fatal_emitter.emit_diagnostic(diag, registry); + if diag.is_error() { + diag.sub(Level::Note, self.error_note.clone(), MultiSpan::new()); + self.error_emitter.emit_diagnostic(diag, registry); } } fn translator(&self) -> &Translator { - self.fatal_emitter.translator() + self.error_emitter.translator() } } diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index ca9cfe4b83612..141e6ead838a4 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -15,6 +15,7 @@ use rustc_middle::ty::CurrentGcx; use rustc_middle::util::Providers; use rustc_parse::lexer::StripTokens; use rustc_parse::new_parser_from_source_str; +use rustc_parse::parser::Recovery; use rustc_parse::parser::attr::AllowLeadingUnsafe; use rustc_query_impl::QueryCtxt; use rustc_query_system::query::print_query_stack; @@ -52,7 +53,7 @@ pub struct Compiler { pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { cfgs.into_iter() .map(|s| { - let psess = ParseSess::with_fatal_emitter( + let psess = ParseSess::with_error_emitter( vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], format!("this error occurred on the command line: `--cfg={s}`"), ); @@ -63,7 +64,7 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] dcx.fatal(format!( - concat!("invalid `--cfg` argument: `{}` ({})"), + "invalid `--cfg` argument: `{}` ({})", s, $reason, )); }; @@ -71,39 +72,38 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { match new_parser_from_source_str(&psess, filename, s.to_string(), StripTokens::Nothing) { - Ok(mut parser) => match parser.parse_meta_item(AllowLeadingUnsafe::No) { - Ok(meta_item) if parser.token == token::Eof => { - if meta_item.path.segments.len() != 1 { - error!("argument key must be an identifier"); - } - match &meta_item.kind { - MetaItemKind::List(..) => {} - MetaItemKind::NameValue(lit) if !lit.kind.is_str() => { - error!("argument value must be a string"); + Ok(mut parser) => { + parser = parser.recovery(Recovery::Forbidden); + match parser.parse_meta_item(AllowLeadingUnsafe::No) { + Ok(meta_item) if parser.token == token::Eof => { + if meta_item.path.segments.len() != 1 { + error!("argument key must be an identifier"); } - MetaItemKind::NameValue(..) | MetaItemKind::Word => { - let ident = meta_item.ident().expect("multi-segment cfg key"); + match &meta_item.kind { + MetaItemKind::List(..) => {} + MetaItemKind::NameValue(lit) if !lit.kind.is_str() => { + error!("argument value must be a string"); + } + MetaItemKind::NameValue(..) | MetaItemKind::Word => { + let ident = meta_item.ident().expect("multi-segment cfg key"); - if ident.is_reserved() { if !ident.name.can_be_raw() { - if s.trim().starts_with(&format!("r#{}", ident.as_str())) { - error!(format!("argument key must be an identifier, but `{}` cannot be a raw identifier", ident.name)); - } else { - error!(format!("argument key must be an identifier but found keyword `{}`", ident.name)); - } - } else if !s.trim().starts_with(&ident.to_string()) { - error!(format!("argument key must be an identifier but found keyword `{}`, escape it using `{}`", ident.as_str(), ident)); + error!(format!("argument key must be an identifier, but `{}` cannot be a raw identifier", ident.name)); } - } - return (ident.name, meta_item.value_str()); + return (ident.name, meta_item.value_str()); + } } } + Ok(..) => {} + Err(err) => { + err.emit(); + }, } - Ok(..) => {} - Err(err) => err.cancel(), }, - Err(errs) => errs.into_iter().for_each(|err| err.cancel()), + Err(errs) => errs.into_iter().for_each(|err| { + err.emit(); + }), }; // If the user tried to use a key="value" flag, but is missing the quotes, provide @@ -129,7 +129,7 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() }; for s in specs { - let psess = ParseSess::with_fatal_emitter( + let psess = ParseSess::with_error_emitter( vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], format!("this error occurred on the command line: `--check-cfg={s}`"), ); @@ -186,16 +186,19 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch { Ok(parser) => parser, Err(errs) => { - errs.into_iter().for_each(|err| err.cancel()); + errs.into_iter().for_each(|err| { + err.emit(); + }); expected_error(); } }; + parser = parser.recovery(Recovery::Forbidden); let meta_item = match parser.parse_meta_item(AllowLeadingUnsafe::No) { Ok(meta_item) if parser.token == token::Eof => meta_item, Ok(..) => expected_error(), Err(err) => { - err.cancel(); + err.emit(); expected_error(); } }; @@ -215,13 +218,6 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch let mut values_specified = false; let mut values_any_specified = false; - let arg_strs = s - .trim() - .trim_start_matches("cfg(") - .trim_end_matches(')') - .split(',') - .collect::>(); - for arg in args { if arg.is_word() && let Some(ident) = arg.ident() @@ -230,26 +226,11 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch error!("`cfg()` names cannot be after values"); } - if ident.is_reserved() { - if !ident.name.can_be_raw() { - if arg_strs[names.len()].starts_with(&format!("r#{}", ident.as_str())) { - error!(format!( - "argument key must be an identifier, but `{}` cannot be a raw identifier", - ident.name - )); - } else { - error!(format!( - "argument key must be an identifier but found keyword `{}`", - ident.name - )); - } - } else if !arg_strs[names.len()].starts_with(&ident.to_string()) { - error!(format!( - "argument key must be an identifier but found keyword `{}`, escape it using `{}`", - ident.as_str(), - ident - )); - } + if !ident.name.can_be_raw() { + error!(format!( + "argument key must be an identifier, but `{}` cannot be a raw identifier", + ident.name + )); } names.push(ident); @@ -258,11 +239,6 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch error!("`cfg()` names cannot be after values"); } - let lit_str = arg_strs[names.len()]; - if !lit_str.starts_with("r#") { - error!(in arg, format!("`cfg()` names must be identifiers but found keyword `{lit_str}`, escape it using `r#{lit_str}`")); - } - names.push(rustc_span::Ident::new( if boolean { rustc_span::kw::True } else { rustc_span::kw::False }, arg.span(), diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index ed4069dae933c..8bb0459bc563d 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -466,7 +466,7 @@ impl<'a> Parser<'a> { // Public for rustfmt usage. pub fn parse_ident(&mut self) -> PResult<'a, Ident> { - self.parse_ident_common(true) + self.parse_ident_common(self.may_recover()) } fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident> { diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 9048c51d5b42d..ce71e414ed798 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -8,7 +8,7 @@ use rustc_ast::attr::AttrIdGenerator; use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::sync::{AppendOnlyVec, Lock}; -use rustc_errors::emitter::{FatalOnlyEmitter, HumanEmitter, stderr_destination}; +use rustc_errors::emitter::{ErrorOnlyEmitter, HumanEmitter, stderr_destination}; use rustc_errors::translation::Translator; use rustc_errors::{ BufferedEarlyLint, ColorConfig, DecorateDiagCompat, Diag, DiagCtxt, DiagCtxtHandle, @@ -315,16 +315,13 @@ impl ParseSess { } } - pub fn with_fatal_emitter(locale_resources: Vec<&'static str>, fatal_note: String) -> Self { + pub fn with_error_emitter(locale_resources: Vec<&'static str>, error_note: String) -> Self { let translator = Translator::with_fallback_bundle(locale_resources, false); let sm = Arc::new(SourceMap::new(FilePathMapping::empty())); - let fatal_emitter = + let emitter = Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), translator)); - let dcx = DiagCtxt::new(Box::new(FatalOnlyEmitter { - fatal_emitter, - fatal_note: Some(fatal_note), - })) - .disable_warnings(); + let dcx = DiagCtxt::new(Box::new(ErrorOnlyEmitter { error_emitter: emitter, error_note })) + .disable_warnings(); ParseSess::with_dcx(dcx, sm) } diff --git a/tests/run-make/multiline-args-value/cfg-frontmatter.stderr b/tests/run-make/multiline-args-value/cfg-frontmatter.stderr index 9b06f84be4884..6acf5fbb7d9f4 100644 --- a/tests/run-make/multiline-args-value/cfg-frontmatter.stderr +++ b/tests/run-make/multiline-args-value/cfg-frontmatter.stderr @@ -1,3 +1,9 @@ +error: expected identifier, found `-` + | + = note: this error occurred on the command line: `--cfg=--- + --- + key` + error: invalid `--cfg` argument: `--- --- key` (expected `key` or `key="value"`) diff --git a/tests/run-make/multiline-args-value/cfg-shebang.stderr b/tests/run-make/multiline-args-value/cfg-shebang.stderr index 09baf3b51239c..5da3cb552305b 100644 --- a/tests/run-make/multiline-args-value/cfg-shebang.stderr +++ b/tests/run-make/multiline-args-value/cfg-shebang.stderr @@ -1,3 +1,8 @@ +error: expected identifier, found `#` + | + = note: this error occurred on the command line: `--cfg=#!/usr/bin/shebang + key` + error: invalid `--cfg` argument: `#!/usr/bin/shebang key` (expected `key` or `key="value"`) diff --git a/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr b/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr index 4a499cc0a1e24..d9cd830aab5d7 100644 --- a/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr +++ b/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr @@ -1,3 +1,9 @@ +error: expected identifier, found `-` + | + = note: this error occurred on the command line: `--check-cfg=--- + --- + cfg(key)` + error: invalid `--check-cfg` argument: `--- --- cfg(key)` diff --git a/tests/run-make/multiline-args-value/check-cfg-shebang.stderr b/tests/run-make/multiline-args-value/check-cfg-shebang.stderr index 5bf18dc2b14c4..2caead5f4e05e 100644 --- a/tests/run-make/multiline-args-value/check-cfg-shebang.stderr +++ b/tests/run-make/multiline-args-value/check-cfg-shebang.stderr @@ -1,3 +1,8 @@ +error: expected identifier, found `#` + | + = note: this error occurred on the command line: `--check-cfg=#!/usr/bin/shebang + cfg(key)` + error: invalid `--check-cfg` argument: `#!/usr/bin/shebang cfg(key)` | diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr index 73ef4320ff684..56eb3b0b67dc2 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `crate` (argument key must be an identifier but found keyword `crate`) +error: invalid `--cfg` argument: `crate` (argument key must be an identifier, but `crate` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr index 6b5d0517c6530..11fe76ca3e916 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr @@ -1,2 +1,6 @@ -error: invalid `--cfg` argument: `priv` (argument key must be an identifier but found keyword `priv`, escape it using `r#priv`) +error: expected identifier, found reserved keyword `priv` + | + = note: this error occurred on the command line: `--cfg=priv` + +error: invalid `--cfg` argument: `priv` (expected `key` or `key="value"`) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr index 7758aaa4dd5c0..910c27cd797bb 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr @@ -1,2 +1,6 @@ +error: `crate` cannot be a raw identifier + | + = note: this error occurred on the command line: `--cfg=r#crate` + error: invalid `--cfg` argument: `r#crate` (argument key must be an identifier, but `crate` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr index 8bdef6d2ba729..2260f4e2f11a4 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr @@ -1,2 +1,6 @@ +error: `self` cannot be a raw identifier + | + = note: this error occurred on the command line: `--cfg=r#self` + error: invalid `--cfg` argument: `r#self` (argument key must be an identifier, but `self` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr index 27ea45726cadd..f40498023f9f6 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr @@ -1,2 +1,6 @@ +error: `Self` cannot be a raw identifier + | + = note: this error occurred on the command line: `--cfg=r#Self` + error: invalid `--cfg` argument: `r#Self` (argument key must be an identifier, but `Self` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr index af109d92baa1a..0d8bb0269f0f3 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr @@ -1,2 +1,6 @@ +error: `super` cannot be a raw identifier + | + = note: this error occurred on the command line: `--cfg=r#super` + error: invalid `--cfg` argument: `r#super` (argument key must be an identifier, but `super` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr index 4699a125cb317..a5fc16149500f 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr @@ -1,2 +1,6 @@ +error: `_` cannot be a raw identifier + | + = note: this error occurred on the command line: `--cfg=r#_` + error: invalid `--cfg` argument: `r#_` (argument key must be an identifier, but `_` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr index cd5bbf73d05c4..e4c855f145aad 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `self` (argument key must be an identifier but found keyword `self`) +error: invalid `--cfg` argument: `self` (argument key must be an identifier, but `self` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr index 08dabe0980227..383b42949d56e 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `Self` (argument key must be an identifier but found keyword `Self`) +error: invalid `--cfg` argument: `Self` (argument key must be an identifier, but `Self` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr index f4d16eba5e0b5..cb80272aa7c9f 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr @@ -1,2 +1,6 @@ -error: invalid `--cfg` argument: `struct` (argument key must be an identifier but found keyword `struct`, escape it using `r#struct`) +error: expected identifier, found keyword `struct` + | + = note: this error occurred on the command line: `--cfg=struct` + +error: invalid `--cfg` argument: `struct` (expected `key` or `key="value"`) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr index 7647f116d1553..630c8f78a7898 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `super` (argument key must be an identifier but found keyword `super`) +error: invalid `--cfg` argument: `super` (argument key must be an identifier, but `super` cannot be a raw identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr index e62f06b0d11e7..55caf707954a3 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr @@ -1,2 +1,6 @@ -error: invalid `--cfg` argument: `_` (argument key must be an identifier but found keyword `_`) +error: expected identifier, found reserved identifier `_` + | + = note: this error occurred on the command line: `--cfg=_` + +error: invalid `--cfg` argument: `_` (expected `key` or `key="value"`) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr index ccb738525b1e3..55e94f26e7bd7 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(crate)` | - = note: argument key must be an identifier but found keyword `crate` + = note: argument key must be an identifier, but `crate` cannot be a raw identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr index 6d7a09abc81af..7832e0c9eab7a 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr @@ -1,5 +1,9 @@ +error: expected unsuffixed literal, found reserved keyword `priv` + | + = note: this error occurred on the command line: `--check-cfg=cfg(priv)` + error: invalid `--check-cfg` argument: `cfg(priv)` | - = note: argument key must be an identifier but found keyword `priv`, escape it using `r#priv` + = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr index 4894758250fe6..3f2a66645a86f 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr @@ -1,3 +1,7 @@ +error: `crate` cannot be a raw identifier + | + = note: this error occurred on the command line: `--check-cfg=cfg(r#crate)` + error: invalid `--check-cfg` argument: `cfg(r#crate)` | = note: argument key must be an identifier, but `crate` cannot be a raw identifier diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr index 03fb62ffdf724..c29573be4e63a 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr @@ -1,3 +1,7 @@ +error: `self` cannot be a raw identifier + | + = note: this error occurred on the command line: `--check-cfg=cfg(r#self)` + error: invalid `--check-cfg` argument: `cfg(r#self)` | = note: argument key must be an identifier, but `self` cannot be a raw identifier diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr index 8908571345126..d4104e58c0dbf 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr @@ -1,3 +1,7 @@ +error: `Self` cannot be a raw identifier + | + = note: this error occurred on the command line: `--check-cfg=cfg(r#Self)` + error: invalid `--check-cfg` argument: `cfg(r#Self)` | = note: argument key must be an identifier, but `Self` cannot be a raw identifier diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr index 7559805ac76b4..b0f47e92d2480 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr @@ -1,3 +1,7 @@ +error: `super` cannot be a raw identifier + | + = note: this error occurred on the command line: `--check-cfg=cfg(r#super)` + error: invalid `--check-cfg` argument: `cfg(r#super)` | = note: argument key must be an identifier, but `super` cannot be a raw identifier diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr index e530cf8d1bc45..0c9a307e743b6 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr @@ -1,3 +1,7 @@ +error: `_` cannot be a raw identifier + | + = note: this error occurred on the command line: `--check-cfg=cfg(r#_)` + error: invalid `--check-cfg` argument: `cfg(r#_)` | = note: argument key must be an identifier, but `_` cannot be a raw identifier diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr index b626f3a77f4cb..30e80662dbcd1 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(self)` | - = note: argument key must be an identifier but found keyword `self` + = note: argument key must be an identifier, but `self` cannot be a raw identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr index 2f2cbf96c9a8c..f1eec929afa69 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(Self)` | - = note: argument key must be an identifier but found keyword `Self` + = note: argument key must be an identifier, but `Self` cannot be a raw identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr index c327242a9f2fb..1bbc8187d2718 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr @@ -1,5 +1,9 @@ +error: expected unsuffixed literal, found keyword `struct` + | + = note: this error occurred on the command line: `--check-cfg=cfg(struct)` + error: invalid `--check-cfg` argument: `cfg(struct)` | - = note: argument key must be an identifier but found keyword `struct`, escape it using `r#struct` + = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr index 454599a00e7ce..aab2d9cf09f7b 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(super)` | - = note: argument key must be an identifier but found keyword `super` + = note: argument key must be an identifier, but `super` cannot be a raw identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr index 3928b127e32dd..1fbbc51ada87f 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr @@ -1,5 +1,9 @@ +error: expected unsuffixed literal, found reserved identifier `_` + | + = note: this error occurred on the command line: `--check-cfg=cfg(_)` + error: invalid `--check-cfg` argument: `cfg(_)` | - = note: argument key must be an identifier but found keyword `_` + = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs index aae4f12dc4517..57ec3f3d54bd4 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs @@ -1,4 +1,4 @@ -//@ edition: 2024 +//@ edition: 2021 //@ revisions: check_cfg_crate check_cfg_super check_cfg_self_lower check_cfg_self_upper //@ revisions: check_cfg_raw_crate check_cfg_raw_super check_cfg_raw_self_lower diff --git a/tests/ui/check-cfg/invalid-arguments.anything_else.stderr b/tests/ui/check-cfg/invalid-arguments.anything_else.stderr index f3bc0b782e22f..62bfe9a2e6f6f 100644 --- a/tests/ui/check-cfg/invalid-arguments.anything_else.stderr +++ b/tests/ui/check-cfg/invalid-arguments.anything_else.stderr @@ -1,3 +1,7 @@ +error: expected unsuffixed literal, found `...` + | + = note: this error occurred on the command line: `--check-cfg=anything_else(...)` + error: invalid `--check-cfg` argument: `anything_else(...)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.giberich.stderr b/tests/ui/check-cfg/invalid-arguments.giberich.stderr index 3e35014549183..b9adace399a80 100644 --- a/tests/ui/check-cfg/invalid-arguments.giberich.stderr +++ b/tests/ui/check-cfg/invalid-arguments.giberich.stderr @@ -1,3 +1,7 @@ +error: expected unsuffixed literal, found `...` + | + = note: this error occurred on the command line: `--check-cfg=cfg(...)` + error: invalid `--check-cfg` argument: `cfg(...)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr b/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr index 5236ed6f60547..d56a48028331b 100644 --- a/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr +++ b/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr @@ -1,3 +1,7 @@ +error: expected identifier, found keyword `unsafe` + | + = note: this error occurred on the command line: `--check-cfg=unsafe(cfg(foo))` + error: invalid `--check-cfg` argument: `unsafe(cfg(foo))` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.unterminated.stderr b/tests/ui/check-cfg/invalid-arguments.unterminated.stderr index 150e1d66426b9..d2db65b960c04 100644 --- a/tests/ui/check-cfg/invalid-arguments.unterminated.stderr +++ b/tests/ui/check-cfg/invalid-arguments.unterminated.stderr @@ -1,3 +1,7 @@ +error: this file contains an unclosed delimiter + | + = note: this error occurred on the command line: `--check-cfg=cfg(` + error: invalid `--check-cfg` argument: `cfg(` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr index 3a12e97868000..6fb2f01ec896c 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr @@ -1,2 +1,6 @@ +error: expected unsuffixed literal, found `c` + | + = note: this error occurred on the command line: `--cfg=a(b=c)` + error: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\") diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr index 7d2087b4b71f7..542d573791ad3 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr @@ -1,2 +1,6 @@ +error: this file contains an unclosed delimiter + | + = note: this error occurred on the command line: `--cfg=a{` + error: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`) diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr index 7bb1814127b29..0d8db852f04c2 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr @@ -1,2 +1,6 @@ +error: unexpected closing delimiter: `)` + | + = note: this error occurred on the command line: `--cfg=)` + error: invalid `--cfg` argument: `)` (expected `key` or `key="value"`) diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr index 985b525225839..db6ee40552865 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr @@ -1,2 +1,6 @@ +error: unexpected token: `value` + | + = note: this error occurred on the command line: `--cfg=key=value` + error: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\") diff --git a/tests/ui/conditional-compilation/cfg-empty-codemap.stderr b/tests/ui/conditional-compilation/cfg-empty-codemap.stderr index 128e3cd730680..fbf58ceed52a3 100644 --- a/tests/ui/conditional-compilation/cfg-empty-codemap.stderr +++ b/tests/ui/conditional-compilation/cfg-empty-codemap.stderr @@ -1,2 +1,6 @@ +error: expected identifier, found `""` + | + = note: this error occurred on the command line: `--cfg=""` + error: invalid `--cfg` argument: `""` (expected `key` or `key="value"`) From 42725a1f72fac60552cfaa051184f08befa34a65 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sat, 18 Oct 2025 20:56:25 +0800 Subject: [PATCH 3/6] Bless clippy test --- ...e.32bit.stderr => cast_size.r32bit.stderr} | 0 ...e.64bit.stderr => cast_size.r64bit.stderr} | 0 src/tools/clippy/tests/ui/cast_size.rs | 8 +++--- ...tderr => fn_to_numeric_cast.r32bit.stderr} | 0 ...tderr => fn_to_numeric_cast.r64bit.stderr} | 0 .../clippy/tests/ui/fn_to_numeric_cast.rs | 26 +++++++++---------- ...tderr => large_enum_variant.r32bit.stderr} | 0 ...tderr => large_enum_variant.r64bit.stderr} | 0 .../clippy/tests/ui/large_enum_variant.rs | 10 +++---- 9 files changed, 22 insertions(+), 22 deletions(-) rename src/tools/clippy/tests/ui/{cast_size.32bit.stderr => cast_size.r32bit.stderr} (100%) rename src/tools/clippy/tests/ui/{cast_size.64bit.stderr => cast_size.r64bit.stderr} (100%) rename src/tools/clippy/tests/ui/{fn_to_numeric_cast.32bit.stderr => fn_to_numeric_cast.r32bit.stderr} (100%) rename src/tools/clippy/tests/ui/{fn_to_numeric_cast.64bit.stderr => fn_to_numeric_cast.r64bit.stderr} (100%) rename src/tools/clippy/tests/ui/{large_enum_variant.32bit.stderr => large_enum_variant.r32bit.stderr} (100%) rename src/tools/clippy/tests/ui/{large_enum_variant.64bit.stderr => large_enum_variant.r64bit.stderr} (100%) diff --git a/src/tools/clippy/tests/ui/cast_size.32bit.stderr b/src/tools/clippy/tests/ui/cast_size.r32bit.stderr similarity index 100% rename from src/tools/clippy/tests/ui/cast_size.32bit.stderr rename to src/tools/clippy/tests/ui/cast_size.r32bit.stderr diff --git a/src/tools/clippy/tests/ui/cast_size.64bit.stderr b/src/tools/clippy/tests/ui/cast_size.r64bit.stderr similarity index 100% rename from src/tools/clippy/tests/ui/cast_size.64bit.stderr rename to src/tools/clippy/tests/ui/cast_size.r64bit.stderr diff --git a/src/tools/clippy/tests/ui/cast_size.rs b/src/tools/clippy/tests/ui/cast_size.rs index ecc5866941918..cefab253bbeed 100644 --- a/src/tools/clippy/tests/ui/cast_size.rs +++ b/src/tools/clippy/tests/ui/cast_size.rs @@ -1,6 +1,6 @@ -//@revisions: 32bit 64bit -//@[32bit]ignore-bitwidth: 64 -//@[64bit]ignore-bitwidth: 32 +//@revisions: r32bit r64bit +//@[r32bit]ignore-bitwidth: 64 +//@[r64bit]ignore-bitwidth: 32 //@no-rustfix: only some diagnostics have suggestions #![warn( @@ -62,7 +62,7 @@ fn main() { //~^ cast_precision_loss 9_999_999_999_999_999usize as f64; //~^ cast_precision_loss - //~[32bit]^^ ERROR: literal out of range for `usize` + //~[r32bit]^^ ERROR: literal out of range for `usize` // 999_999_999_999_999_999_999_999_999_999u128 as f128; } diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.32bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast.r32bit.stderr similarity index 100% rename from src/tools/clippy/tests/ui/fn_to_numeric_cast.32bit.stderr rename to src/tools/clippy/tests/ui/fn_to_numeric_cast.r32bit.stderr diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast.r64bit.stderr similarity index 100% rename from src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr rename to src/tools/clippy/tests/ui/fn_to_numeric_cast.r64bit.stderr diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs index f53cbacdb3771..a38792cd9ede0 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs @@ -1,6 +1,6 @@ -//@revisions: 32bit 64bit -//@[32bit]ignore-bitwidth: 64 -//@[64bit]ignore-bitwidth: 32 +//@revisions: r32bit r64bit +//@[r32bit]ignore-bitwidth: 64 +//@[r64bit]ignore-bitwidth: 32 //@no-rustfix #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] @@ -14,8 +14,8 @@ fn test_function_to_numeric_cast() { let _ = foo as i16; //~^ fn_to_numeric_cast_with_truncation let _ = foo as i32; - //~[64bit]^ fn_to_numeric_cast_with_truncation - //~[32bit]^^ fn_to_numeric_cast + //~[r64bit]^ fn_to_numeric_cast_with_truncation + //~[r32bit]^^ fn_to_numeric_cast let _ = foo as i64; //~^ fn_to_numeric_cast let _ = foo as i128; @@ -28,8 +28,8 @@ fn test_function_to_numeric_cast() { let _ = foo as u16; //~^ fn_to_numeric_cast_with_truncation let _ = foo as u32; - //~[64bit]^ fn_to_numeric_cast_with_truncation - //~[32bit]^^ fn_to_numeric_cast + //~[r64bit]^ fn_to_numeric_cast_with_truncation + //~[r32bit]^^ fn_to_numeric_cast let _ = foo as u64; //~^ fn_to_numeric_cast let _ = foo as u128; @@ -51,8 +51,8 @@ fn test_function_var_to_numeric_cast() { let _ = abc as i16; //~^ fn_to_numeric_cast_with_truncation let _ = abc as i32; - //~[64bit]^ fn_to_numeric_cast_with_truncation - //~[32bit]^^ fn_to_numeric_cast + //~[r64bit]^ fn_to_numeric_cast_with_truncation + //~[r32bit]^^ fn_to_numeric_cast let _ = abc as i64; //~^ fn_to_numeric_cast let _ = abc as i128; @@ -65,8 +65,8 @@ fn test_function_var_to_numeric_cast() { let _ = abc as u16; //~^ fn_to_numeric_cast_with_truncation let _ = abc as u32; - //~[64bit]^ fn_to_numeric_cast_with_truncation - //~[32bit]^^ fn_to_numeric_cast + //~[r64bit]^ fn_to_numeric_cast_with_truncation + //~[r32bit]^^ fn_to_numeric_cast let _ = abc as u64; //~^ fn_to_numeric_cast let _ = abc as u128; @@ -78,8 +78,8 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 - //~[64bit]^ fn_to_numeric_cast_with_truncation - //~[32bit]^^ fn_to_numeric_cast + //~[r64bit]^ fn_to_numeric_cast_with_truncation + //~[r32bit]^^ fn_to_numeric_cast } fn main() {} diff --git a/src/tools/clippy/tests/ui/large_enum_variant.32bit.stderr b/src/tools/clippy/tests/ui/large_enum_variant.r32bit.stderr similarity index 100% rename from src/tools/clippy/tests/ui/large_enum_variant.32bit.stderr rename to src/tools/clippy/tests/ui/large_enum_variant.r32bit.stderr diff --git a/src/tools/clippy/tests/ui/large_enum_variant.64bit.stderr b/src/tools/clippy/tests/ui/large_enum_variant.r64bit.stderr similarity index 100% rename from src/tools/clippy/tests/ui/large_enum_variant.64bit.stderr rename to src/tools/clippy/tests/ui/large_enum_variant.r64bit.stderr diff --git a/src/tools/clippy/tests/ui/large_enum_variant.rs b/src/tools/clippy/tests/ui/large_enum_variant.rs index 9cf6318ca342b..43c19d6486269 100644 --- a/src/tools/clippy/tests/ui/large_enum_variant.rs +++ b/src/tools/clippy/tests/ui/large_enum_variant.rs @@ -1,8 +1,8 @@ -//@revisions: 32bit 64bit +//@revisions: r32bit r64bit //@aux-build:proc_macros.rs //@no-rustfix -//@[32bit]ignore-bitwidth: 64 -//@[64bit]ignore-bitwidth: 32 +//@[r32bit]ignore-bitwidth: 64 +//@[r64bit]ignore-bitwidth: 32 #![allow(dead_code)] #![allow(unused_variables)] #![warn(clippy::large_enum_variant)] @@ -221,13 +221,13 @@ mod issue11915 { } enum NoWarnings { - //~[64bit]^ large_enum_variant + //~[r64bit]^ large_enum_variant BigBoi(PublishWithBytes), _SmallBoi(u8), } enum MakesClippyAngry { - //~[64bit]^ large_enum_variant + //~[r64bit]^ large_enum_variant BigBoi(PublishWithVec), _SmallBoi(u8), } From 841ed1a542afac1b7a9079f84db4b20505ec0e50 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Mon, 20 Oct 2025 23:20:56 +0800 Subject: [PATCH 4/6] Cancel errors during interface::parse_cfg/parse_check_cfg --- compiler/rustc_interface/src/interface.rs | 11 +++++------ .../multiline-args-value/cfg-frontmatter.stderr | 6 ------ .../run-make/multiline-args-value/cfg-shebang.stderr | 5 ----- .../multiline-args-value/check-cfg-frontmatter.stderr | 6 ------ .../multiline-args-value/check-cfg-shebang.stderr | 5 ----- .../cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr | 4 ---- .../cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr | 4 ---- .../path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr | 4 ---- ...kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr | 4 ---- ...-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr | 4 ---- ...cfg-pred-cli-check-cfg.check_cfg_underscore.stderr | 4 ---- .../check-cfg/invalid-arguments.anything_else.stderr | 4 ---- tests/ui/check-cfg/invalid-arguments.giberich.stderr | 4 ---- .../ui/check-cfg/invalid-arguments.unsafe_attr.stderr | 4 ---- .../check-cfg/invalid-arguments.unterminated.stderr | 4 ---- .../conditional-compilation/cfg-arg-invalid-1.stderr | 4 ---- .../conditional-compilation/cfg-arg-invalid-6.stderr | 4 ---- .../conditional-compilation/cfg-arg-invalid-8.stderr | 4 ---- .../conditional-compilation/cfg-arg-invalid-9.stderr | 4 ---- .../conditional-compilation/cfg-empty-codemap.stderr | 4 ---- 20 files changed, 5 insertions(+), 88 deletions(-) diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 141e6ead838a4..e94979d08061c 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -97,12 +97,12 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { } Ok(..) => {} Err(err) => { - err.emit(); + err.cancel(); }, } }, Err(errs) => errs.into_iter().for_each(|err| { - err.emit(); + err.cancel(); }), }; @@ -184,21 +184,20 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch let mut parser = match new_parser_from_source_str(&psess, filename, s.to_string(), StripTokens::Nothing) { - Ok(parser) => parser, + Ok(parser) => parser.recovery(Recovery::Forbidden), Err(errs) => { errs.into_iter().for_each(|err| { - err.emit(); + err.cancel(); }); expected_error(); } }; - parser = parser.recovery(Recovery::Forbidden); let meta_item = match parser.parse_meta_item(AllowLeadingUnsafe::No) { Ok(meta_item) if parser.token == token::Eof => meta_item, Ok(..) => expected_error(), Err(err) => { - err.emit(); + err.cancel(); expected_error(); } }; diff --git a/tests/run-make/multiline-args-value/cfg-frontmatter.stderr b/tests/run-make/multiline-args-value/cfg-frontmatter.stderr index 6acf5fbb7d9f4..9b06f84be4884 100644 --- a/tests/run-make/multiline-args-value/cfg-frontmatter.stderr +++ b/tests/run-make/multiline-args-value/cfg-frontmatter.stderr @@ -1,9 +1,3 @@ -error: expected identifier, found `-` - | - = note: this error occurred on the command line: `--cfg=--- - --- - key` - error: invalid `--cfg` argument: `--- --- key` (expected `key` or `key="value"`) diff --git a/tests/run-make/multiline-args-value/cfg-shebang.stderr b/tests/run-make/multiline-args-value/cfg-shebang.stderr index 5da3cb552305b..09baf3b51239c 100644 --- a/tests/run-make/multiline-args-value/cfg-shebang.stderr +++ b/tests/run-make/multiline-args-value/cfg-shebang.stderr @@ -1,8 +1,3 @@ -error: expected identifier, found `#` - | - = note: this error occurred on the command line: `--cfg=#!/usr/bin/shebang - key` - error: invalid `--cfg` argument: `#!/usr/bin/shebang key` (expected `key` or `key="value"`) diff --git a/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr b/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr index d9cd830aab5d7..4a499cc0a1e24 100644 --- a/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr +++ b/tests/run-make/multiline-args-value/check-cfg-frontmatter.stderr @@ -1,9 +1,3 @@ -error: expected identifier, found `-` - | - = note: this error occurred on the command line: `--check-cfg=--- - --- - cfg(key)` - error: invalid `--check-cfg` argument: `--- --- cfg(key)` diff --git a/tests/run-make/multiline-args-value/check-cfg-shebang.stderr b/tests/run-make/multiline-args-value/check-cfg-shebang.stderr index 2caead5f4e05e..5bf18dc2b14c4 100644 --- a/tests/run-make/multiline-args-value/check-cfg-shebang.stderr +++ b/tests/run-make/multiline-args-value/check-cfg-shebang.stderr @@ -1,8 +1,3 @@ -error: expected identifier, found `#` - | - = note: this error occurred on the command line: `--check-cfg=#!/usr/bin/shebang - cfg(key)` - error: invalid `--check-cfg` argument: `#!/usr/bin/shebang cfg(key)` | diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr index 11fe76ca3e916..5fd341485cd99 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_priv.stderr @@ -1,6 +1,2 @@ -error: expected identifier, found reserved keyword `priv` - | - = note: this error occurred on the command line: `--cfg=priv` - error: invalid `--cfg` argument: `priv` (expected `key` or `key="value"`) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr index cb80272aa7c9f..5ee3f35ae0cfe 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_struct.stderr @@ -1,6 +1,2 @@ -error: expected identifier, found keyword `struct` - | - = note: this error occurred on the command line: `--cfg=struct` - error: invalid `--cfg` argument: `struct` (expected `key` or `key="value"`) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr index 55caf707954a3..4dfb3f8276469 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr @@ -1,6 +1,2 @@ -error: expected identifier, found reserved identifier `_` - | - = note: this error occurred on the command line: `--cfg=_` - error: invalid `--cfg` argument: `_` (expected `key` or `key="value"`) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr index 7832e0c9eab7a..2165d37500a91 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr @@ -1,7 +1,3 @@ -error: expected unsuffixed literal, found reserved keyword `priv` - | - = note: this error occurred on the command line: `--check-cfg=cfg(priv)` - error: invalid `--check-cfg` argument: `cfg(priv)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr index 1bbc8187d2718..40942a955bf92 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr @@ -1,7 +1,3 @@ -error: expected unsuffixed literal, found keyword `struct` - | - = note: this error occurred on the command line: `--check-cfg=cfg(struct)` - error: invalid `--check-cfg` argument: `cfg(struct)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr index 1fbbc51ada87f..98a645f039a51 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr @@ -1,7 +1,3 @@ -error: expected unsuffixed literal, found reserved identifier `_` - | - = note: this error occurred on the command line: `--check-cfg=cfg(_)` - error: invalid `--check-cfg` argument: `cfg(_)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.anything_else.stderr b/tests/ui/check-cfg/invalid-arguments.anything_else.stderr index 62bfe9a2e6f6f..f3bc0b782e22f 100644 --- a/tests/ui/check-cfg/invalid-arguments.anything_else.stderr +++ b/tests/ui/check-cfg/invalid-arguments.anything_else.stderr @@ -1,7 +1,3 @@ -error: expected unsuffixed literal, found `...` - | - = note: this error occurred on the command line: `--check-cfg=anything_else(...)` - error: invalid `--check-cfg` argument: `anything_else(...)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.giberich.stderr b/tests/ui/check-cfg/invalid-arguments.giberich.stderr index b9adace399a80..3e35014549183 100644 --- a/tests/ui/check-cfg/invalid-arguments.giberich.stderr +++ b/tests/ui/check-cfg/invalid-arguments.giberich.stderr @@ -1,7 +1,3 @@ -error: expected unsuffixed literal, found `...` - | - = note: this error occurred on the command line: `--check-cfg=cfg(...)` - error: invalid `--check-cfg` argument: `cfg(...)` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr b/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr index d56a48028331b..5236ed6f60547 100644 --- a/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr +++ b/tests/ui/check-cfg/invalid-arguments.unsafe_attr.stderr @@ -1,7 +1,3 @@ -error: expected identifier, found keyword `unsafe` - | - = note: this error occurred on the command line: `--check-cfg=unsafe(cfg(foo))` - error: invalid `--check-cfg` argument: `unsafe(cfg(foo))` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/check-cfg/invalid-arguments.unterminated.stderr b/tests/ui/check-cfg/invalid-arguments.unterminated.stderr index d2db65b960c04..150e1d66426b9 100644 --- a/tests/ui/check-cfg/invalid-arguments.unterminated.stderr +++ b/tests/ui/check-cfg/invalid-arguments.unterminated.stderr @@ -1,7 +1,3 @@ -error: this file contains an unclosed delimiter - | - = note: this error occurred on the command line: `--check-cfg=cfg(` - error: invalid `--check-cfg` argument: `cfg(` | = note: expected `cfg(name, values("value1", "value2", ... "valueN"))` diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr index 6fb2f01ec896c..3a12e97868000 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr @@ -1,6 +1,2 @@ -error: expected unsuffixed literal, found `c` - | - = note: this error occurred on the command line: `--cfg=a(b=c)` - error: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\") diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr index 542d573791ad3..7d2087b4b71f7 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr @@ -1,6 +1,2 @@ -error: this file contains an unclosed delimiter - | - = note: this error occurred on the command line: `--cfg=a{` - error: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`) diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr index 0d8db852f04c2..7bb1814127b29 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr @@ -1,6 +1,2 @@ -error: unexpected closing delimiter: `)` - | - = note: this error occurred on the command line: `--cfg=)` - error: invalid `--cfg` argument: `)` (expected `key` or `key="value"`) diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr index db6ee40552865..985b525225839 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr @@ -1,6 +1,2 @@ -error: unexpected token: `value` - | - = note: this error occurred on the command line: `--cfg=key=value` - error: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\") diff --git a/tests/ui/conditional-compilation/cfg-empty-codemap.stderr b/tests/ui/conditional-compilation/cfg-empty-codemap.stderr index fbf58ceed52a3..128e3cd730680 100644 --- a/tests/ui/conditional-compilation/cfg-empty-codemap.stderr +++ b/tests/ui/conditional-compilation/cfg-empty-codemap.stderr @@ -1,6 +1,2 @@ -error: expected identifier, found `""` - | - = note: this error occurred on the command line: `--cfg=""` - error: invalid `--cfg` argument: `""` (expected `key` or `key="value"`) From 91fdcb2ade0f2678f92476501a524b560a87d512 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Tue, 21 Oct 2025 00:06:31 +0800 Subject: [PATCH 5/6] Use EmitterWithNote and allow warnings, adjust wording for --cfg/--check-cfg error --- compiler/rustc_errors/src/emitter.rs | 20 +++++++--------- compiler/rustc_interface/src/interface.rs | 24 +++++++------------ compiler/rustc_session/src/parse.rs | 7 +++--- ...th-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr | 2 +- ...w-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr | 4 ++-- ...cfg-pred-cli-cfg.cfg_raw_self_lower.stderr | 4 ++-- ...cfg-pred-cli-cfg.cfg_raw_self_upper.stderr | 4 ++-- ...w-as-cfg-pred-cli-cfg.cfg_raw_super.stderr | 4 ++-- ...cfg-pred-cli-cfg.cfg_raw_underscore.stderr | 4 ++-- ...-as-cfg-pred-cli-cfg.cfg_self_lower.stderr | 2 +- ...-as-cfg-pred-cli-cfg.cfg_self_upper.stderr | 2 +- ...th-kw-as-cfg-pred-cli-cfg.cfg_super.stderr | 2 +- ...-pred-cli-check-cfg.check_cfg_crate.stderr | 2 +- ...d-cli-check-cfg.check_cfg_raw_crate.stderr | 4 ++-- ...-check-cfg.check_cfg_raw_self_lower.stderr | 4 ++-- ...-check-cfg.check_cfg_raw_self_upper.stderr | 4 ++-- ...d-cli-check-cfg.check_cfg_raw_super.stderr | 4 ++-- ...-check-cfg.check_cfg_raw_underscore.stderr | 4 ++-- ...-cli-check-cfg.check_cfg_self_lower.stderr | 2 +- ...-cli-check-cfg.check_cfg_self_upper.stderr | 2 +- ...-pred-cli-check-cfg.check_cfg_super.stderr | 2 +- .../cfg-arg-invalid-7.rs | 2 +- .../cfg-arg-invalid-7.stderr | 2 +- 23 files changed, 50 insertions(+), 61 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 8b3e85e3ca680..06a896439918c 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -534,28 +534,24 @@ impl Emitter for HumanEmitter { } } -/// An emitter that does nothing when emitting a non-error diagnostic. -/// Error diagnostics are forwarded to `error_emitter` to avoid silent -/// failures of rustc, as witnessed e.g. in issue #89358. -pub struct ErrorOnlyEmitter { - pub error_emitter: Box, - pub error_note: String, +/// An emitter that adds a note to each diagnostic. +pub struct EmitterWithNote { + pub emitter: Box, + pub note: String, } -impl Emitter for ErrorOnlyEmitter { +impl Emitter for EmitterWithNote { fn source_map(&self) -> Option<&SourceMap> { None } fn emit_diagnostic(&mut self, mut diag: DiagInner, registry: &Registry) { - if diag.is_error() { - diag.sub(Level::Note, self.error_note.clone(), MultiSpan::new()); - self.error_emitter.emit_diagnostic(diag, registry); - } + diag.sub(Level::Note, self.note.clone(), MultiSpan::new()); + self.emitter.emit_diagnostic(diag, registry); } fn translator(&self) -> &Translator { - self.error_emitter.translator() + self.emitter.translator() } } diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index e94979d08061c..b6794346a124e 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -53,9 +53,9 @@ pub struct Compiler { pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { cfgs.into_iter() .map(|s| { - let psess = ParseSess::with_error_emitter( + let psess = ParseSess::emitter_with_note( vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], - format!("this error occurred on the command line: `--cfg={s}`"), + format!("this occurred on the command line: `--cfg={s}`"), ); let filename = FileName::cfg_spec_source_code(&s); @@ -63,10 +63,7 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { ($reason: expr) => { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - dcx.fatal(format!( - "invalid `--cfg` argument: `{}` ({})", - s, $reason, - )); + dcx.fatal(format!("invalid `--cfg` argument: `{}` ({})", s, $reason,)); }; } @@ -88,7 +85,7 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { let ident = meta_item.ident().expect("multi-segment cfg key"); if !ident.name.can_be_raw() { - error!(format!("argument key must be an identifier, but `{}` cannot be a raw identifier", ident.name)); + error!("argument key must be an identifier"); } return (ident.name, meta_item.value_str()); @@ -98,9 +95,9 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { Ok(..) => {} Err(err) => { err.cancel(); - }, + } } - }, + } Err(errs) => errs.into_iter().for_each(|err| { err.cancel(); }), @@ -129,9 +126,9 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() }; for s in specs { - let psess = ParseSess::with_error_emitter( + let psess = ParseSess::emitter_with_note( vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], - format!("this error occurred on the command line: `--check-cfg={s}`"), + format!("this occurred on the command line: `--check-cfg={s}`"), ); let filename = FileName::cfg_spec_source_code(&s); @@ -226,10 +223,7 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch } if !ident.name.can_be_raw() { - error!(format!( - "argument key must be an identifier, but `{}` cannot be a raw identifier", - ident.name - )); + error!("`cfg()` names must be identifiers"); } names.push(ident); diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index ce71e414ed798..8c70e18fb66dd 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -8,7 +8,7 @@ use rustc_ast::attr::AttrIdGenerator; use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::sync::{AppendOnlyVec, Lock}; -use rustc_errors::emitter::{ErrorOnlyEmitter, HumanEmitter, stderr_destination}; +use rustc_errors::emitter::{EmitterWithNote, HumanEmitter, stderr_destination}; use rustc_errors::translation::Translator; use rustc_errors::{ BufferedEarlyLint, ColorConfig, DecorateDiagCompat, Diag, DiagCtxt, DiagCtxtHandle, @@ -315,13 +315,12 @@ impl ParseSess { } } - pub fn with_error_emitter(locale_resources: Vec<&'static str>, error_note: String) -> Self { + pub fn emitter_with_note(locale_resources: Vec<&'static str>, note: String) -> Self { let translator = Translator::with_fallback_bundle(locale_resources, false); let sm = Arc::new(SourceMap::new(FilePathMapping::empty())); let emitter = Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), translator)); - let dcx = DiagCtxt::new(Box::new(ErrorOnlyEmitter { error_emitter: emitter, error_note })) - .disable_warnings(); + let dcx = DiagCtxt::new(Box::new(EmitterWithNote { emitter, note })); ParseSess::with_dcx(dcx, sm) } diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr index 56eb3b0b67dc2..c0a9c57c8e0f6 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `crate` (argument key must be an identifier, but `crate` cannot be a raw identifier) +error: invalid `--cfg` argument: `crate` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr index 910c27cd797bb..95a7fcc8cabc4 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr @@ -1,6 +1,6 @@ error: `crate` cannot be a raw identifier | - = note: this error occurred on the command line: `--cfg=r#crate` + = note: this occurred on the command line: `--cfg=r#crate` -error: invalid `--cfg` argument: `r#crate` (argument key must be an identifier, but `crate` cannot be a raw identifier) +error: invalid `--cfg` argument: `r#crate` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr index 2260f4e2f11a4..ca6b06c6e5b1b 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr @@ -1,6 +1,6 @@ error: `self` cannot be a raw identifier | - = note: this error occurred on the command line: `--cfg=r#self` + = note: this occurred on the command line: `--cfg=r#self` -error: invalid `--cfg` argument: `r#self` (argument key must be an identifier, but `self` cannot be a raw identifier) +error: invalid `--cfg` argument: `r#self` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr index f40498023f9f6..0d967bacc0b6b 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr @@ -1,6 +1,6 @@ error: `Self` cannot be a raw identifier | - = note: this error occurred on the command line: `--cfg=r#Self` + = note: this occurred on the command line: `--cfg=r#Self` -error: invalid `--cfg` argument: `r#Self` (argument key must be an identifier, but `Self` cannot be a raw identifier) +error: invalid `--cfg` argument: `r#Self` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr index 0d8bb0269f0f3..8c867845035e7 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr @@ -1,6 +1,6 @@ error: `super` cannot be a raw identifier | - = note: this error occurred on the command line: `--cfg=r#super` + = note: this occurred on the command line: `--cfg=r#super` -error: invalid `--cfg` argument: `r#super` (argument key must be an identifier, but `super` cannot be a raw identifier) +error: invalid `--cfg` argument: `r#super` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr index a5fc16149500f..43370e80dea22 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr @@ -1,6 +1,6 @@ error: `_` cannot be a raw identifier | - = note: this error occurred on the command line: `--cfg=r#_` + = note: this occurred on the command line: `--cfg=r#_` -error: invalid `--cfg` argument: `r#_` (argument key must be an identifier, but `_` cannot be a raw identifier) +error: invalid `--cfg` argument: `r#_` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr index e4c855f145aad..59fa823611584 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `self` (argument key must be an identifier, but `self` cannot be a raw identifier) +error: invalid `--cfg` argument: `self` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr index 383b42949d56e..e611fdd554e65 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `Self` (argument key must be an identifier, but `Self` cannot be a raw identifier) +error: invalid `--cfg` argument: `Self` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr index 630c8f78a7898..3796621664f14 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `super` (argument key must be an identifier, but `super` cannot be a raw identifier) +error: invalid `--cfg` argument: `super` (argument key must be an identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr index 55e94f26e7bd7..4d26558484db5 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(crate)` | - = note: argument key must be an identifier, but `crate` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr index 3f2a66645a86f..caa3cce611dfb 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr @@ -1,9 +1,9 @@ error: `crate` cannot be a raw identifier | - = note: this error occurred on the command line: `--check-cfg=cfg(r#crate)` + = note: this occurred on the command line: `--check-cfg=cfg(r#crate)` error: invalid `--check-cfg` argument: `cfg(r#crate)` | - = note: argument key must be an identifier, but `crate` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr index c29573be4e63a..5ab40997964c2 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr @@ -1,9 +1,9 @@ error: `self` cannot be a raw identifier | - = note: this error occurred on the command line: `--check-cfg=cfg(r#self)` + = note: this occurred on the command line: `--check-cfg=cfg(r#self)` error: invalid `--check-cfg` argument: `cfg(r#self)` | - = note: argument key must be an identifier, but `self` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr index d4104e58c0dbf..300fe2bf83038 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr @@ -1,9 +1,9 @@ error: `Self` cannot be a raw identifier | - = note: this error occurred on the command line: `--check-cfg=cfg(r#Self)` + = note: this occurred on the command line: `--check-cfg=cfg(r#Self)` error: invalid `--check-cfg` argument: `cfg(r#Self)` | - = note: argument key must be an identifier, but `Self` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr index b0f47e92d2480..fc4d17cc8aab2 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr @@ -1,9 +1,9 @@ error: `super` cannot be a raw identifier | - = note: this error occurred on the command line: `--check-cfg=cfg(r#super)` + = note: this occurred on the command line: `--check-cfg=cfg(r#super)` error: invalid `--check-cfg` argument: `cfg(r#super)` | - = note: argument key must be an identifier, but `super` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr index 0c9a307e743b6..3d004bd946d26 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr @@ -1,9 +1,9 @@ error: `_` cannot be a raw identifier | - = note: this error occurred on the command line: `--check-cfg=cfg(r#_)` + = note: this occurred on the command line: `--check-cfg=cfg(r#_)` error: invalid `--check-cfg` argument: `cfg(r#_)` | - = note: argument key must be an identifier, but `_` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr index 30e80662dbcd1..438d526fb1f9f 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(self)` | - = note: argument key must be an identifier, but `self` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr index f1eec929afa69..fe5b3bf184e46 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(Self)` | - = note: argument key must be an identifier, but `Self` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr index aab2d9cf09f7b..fb3fec0de3e87 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(super)` | - = note: argument key must be an identifier, but `super` cannot be a raw identifier + = note: `cfg()` names must be identifiers = note: visit for more details diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs index f05adc7bf7aad..d90075da3e63c 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs @@ -3,4 +3,4 @@ //@ compile-flags: --cfg a" //~? RAW unterminated double quote string -//~? RAW this error occurred on the command line +//~? RAW this occurred on the command line diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr index 919709c847019..833d24a907dc2 100644 --- a/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr +++ b/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr @@ -1,4 +1,4 @@ error[E0765]: unterminated double quote string | - = note: this error occurred on the command line: `--cfg=a"` + = note: this occurred on the command line: `--cfg=a"` From 65b32a4bb973247f4718e8cf009b691ca31e16b7 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Tue, 21 Oct 2025 00:10:44 +0800 Subject: [PATCH 6/6] Adjust wording for --cfg/--check-cfg errors --- compiler/rustc_interface/src/interface.rs | 6 ++++-- tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr | 2 +- .../ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr | 2 +- .../path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr | 2 +- .../path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr | 2 +- .../ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr | 2 +- .../path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr | 2 +- .../cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr | 2 +- .../cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr | 2 +- tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr | 2 +- ...path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr | 2 +- ...-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr | 2 +- ...s-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr | 2 +- ...s-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr | 2 +- ...-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr | 2 +- ...s-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr | 2 +- ...kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr | 2 +- ...kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr | 2 +- ...path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr | 2 +- 19 files changed, 22 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index b6794346a124e..065658c6ea566 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -85,7 +85,9 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec) -> Cfg { let ident = meta_item.ident().expect("multi-segment cfg key"); if !ident.name.can_be_raw() { - error!("argument key must be an identifier"); + error!( + "malformed `cfg` input, expected a valid identifier" + ); } return (ident.name, meta_item.value_str()); @@ -223,7 +225,7 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch } if !ident.name.can_be_raw() { - error!("`cfg()` names must be identifiers"); + error!("malformed `cfg` input, expected a valid identifier"); } names.push(ident); diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr index c0a9c57c8e0f6..daaddd3074160 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_crate.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `crate` (argument key must be an identifier) +error: invalid `--cfg` argument: `crate` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr index 95a7fcc8cabc4..cede4537138b7 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr @@ -2,5 +2,5 @@ error: `crate` cannot be a raw identifier | = note: this occurred on the command line: `--cfg=r#crate` -error: invalid `--cfg` argument: `r#crate` (argument key must be an identifier) +error: invalid `--cfg` argument: `r#crate` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr index ca6b06c6e5b1b..57ce4218fe9c6 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr @@ -2,5 +2,5 @@ error: `self` cannot be a raw identifier | = note: this occurred on the command line: `--cfg=r#self` -error: invalid `--cfg` argument: `r#self` (argument key must be an identifier) +error: invalid `--cfg` argument: `r#self` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr index 0d967bacc0b6b..e594d3f62c9ea 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr @@ -2,5 +2,5 @@ error: `Self` cannot be a raw identifier | = note: this occurred on the command line: `--cfg=r#Self` -error: invalid `--cfg` argument: `r#Self` (argument key must be an identifier) +error: invalid `--cfg` argument: `r#Self` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr index 8c867845035e7..08ac88359a02c 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr @@ -2,5 +2,5 @@ error: `super` cannot be a raw identifier | = note: this occurred on the command line: `--cfg=r#super` -error: invalid `--cfg` argument: `r#super` (argument key must be an identifier) +error: invalid `--cfg` argument: `r#super` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr index 43370e80dea22..f7c204319a36f 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr @@ -2,5 +2,5 @@ error: `_` cannot be a raw identifier | = note: this occurred on the command line: `--cfg=r#_` -error: invalid `--cfg` argument: `r#_` (argument key must be an identifier) +error: invalid `--cfg` argument: `r#_` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr index 59fa823611584..9d7897c48ef46 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_lower.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `self` (argument key must be an identifier) +error: invalid `--cfg` argument: `self` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr index e611fdd554e65..16c91198eea79 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_self_upper.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `Self` (argument key must be an identifier) +error: invalid `--cfg` argument: `Self` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr index 3796621664f14..08513ac466cb7 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_super.stderr @@ -1,2 +1,2 @@ -error: invalid `--cfg` argument: `super` (argument key must be an identifier) +error: invalid `--cfg` argument: `super` (malformed `cfg` input, expected a valid identifier) diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr index 4d26558484db5..69f06cf5e216c 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_crate.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(crate)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr index caa3cce611dfb..6be2c90481dd5 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr @@ -4,6 +4,6 @@ error: `crate` cannot be a raw identifier error: invalid `--check-cfg` argument: `cfg(r#crate)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr index 5ab40997964c2..55bfa012942e3 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr @@ -4,6 +4,6 @@ error: `self` cannot be a raw identifier error: invalid `--check-cfg` argument: `cfg(r#self)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr index 300fe2bf83038..ada7945a7778a 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr @@ -4,6 +4,6 @@ error: `Self` cannot be a raw identifier error: invalid `--check-cfg` argument: `cfg(r#Self)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr index fc4d17cc8aab2..a395e2ce9b157 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr @@ -4,6 +4,6 @@ error: `super` cannot be a raw identifier error: invalid `--check-cfg` argument: `cfg(r#super)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr index 3d004bd946d26..e796f0a2a8f38 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr @@ -4,6 +4,6 @@ error: `_` cannot be a raw identifier error: invalid `--check-cfg` argument: `cfg(r#_)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr index 438d526fb1f9f..b109650d116d4 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_lower.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(self)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr index fe5b3bf184e46..649cde33e159a 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_self_upper.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(Self)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr index fb3fec0de3e87..488d2982e7b80 100644 --- a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_super.stderr @@ -1,5 +1,5 @@ error: invalid `--check-cfg` argument: `cfg(super)` | - = note: `cfg()` names must be identifiers + = note: malformed `cfg` input, expected a valid identifier = note: visit for more details