Emit error when using path-segment keyword as cfg pred

This commit is contained in:
mu001999
2025-10-17 00:42:21 +08:00
parent e22dab387f
commit fc822f8c85
52 changed files with 988 additions and 99 deletions
@@ -82,7 +82,8 @@ pub fn parse_cfg_entry<S: Stage>(
}
},
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 {
return Err(cx.expected_identifier(meta.path().span()));
};
parse_name_value(name, meta.path().span(), a.name_value(), meta.span(), cx)?
@@ -158,7 +159,7 @@ fn parse_cfg_entry_target<S: Stage>(
};
// 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 {
return Err(cx.expected_identifier(sub_item.path().span()));
};
let name = Symbol::intern(&format!("target_{name}"));
@@ -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
}
+8 -14
View File
@@ -532,30 +532,24 @@ fn translator(&self) -> &Translator {
}
}
/// 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<dyn Emitter + DynSend>,
pub fatal_note: Option<String>,
/// An emitter that adds a note to each diagnostic.
pub struct EmitterWithNote {
pub emitter: Box<dyn Emitter + DynSend>,
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()
}
}
+44 -26
View File
@@ -15,6 +15,7 @@
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<String>) -> 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,46 @@ macro_rules! error {
($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
&& parser.dcx().has_errors().is_none() =>
{
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.is_path_segment_keyword() {
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()),
}
};
// 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 +127,9 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec<String>) -> 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,7 +182,7 @@ macro_rules! error {
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());
expected_error();
@@ -179,7 +190,9 @@ macro_rules! error {
};
let meta_item = match parser.parse_meta_item(AllowLeadingUnsafe::No) {
Ok(meta_item) if parser.token == token::Eof => meta_item,
Ok(meta_item) if parser.token == token::Eof && parser.dcx().has_errors().is_none() => {
meta_item
}
Ok(..) => expected_error(),
Err(err) => {
err.cancel();
@@ -209,6 +222,11 @@ macro_rules! error {
if values_specified {
error!("`cfg()` names cannot be after values");
}
if ident.is_path_segment_keyword() {
error!("malformed `cfg` input, expected a valid identifier");
}
names.push(ident);
} else if let Some(boolean) = arg.boolean_literal() {
if values_specified {
+1 -1
View File
@@ -466,7 +466,7 @@ fn expect_one_of(
// 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> {
+4 -8
View File
@@ -8,7 +8,7 @@
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 @@ pub fn with_dcx(dcx: DiagCtxt, source_map: Arc<SourceMap>) -> Self {
}
}
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)
}
+4 -4
View File
@@ -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;
}
+13 -13
View File
@@ -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)]
#![allow(function_casts_as_integer)]
@@ -15,8 +15,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;
@@ -29,8 +29,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;
@@ -52,8 +52,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;
@@ -66,8 +66,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;
@@ -79,8 +79,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() {}
@@ -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 @@ pub(crate) struct Vtable {
}
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),
}
+5 -5
View File
@@ -1,12 +1,12 @@
// Test that the correct module flags are emitted with different control-flow protection flags.
//@ add-minicore
//@ 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
+1 -1
View File
@@ -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() {}
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `crate` (malformed `cfg` input, expected a valid identifier)
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `priv` (expected `key` or `key="value"`)
@@ -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` (expected `key` or `key="value"`)
@@ -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` (expected `key` or `key="value"`)
@@ -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` (expected `key` or `key="value"`)
@@ -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` (expected `key` or `key="value"`)
@@ -0,0 +1,6 @@
error: `_` cannot be a raw identifier
|
= note: this occurred on the command line: `--cfg=r#_`
error: invalid `--cfg` argument: `r#_` (expected `key` or `key="value"`)
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `self` (malformed `cfg` input, expected a valid identifier)
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `Self` (malformed `cfg` input, expected a valid identifier)
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `struct` (expected `key` or `key="value"`)
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `super` (malformed `cfg` input, expected a valid identifier)
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `_` (expected `key` or `key="value"`)
@@ -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
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(crate)`
|
= note: malformed `cfg` input, expected a valid identifier
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(priv)`
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -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: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -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: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -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: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -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: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -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: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(self)`
|
= note: malformed `cfg` input, expected a valid identifier
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(Self)`
|
= note: malformed `cfg` input, expected a valid identifier
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(struct)`
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(super)`
|
= note: malformed `cfg` input, expected a valid identifier
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -0,0 +1,5 @@
error: invalid `--check-cfg` argument: `cfg(_)`
|
= note: expected `cfg(name, values("value1", "value2", ... "valueN"))`
= note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details
@@ -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
@@ -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() {}
+129
View File
@@ -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 malformed `cfg` macro input
};
}
#[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 malformed `cfg` macro input
cfg!(super); //~ ERROR malformed `cfg` macro input
cfg!(self); //~ ERROR malformed `cfg` macro input
cfg!(Self); //~ ERROR malformed `cfg` macro input
cfg!(r#crate); //~ ERROR `crate` cannot be a raw identifier
//~^ ERROR malformed `cfg` macro input
cfg!(r#super); //~ ERROR `super` cannot be a raw identifier
//~^ ERROR malformed `cfg` macro input
cfg!(r#self); //~ ERROR `self` cannot be a raw identifier
//~^ ERROR malformed `cfg` macro input
cfg!(r#Self); //~ ERROR `Self` cannot be a raw identifier
//~^ ERROR malformed `cfg` macro input
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 {}
+573
View File
@@ -0,0 +1,573 @@
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
= 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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
= 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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:14: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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
= note: this error originates in the macro `cfg` which comes from the expansion of the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:65:5
|
LL | cfg!(crate);
| ^^^^^-----^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:66:5
|
LL | cfg!(super);
| ^^^^^-----^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:67:5
|
LL | cfg!(self);
| ^^^^^----^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:68:5
|
LL | cfg!(Self);
| ^^^^^----^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:70:5
|
LL | cfg!(r#crate);
| ^^^^^-------^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:72:5
|
LL | cfg!(r#super);
| ^^^^^-------^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:74:5
|
LL | cfg!(r#self);
| ^^^^^------^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
error[E0539]: malformed `cfg` macro input
--> $DIR/path-kw-as-cfg-pred.rs:76:5
|
LL | cfg!(r#Self);
| ^^^^^------^
| | |
| | expected a valid identifier here
| help: must be of the form: `cfg!(predicate)`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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`.
+1 -5
View File
@@ -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))]
+1 -1
View File
@@ -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
@@ -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
@@ -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"`
@@ -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
@@ -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 inner(acc: u32, 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);