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_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 0d10f29d31d64..06a896439918c 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -534,30 +534,24 @@ 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 -/// failures of rustc, as witnessed e.g. in issue #89358. -pub struct FatalOnlyEmitter { - pub fatal_emitter: Box, - pub fatal_note: Option, +/// An emitter that adds a note to each diagnostic. +pub struct EmitterWithNote { + pub emitter: Box, + pub note: String, } -impl Emitter for FatalOnlyEmitter { +impl Emitter for EmitterWithNote { 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); - } + diag.sub(Level::Note, self.note.clone(), MultiSpan::new()); + self.emitter.emit_diagnostic(diag, registry); } fn translator(&self) -> &Translator { - self.fatal_emitter.translator() + self.emitter.translator() } } diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index b52c5b4cd663b..065658c6ea566 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,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_fatal_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); @@ -62,36 +63,47 @@ 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!( - concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), - s - )); + dcx.fatal(format!("invalid `--cfg` argument: `{}` ({})", s, $reason,)); }; } 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"); - return (ident.name, meta_item.value_str()); + 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.name.can_be_raw() { + error!( + "malformed `cfg` input, expected a valid identifier" + ); + } + + return (ident.name, meta_item.value_str()); + } } } + Ok(..) => {} + Err(err) => { + err.cancel(); + } } - Ok(..) => {} - Err(err) => err.cancel(), - }, - Err(errs) => errs.into_iter().for_each(|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. @@ -116,9 +128,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_fatal_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); @@ -171,9 +183,11 @@ 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.cancel()); + errs.into_iter().for_each(|err| { + err.cancel(); + }); expected_error(); } }; @@ -209,11 +223,17 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec) -> Ch if values_specified { error!("`cfg()` names cannot be after values"); } + + if !ident.name.can_be_raw() { + error!("malformed `cfg` input, expected a valid identifier"); + } + names.push(ident); } else if let Some(boolean) = arg.boolean_literal() { if values_specified { error!("`cfg()` names cannot be after values"); } + 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..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::{FatalOnlyEmitter, 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,16 +315,12 @@ impl ParseSess { } } - pub fn with_fatal_emitter(locale_resources: Vec<&'static str>, fatal_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 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(EmitterWithNote { emitter, note })); ParseSess::with_dcx(dcx, sm) } 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), } 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..daaddd3074160 --- /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` (malformed `cfg` input, expected a valid 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 new file mode 100644 index 0000000000000..5fd341485cd99 --- /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` (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 new file mode 100644 index 0000000000000..cede4537138b7 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_crate.stderr @@ -0,0 +1,6 @@ +error: `crate` cannot be a raw identifier + | + = note: this occurred on the command line: `--cfg=r#crate` + +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 new file mode 100644 index 0000000000000..57ce4218fe9c6 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_lower.stderr @@ -0,0 +1,6 @@ +error: `self` cannot be a raw identifier + | + = note: this occurred on the command line: `--cfg=r#self` + +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 new file mode 100644 index 0000000000000..e594d3f62c9ea --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_self_upper.stderr @@ -0,0 +1,6 @@ +error: `Self` cannot be a raw identifier + | + = note: this occurred on the command line: `--cfg=r#Self` + +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 new file mode 100644 index 0000000000000..08ac88359a02c --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_super.stderr @@ -0,0 +1,6 @@ +error: `super` cannot be a raw identifier + | + = note: this occurred on the command line: `--cfg=r#super` + +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 new file mode 100644 index 0000000000000..f7c204319a36f --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_raw_underscore.stderr @@ -0,0 +1,6 @@ +error: `_` cannot be a raw identifier + | + = note: this occurred on the command line: `--cfg=r#_` + +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 new file mode 100644 index 0000000000000..9d7897c48ef46 --- /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` (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 new file mode 100644 index 0000000000000..16c91198eea79 --- /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` (malformed `cfg` input, expected a valid 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 new file mode 100644 index 0000000000000..5ee3f35ae0cfe --- /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` (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 new file mode 100644 index 0000000000000..08513ac466cb7 --- /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` (malformed `cfg` input, expected a valid 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 new file mode 100644 index 0000000000000..4dfb3f8276469 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-cfg.cfg_underscore.stderr @@ -0,0 +1,2 @@ +error: invalid `--cfg` argument: `_` (expected `key` or `key="value"`) + 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..69f06cf5e216c --- /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: 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_priv.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_priv.stderr new file mode 100644 index 0000000000000..2165d37500a91 --- /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: 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 new file mode 100644 index 0000000000000..6be2c90481dd5 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_crate.stderr @@ -0,0 +1,9 @@ +error: `crate` cannot be a raw identifier + | + = note: this occurred on the command line: `--check-cfg=cfg(r#crate)` + +error: invalid `--check-cfg` argument: `cfg(r#crate)` + | + = 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 new file mode 100644 index 0000000000000..55bfa012942e3 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_lower.stderr @@ -0,0 +1,9 @@ +error: `self` cannot be a raw identifier + | + = note: this occurred on the command line: `--check-cfg=cfg(r#self)` + +error: invalid `--check-cfg` argument: `cfg(r#self)` + | + = 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 new file mode 100644 index 0000000000000..ada7945a7778a --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_self_upper.stderr @@ -0,0 +1,9 @@ +error: `Self` cannot be a raw identifier + | + = note: this occurred on the command line: `--check-cfg=cfg(r#Self)` + +error: invalid `--check-cfg` argument: `cfg(r#Self)` + | + = 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 new file mode 100644 index 0000000000000..a395e2ce9b157 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_super.stderr @@ -0,0 +1,9 @@ +error: `super` cannot be a raw identifier + | + = note: this occurred on the command line: `--check-cfg=cfg(r#super)` + +error: invalid `--check-cfg` argument: `cfg(r#super)` + | + = 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 new file mode 100644 index 0000000000000..e796f0a2a8f38 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_raw_underscore.stderr @@ -0,0 +1,9 @@ +error: `_` cannot be a raw identifier + | + = note: this occurred on the command line: `--check-cfg=cfg(r#_)` + +error: invalid `--check-cfg` argument: `cfg(r#_)` + | + = 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 new file mode 100644 index 0000000000000..b109650d116d4 --- /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: 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 new file mode 100644 index 0000000000000..649cde33e159a --- /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: 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_struct.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_struct.stderr new file mode 100644 index 0000000000000..40942a955bf92 --- /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: 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 new file mode 100644 index 0000000000000..488d2982e7b80 --- /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: 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_underscore.stderr b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.check_cfg_underscore.stderr new file mode 100644 index 0000000000000..98a645f039a51 --- /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: 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 new file mode 100644 index 0000000000000..57ec3f3d54bd4 --- /dev/null +++ b/tests/ui/cfg/path-kw-as-cfg-pred-cli-check-cfg.rs @@ -0,0 +1,25 @@ +//@ 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 +//@ 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/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"` 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);