diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 8f2de4af14e00..0e1c84bb13773 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -118,6 +118,7 @@ impl<'sess> AttributeParser<'sess, Early> { target_node_id: NodeId, features: Option<&'sess Features>, emit_errors: ShouldEmit, + parsing_cfg: bool, parse_fn: fn(cx: &mut AcceptContext<'_, '_, Early>, item: &ArgParser<'_>) -> Option, template: &AttributeTemplate, ) -> Option { @@ -133,7 +134,8 @@ impl<'sess> AttributeParser<'sess, Early> { }; let parts = normal_attr.item.path.segments.iter().map(|seg| seg.ident.name).collect::>(); - let meta_parser = MetaItemParser::from_attr(normal_attr, &parts, &sess.psess, emit_errors)?; + let meta_parser = + MetaItemParser::from_attr(normal_attr, &parts, &sess.psess, emit_errors, parsing_cfg)?; let path = meta_parser.path(); let args = meta_parser.args(); let mut cx: AcceptContext<'_, 'sess, Early> = AcceptContext { @@ -251,6 +253,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> { &parts, &self.sess.psess, self.stage.should_emit(), + false, ) else { continue; }; diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 3f4f567901575..6481118ae1cf9 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -104,6 +104,7 @@ impl<'a> ArgParser<'a> { parts: &[Symbol], psess: &'sess ParseSess, should_emit: ShouldEmit, + parsing_cfg: bool, ) -> Option { Some(match value { AttrArgs::Empty => Self::NoArgs, @@ -124,7 +125,7 @@ impl<'a> ArgParser<'a> { return None; } - Self::List(MetaItemListParser::new(args, psess, should_emit)?) + Self::List(MetaItemListParser::new(args, psess, should_emit, parsing_cfg)?) } AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser { eq_span: *eq_span, @@ -248,10 +249,17 @@ impl<'a> MetaItemParser<'a> { parts: &[Symbol], psess: &'sess ParseSess, should_emit: ShouldEmit, + parsing_cfg: bool, ) -> Option { Some(Self { path: PathParser(Cow::Borrowed(&attr.item.path)), - args: ArgParser::from_attr_args(&attr.item.args, parts, psess, should_emit)?, + args: ArgParser::from_attr_args( + &attr.item.args, + parts, + psess, + should_emit, + parsing_cfg, + )?, }) } } @@ -425,7 +433,13 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> { }; } - let path = self.parser.parse_path(PathStyle::Mod)?; + let path = if self.parser.parse_cfg_pred { + let path = self.parser.parse_path(PathStyle::CfgPred)?; + self.parser.parse_cfg_pred = false; + path + } else { + self.parser.parse_path(PathStyle::Mod)? + }; // Check style of arguments that this meta item has let args = if self.parser.check(exp!(OpenParen)) { @@ -513,8 +527,11 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> { psess: &'sess ParseSess, span: Span, should_emit: ShouldEmit, + parsing_cfg: bool, ) -> PResult<'sess, MetaItemListParser<'static>> { let mut parser = Parser::new(psess, tokens, None); + parser.parse_cfg_pred = parsing_cfg; + let mut this = MetaItemListParserContext { parser: &mut parser, should_emit }; // Presumably, the majority of the time there will only be one attr. @@ -546,12 +563,14 @@ impl<'a> MetaItemListParser<'a> { delim: &'a DelimArgs, psess: &'sess ParseSess, should_emit: ShouldEmit, + parsing_cfg: bool, ) -> Option { match MetaItemListParserContext::parse( delim.tokens.clone(), psess, delim.dspan.entire(), should_emit, + parsing_cfg, ) { Ok(s) => Some(s), Err(e) => { diff --git a/compiler/rustc_builtin_macros/src/cfg.rs b/compiler/rustc_builtin_macros/src/cfg.rs index 85b8ef79c0504..2427baa8161e8 100644 --- a/compiler/rustc_builtin_macros/src/cfg.rs +++ b/compiler/rustc_builtin_macros/src/cfg.rs @@ -42,6 +42,7 @@ fn parse_cfg<'a>( tts: TokenStream, ) -> PResult<'a, ast::MetaItemInner> { let mut p = cx.new_parser_from_tts(tts); + p.parse_cfg_pred = true; if p.token == token::Eof { return Err(cx.dcx().create_err(errors::RequiresCfgPattern { span })); diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 2925e337071ca..f568c260002d3 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -428,6 +428,7 @@ impl<'a> StripUnconfigured<'a> { node, self.features, emit_errors, + true, parse_cfg_attr, &CFG_TEMPLATE, ) else { 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/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index acd338156ce88..5db117c79c25a 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -381,6 +381,7 @@ impl<'a> Parser<'a> { pub fn parse_cfg_attr( &mut self, ) -> PResult<'a, (ast::MetaItemInner, Vec<(ast::AttrItem, Span)>)> { + self.parse_cfg_pred = true; let cfg_predicate = self.parse_meta_item_inner()?; self.expect(exp!(Comma))?; @@ -449,7 +450,14 @@ impl<'a> Parser<'a> { ast::Safety::Default }; - let path = self.parse_path(PathStyle::Mod)?; + let path = if self.parse_cfg_pred { + let path = self.parse_path(PathStyle::CfgPred)?; + self.parse_cfg_pred = false; + path + } else { + self.parse_path(PathStyle::Mod)? + }; + let kind = self.parse_meta_item_kind()?; if is_unsafe { self.expect(exp!(CloseParen))?; diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index ed4069dae933c..8d33e32b89d35 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -181,6 +181,7 @@ pub struct Parser<'a> { /// The previous token. pub prev_token: Token, pub capture_cfg: bool, + pub parse_cfg_pred: bool, restrictions: Restrictions, expected_token_types: TokenTypeSet, token_cursor: TokenCursor, @@ -372,6 +373,7 @@ impl<'a> Parser<'a> { }, current_closure: None, recovery: Recovery::Allowed, + parse_cfg_pred: false, }; // Make parser point to the first token. diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index f7757921cd426..472af33539b7d 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -57,6 +57,8 @@ pub enum PathStyle { /// anyway, due to macros), but it is used to avoid weird suggestions about expected /// tokens when something goes wrong. Mod, + /// Disallow path segment keywords when parsing cfg preds + CfgPred, } impl PathStyle { @@ -299,7 +301,12 @@ impl<'a> Parser<'a> { style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, PathSegment> { - let ident = self.parse_path_segment_ident()?; + let ident = if style == PathStyle::CfgPred { + self.parse_ident()? + } else { + self.parse_path_segment_ident()? + }; + let is_args_start = |token: &Token| { matches!(token.kind, token::Lt | token::Shl | token::OpenParen | token::LArrow) }; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 71b0f408b5d88..df848f70e80d3 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -3048,7 +3048,7 @@ impl Symbol { self == kw::True || self == kw::False } - /// Returns `true` if this symbol can be a raw identifier. + /// Returns `true` if this symbol can be a raw identifier in path segment. pub fn can_be_raw(self) -> bool { self != sym::empty && self != kw::Underscore && !self.is_path_segment_keyword() } 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_async.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_async.stderr new file mode 100644 index 0000000000000..45ba2e029f8a0 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_async.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `async` (argument key must be an identifier but found keyword `async`, escape it using `r#async`) + 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_enum.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_enum.stderr new file mode 100644 index 0000000000000..f789a9cd102f4 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_enum.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `enum` (argument key must be an identifier but found keyword `enum`, escape it using `r#enum`) + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_impl.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_impl.stderr new file mode 100644 index 0000000000000..288866228094e --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_impl.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `impl` (argument key must be an identifier but found keyword `impl`, escape it using `r#impl`) + 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_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_trait.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_trait.stderr new file mode 100644 index 0000000000000..0d54f805d3d06 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_trait.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `trait` (argument key must be an identifier but found keyword `trait`, escape it using `r#trait`) + 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..2a4137ed759ca --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.rs @@ -0,0 +1,26 @@ +//@ edition: 2024 +//@ check-fail + +//@ revisions: cfg_crate cfg_super cfg_self_lower cfg_self_upper +//@ revisions: cfg_struct cfg_enum cfg_async cfg_impl cfg_trait +//@ revisions: cfg_raw_crate cfg_raw_super cfg_raw_self_lower cfg_raw_self_upper + +//@ [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_struct]compile-flags: --cfg struct +//@ [cfg_enum]compile-flags: --cfg enum +//@ [cfg_async]compile-flags: --cfg async +//@ [cfg_impl]compile-flags: --cfg impl +//@ [cfg_trait]compile-flags: --cfg trait + +//@ [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 + +fn main() {} + +//~? ERROR invalid `--cfg` argument diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_async.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_async.stderr new file mode 100644 index 0000000000000..00ca91e6e004b --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_async.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(async)` + | + = note: argument key must be an identifier but found keyword `async`, escape it using `r#async` + = note: visit for more details + 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_enum.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_enum.stderr new file mode 100644 index 0000000000000..cfab185b79234 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_enum.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(enum)` + | + = note: argument key must be an identifier but found keyword `enum`, escape it using `r#enum` + = note: visit for more details + diff --git a/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_impl.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_impl.stderr new file mode 100644 index 0000000000000..4a86ffb55ad43 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_impl.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(impl)` + | + = note: argument key must be an identifier but found keyword `impl`, escape it using `r#impl` + = 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_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_trait.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_trait.stderr new file mode 100644 index 0000000000000..10b98115e73e6 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_trait.stderr @@ -0,0 +1,5 @@ +error: invalid `--check-cfg` argument: `cfg(trait)` + | + = note: argument key must be an identifier but found keyword `trait`, escape it using `r#trait` + = 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..275794c26bf8e --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs @@ -0,0 +1,27 @@ +//@ edition: 2024 +//@ check-fail + +//@ revisions: check_cfg_crate check_cfg_super check_cfg_self_lower check_cfg_self_upper +//@ revisions: check_cfg_struct check_cfg_enum check_cfg_async check_cfg_impl check_cfg_trait +//@ revisions: check_cfg_raw_crate check_cfg_raw_super check_cfg_raw_self_lower +//@ revisions: check_cfg_raw_self_upper + +//@ [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_struct]compile-flags: --check-cfg 'cfg(struct)' +//@ [check_cfg_enum]compile-flags: --check-cfg 'cfg(enum)' +//@ [check_cfg_async]compile-flags: --check-cfg 'cfg(async)' +//@ [check_cfg_impl]compile-flags: --check-cfg 'cfg(impl)' +//@ [check_cfg_trait]compile-flags: --check-cfg 'cfg(trait)' + +//@ [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)' + +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..fbfb9914aac36 --- /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#enum --cfg r#async --cfg r#impl --cfg r#trait +//@ compile-flags: --check-cfg 'cfg(r#struct)' --check-cfg 'cfg(r#enum)' --check-cfg 'cfg(r#async)' --check-cfg 'cfg(r#impl)' --check-cfg 'cfg(r#trait)' + +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..3f929556b5a8a --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred.rs @@ -0,0 +1,140 @@ +//@ edition: 2024 + +#![allow(unexpected_cfgs)] + +macro_rules! foo { + () => { + #[cfg($crate)] //~ ERROR expected identifier, found reserved identifier `$crate` + mod _cfg_dollar_crate {} + #[cfg_attr($crate, path = "foo")] //~ ERROR expected identifier, found reserved identifier `$crate` + mod _cfg_attr_dollar_crate {} + #[cfg_attr(true, cfg($crate))] //~ ERROR expected identifier, found reserved identifier `$crate` + mod _cfg_attr_true_cfg_crate {} + + cfg!($crate); //~ ERROR expected identifier, found reserved identifier `$crate` + }; +} + +#[cfg(crate)] //~ ERROR expected identifier, found keyword `crate` +mod _cfg_crate {} +#[cfg(super)] //~ ERROR expected identifier, found keyword `super` +mod _cfg_super {} +#[cfg(self)] //~ ERROR expected identifier, found keyword `self` +mod _cfg_self_lower {} +#[cfg(Self)] //~ ERROR expected identifier, found keyword `Self` +mod _cfg_self_upper {} +#[cfg_attr(crate, path = "foo")] //~ ERROR expected identifier, found keyword `crate` +mod _cfg_attr_crate {} +#[cfg_attr(super, path = "foo")] //~ ERROR expected identifier, found keyword `super` +mod _cfg_attr_super {} +#[cfg_attr(self, path = "foo")] //~ ERROR expected identifier, found keyword `self` +mod _cfg_attr_self_lower {} +#[cfg_attr(Self, path = "foo")] //~ ERROR expected identifier, found keyword `Self` +mod _cfg_attr_self_upper {} +#[cfg_attr(true, cfg(crate))] //~ ERROR expected identifier, found keyword `crate` +mod _cfg_attr_true_cfg_crate {} +#[cfg_attr(true, cfg(super))] //~ ERROR expected identifier, found keyword `super` +mod _cfg_attr_true_cfg_super {} +#[cfg_attr(true, cfg(self))] //~ ERROR expected identifier, found keyword `self` +mod _cfg_attr_true_cfg_self_lower {} +#[cfg_attr(true, cfg(Self))] //~ ERROR expected identifier, found keyword `Self` +mod _cfg_attr_true_cfg_self_upper {} + +#[cfg(struct)] //~ ERROR expected identifier, found keyword +mod _cfg_struct {} +#[cfg(enum)] //~ ERROR expected identifier, found keyword +mod _cfg_enum {} +#[cfg(async)] //~ ERROR expected identifier, found keyword +mod _cfg_async {} +#[cfg(impl)] //~ ERROR expected identifier, found keyword +mod _cfg_impl {} +#[cfg(trait)] //~ ERROR expected identifier, found keyword +mod _cfg_trait {} +#[cfg_attr(struct, path = "foo")] //~ ERROR expected identifier, found keyword +mod _cfg_attr_struct {} +#[cfg_attr(enum, path = "foo")] //~ ERROR expected identifier, found keyword +mod _cfg_attr_enum {} +#[cfg_attr(async, path = "foo")] //~ ERROR expected identifier, found keyword +mod _cfg_attr_async {} +#[cfg_attr(impl, path = "foo")] //~ ERROR expected identifier, found keyword +mod _cfg_attr_impl {} +#[cfg_attr(trait, path = "foo")] //~ ERROR expected identifier, found keyword +mod _cfg_attr_trait {} +#[cfg_attr(true, cfg(struct))] //~ ERROR expected identifier, found keyword +mod _cfg_attr_true_cfg_struct {} +#[cfg_attr(true, cfg(enum))] //~ ERROR expected identifier, found keyword +mod _cfg_attr_true_cfg_enum {} +#[cfg_attr(true, cfg(async))] //~ ERROR expected identifier, found keyword +mod _cfg_attr_true_cfg_async {} +#[cfg_attr(true, cfg(impl))] //~ ERROR expected identifier, found keyword +mod _cfg_attr_true_cfg_impl {} +#[cfg_attr(true, cfg(trait))] //~ ERROR expected identifier, found keyword +mod _cfg_attr_true_cfg_trait {} + +fn main() { + foo!(); + + cfg!(crate); //~ ERROR expected identifier, found keyword `crate` + cfg!(super); //~ ERROR expected identifier, found keyword `super` + cfg!(self); //~ ERROR expected identifier, found keyword `self` + cfg!(Self); //~ ERROR expected identifier, found keyword `Self` + + cfg!(struct); //~ ERROR expected identifier, found keyword + cfg!(enum); //~ ERROR expected identifier, found keyword + cfg!(async); //~ ERROR expected identifier, found keyword + cfg!(impl); //~ ERROR expected identifier, found keyword + cfg!(trait); //~ ERROR expected identifier, found keyword + + cfg!(r#crate); //~ ERROR `crate` cannot be a raw identifier + cfg!(r#super); //~ ERROR `super` cannot be a raw identifier + cfg!(r#self); //~ ERROR `self` cannot be a raw identifier + cfg!(r#Self); //~ ERROR `Self` cannot be a raw identifier + + cfg!(r#struct); // Ok + cfg!(r#enum); // Ok + cfg!(r#async); // Ok + cfg!(r#impl); // Ok + cfg!(r#trait); // Ok +} + +#[cfg(r#crate)] //~ ERROR `crate` cannot be a raw identifier +mod _cfg_r_crate {} +#[cfg(r#super)] //~ ERROR `super` cannot be a raw identifier +mod _cfg_r_super {} +#[cfg(r#self)] //~ ERROR `self` cannot be a raw identifier +mod _cfg_r_self_lower {} +#[cfg(r#Self)] //~ ERROR `Self` cannot be a raw identifier +mod _cfg_r_self_upper {} +#[cfg_attr(r#crate, cfg(r#crate))] //~ 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 `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 `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 `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#enum)] // Ok +mod _cfg_r_enum {} +#[cfg(r#async)] // Ok +mod _cfg_r_async {} +#[cfg(r#impl)] // Ok +mod _cfg_r_impl {} +#[cfg(r#trait)] // Ok +mod _cfg_r_trait {} +#[cfg_attr(r#struct, cfg(r#struct))] // Ok +mod _cfg_attr_r_struct {} +#[cfg_attr(r#enum, cfg(r#enum))] // Ok +mod _cfg_attr_r_enum {} +#[cfg_attr(r#async, cfg(r#async))] // Ok +mod _cfg_attr_r_async {} +#[cfg_attr(r#impl, cfg(r#impl))] // Ok +mod _cfg_attr_r_impl {} +#[cfg_attr(r#trait, cfg(r#trait))] // Ok +mod _cfg_attr_r_trait {} 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..e8a16df10e96b --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred.stderr @@ -0,0 +1,383 @@ +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:88:10 + | +LL | cfg!(r#crate); + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:89:10 + | +LL | cfg!(r#super); + | ^^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:90:10 + | +LL | cfg!(r#self); + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:91:10 + | +LL | cfg!(r#Self); + | ^^^^^^ + +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:100:7 + | +LL | #[cfg(r#crate)] + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:102:7 + | +LL | #[cfg(r#super)] + | ^^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:104:7 + | +LL | #[cfg(r#self)] + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:106:7 + | +LL | #[cfg(r#Self)] + | ^^^^^^ + +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:108:12 + | +LL | #[cfg_attr(r#crate, cfg(r#crate))] + | ^^^^^^^ + +error: `crate` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:108:25 + | +LL | #[cfg_attr(r#crate, cfg(r#crate))] + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:111:12 + | +LL | #[cfg_attr(r#super, cfg(r#super))] + | ^^^^^^^ + +error: `super` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:111:25 + | +LL | #[cfg_attr(r#super, cfg(r#super))] + | ^^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:114:12 + | +LL | #[cfg_attr(r#self, cfg(r#self))] + | ^^^^^^ + +error: `self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:114:24 + | +LL | #[cfg_attr(r#self, cfg(r#self))] + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:117:12 + | +LL | #[cfg_attr(r#Self, cfg(r#Self))] + | ^^^^^^ + +error: `Self` cannot be a raw identifier + --> $DIR/path-kw-as-cfg-pred.rs:117:24 + | +LL | #[cfg_attr(r#Self, cfg(r#Self))] + | ^^^^^^ + +error: expected identifier, found keyword `crate` + --> $DIR/path-kw-as-cfg-pred.rs:18:7 + | +LL | #[cfg(crate)] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `super` + --> $DIR/path-kw-as-cfg-pred.rs:20:7 + | +LL | #[cfg(super)] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `self` + --> $DIR/path-kw-as-cfg-pred.rs:22:7 + | +LL | #[cfg(self)] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `Self` + --> $DIR/path-kw-as-cfg-pred.rs:24:7 + | +LL | #[cfg(Self)] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `crate` + --> $DIR/path-kw-as-cfg-pred.rs:26:12 + | +LL | #[cfg_attr(crate, path = "foo")] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `super` + --> $DIR/path-kw-as-cfg-pred.rs:28:12 + | +LL | #[cfg_attr(super, path = "foo")] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `self` + --> $DIR/path-kw-as-cfg-pred.rs:30:12 + | +LL | #[cfg_attr(self, path = "foo")] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `Self` + --> $DIR/path-kw-as-cfg-pred.rs:32:12 + | +LL | #[cfg_attr(Self, path = "foo")] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `crate` + --> $DIR/path-kw-as-cfg-pred.rs:34:22 + | +LL | #[cfg_attr(true, cfg(crate))] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `super` + --> $DIR/path-kw-as-cfg-pred.rs:36:22 + | +LL | #[cfg_attr(true, cfg(super))] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `self` + --> $DIR/path-kw-as-cfg-pred.rs:38:22 + | +LL | #[cfg_attr(true, cfg(self))] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `Self` + --> $DIR/path-kw-as-cfg-pred.rs:40:22 + | +LL | #[cfg_attr(true, cfg(Self))] + | ^^^^ expected identifier, found keyword + +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 keyword `enum` + --> $DIR/path-kw-as-cfg-pred.rs:45:7 + | +LL | #[cfg(enum)] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `async` + --> $DIR/path-kw-as-cfg-pred.rs:47:7 + | +LL | #[cfg(async)] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `impl` + --> $DIR/path-kw-as-cfg-pred.rs:49:7 + | +LL | #[cfg(impl)] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `trait` + --> $DIR/path-kw-as-cfg-pred.rs:51:7 + | +LL | #[cfg(trait)] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:53: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 keyword `enum` + --> $DIR/path-kw-as-cfg-pred.rs:55:12 + | +LL | #[cfg_attr(enum, path = "foo")] + | ^^^^ expected identifier, found keyword + | +help: escape `enum` to use it as an identifier + | +LL | #[cfg_attr(r#enum, path = "foo")] + | ++ + +error: expected identifier, found keyword `async` + --> $DIR/path-kw-as-cfg-pred.rs:57:12 + | +LL | #[cfg_attr(async, path = "foo")] + | ^^^^^ expected identifier, found keyword + | +help: escape `async` to use it as an identifier + | +LL | #[cfg_attr(r#async, path = "foo")] + | ++ + +error: expected identifier, found keyword `impl` + --> $DIR/path-kw-as-cfg-pred.rs:59:12 + | +LL | #[cfg_attr(impl, path = "foo")] + | ^^^^ expected identifier, found keyword + | +help: escape `impl` to use it as an identifier + | +LL | #[cfg_attr(r#impl, path = "foo")] + | ++ + +error: expected identifier, found keyword `trait` + --> $DIR/path-kw-as-cfg-pred.rs:61:12 + | +LL | #[cfg_attr(trait, path = "foo")] + | ^^^^^ expected identifier, found keyword + | +help: escape `trait` to use it as an identifier + | +LL | #[cfg_attr(r#trait, path = "foo")] + | ++ + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:63:22 + | +LL | #[cfg_attr(true, cfg(struct))] + | ^^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `enum` + --> $DIR/path-kw-as-cfg-pred.rs:65:22 + | +LL | #[cfg_attr(true, cfg(enum))] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `async` + --> $DIR/path-kw-as-cfg-pred.rs:67:22 + | +LL | #[cfg_attr(true, cfg(async))] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `impl` + --> $DIR/path-kw-as-cfg-pred.rs:69:22 + | +LL | #[cfg_attr(true, cfg(impl))] + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `trait` + --> $DIR/path-kw-as-cfg-pred.rs:71:22 + | +LL | #[cfg_attr(true, cfg(trait))] + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found reserved identifier `$crate` + --> $DIR/path-kw-as-cfg-pred.rs:7:15 + | +LL | #[cfg($crate)] + | ^^^^^^ expected identifier, found reserved identifier +... +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: expected identifier, found reserved identifier `$crate` + --> $DIR/path-kw-as-cfg-pred.rs:9:20 + | +LL | #[cfg_attr($crate, path = "foo")] + | ^^^^^^ expected identifier, found reserved identifier +... +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: expected identifier, found reserved identifier `$crate` + --> $DIR/path-kw-as-cfg-pred.rs:11:30 + | +LL | #[cfg_attr(true, cfg($crate))] + | ^^^^^^ expected identifier, found reserved identifier +... +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: expected identifier, found reserved identifier `$crate` + --> $DIR/path-kw-as-cfg-pred.rs:14:14 + | +LL | cfg!($crate); + | ^^^^^^ expected identifier, found reserved identifier +... +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: expected identifier, found keyword `crate` + --> $DIR/path-kw-as-cfg-pred.rs:77:10 + | +LL | cfg!(crate); + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `super` + --> $DIR/path-kw-as-cfg-pred.rs:78:10 + | +LL | cfg!(super); + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `self` + --> $DIR/path-kw-as-cfg-pred.rs:79:10 + | +LL | cfg!(self); + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `Self` + --> $DIR/path-kw-as-cfg-pred.rs:80:10 + | +LL | cfg!(Self); + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `struct` + --> $DIR/path-kw-as-cfg-pred.rs:82:10 + | +LL | cfg!(struct); + | ^^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `enum` + --> $DIR/path-kw-as-cfg-pred.rs:83:10 + | +LL | cfg!(enum); + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `async` + --> $DIR/path-kw-as-cfg-pred.rs:84:10 + | +LL | cfg!(async); + | ^^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `impl` + --> $DIR/path-kw-as-cfg-pred.rs:85:10 + | +LL | cfg!(impl); + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `trait` + --> $DIR/path-kw-as-cfg-pred.rs:86:10 + | +LL | cfg!(trait); + | ^^^^^ expected identifier, found keyword + +error: aborting due to 56 previous errors + 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 83% 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..2951aadb69ffb 100644 --- a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return.stderr +++ b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.return_.stderr @@ -1,21 +1,21 @@ error[E0080]: reached the configured maximum number of stack frames - --> $DIR/ctfe-id-unlimited.rs:28:20 + --> $DIR/ctfe-id-unlimited.rs:32:20 | LL | const ID_ED: u32 = rec_id(ORIGINAL); | ^^^^^^^^^^^^^^^^ evaluation of `ID_ED` failed inside this call | note: inside `rec_id` - --> $DIR/ctfe-id-unlimited.rs:21:5 + --> $DIR/ctfe-id-unlimited.rs:25:5 | LL | inner(0, n) | ^^^^^^^^^^^ note: [... 125 additional calls inside `inner` ...] - --> $DIR/ctfe-id-unlimited.rs:17:42 + --> $DIR/ctfe-id-unlimited.rs:21:42 | LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), | ^^^^^^^^^^^^^^^^^^^^^ note: inside `inner` - --> $DIR/ctfe-id-unlimited.rs:17:42 + --> $DIR/ctfe-id-unlimited.rs:21:42 | LL | #[cfg(r#return)] _ => return inner(acc + 1, n - 1), | ^^^^^^^^^^^^^^^^^^^^^ the failure occurred here diff --git a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs index 53cccb38e2b88..b7c1717e23226 100644 --- a/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs +++ b/tests/ui/explicit-tail-calls/ctfe-id-unlimited.rs @@ -1,5 +1,9 @@ -//@ revisions: become return -//@ [become] run-pass +//@ revisions: become_ return_ +//@ [become_] run-pass +//@ [become_] compile-flags: --cfg r#become +//@ [return_] compile-flags: --cfg r#return + +#![allow(unexpected_cfgs)] #![expect(incomplete_features)] #![feature(explicit_tail_calls)] @@ -25,7 +29,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);