diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index 3a2f0ea74ba25..47d3a1249c846 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -103,10 +103,11 @@ pub fn parse_cfg_entry( Some(sym::target) => parse_cfg_entry_target(cx, list, meta.span())?, Some(sym::version) => parse_cfg_entry_version(cx, list, meta.span())?, _ => { - return Err(cx.emit_err(session_diagnostics::InvalidPredicate { - span: meta.span(), - predicate: meta.path().to_string(), - })); + let mut possibilities = vec![sym::any, sym::all, sym::not, sym::target]; + if cx.features().cfg_version() { + possibilities.push(sym::version); + } + return Err(cx.adcx().expected_specific_argument(meta.span(), &possibilities)); } }, a @ (ArgParser::NoArgs | ArgParser::NameValue(_)) => { diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 121cac79e6382..193ffe195fb6c 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -13,15 +13,6 @@ use rustc_target::spec::TargetTuple; use crate::AttributeTemplate; use crate::context::Suggestion; -#[derive(Diagnostic)] -#[diag("invalid predicate `{$predicate}`", code = E0537)] -pub(crate) struct InvalidPredicate { - #[primary_span] - pub span: Span, - - pub predicate: String, -} - #[derive(Diagnostic)] #[diag("{$attr_str} attribute cannot have empty value")] pub(crate) struct DocAliasEmpty<'a> { diff --git a/compiler/rustc_error_codes/src/error_codes/E0537.md b/compiler/rustc_error_codes/src/error_codes/E0537.md index 123efd4f57df3..8d5b3b3fb8714 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0537.md +++ b/compiler/rustc_error_codes/src/error_codes/E0537.md @@ -1,8 +1,9 @@ +#### Note: this error code is no longer emitted by the compiler An unknown predicate was used inside the `cfg` attribute. Erroneous code example: -```compile_fail,E0537 +```compile_fail,E0539 #[cfg(unknown())] // error: invalid predicate `unknown` pub fn something() {} diff --git a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs index a034b7246a347..dd3097119271b 100644 --- a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs +++ b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs @@ -29,5 +29,5 @@ static FOO: usize = 0; fn main() { let _a = cfg!(unsafe(foo)); //~^ ERROR: expected identifier, found keyword `unsafe` - //~^^ ERROR: invalid predicate `r#unsafe` + //~^^ ERROR: malformed `cfg` macro input [E0539] } diff --git a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr index dec8c4d3542b4..0236f79d0bc3e 100644 --- a/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr +++ b/tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr @@ -33,11 +33,20 @@ help: escape `unsafe` to use it as an identifier LL | let _a = cfg!(r#unsafe(foo)); | ++ -error[E0537]: invalid predicate `r#unsafe` - --> $DIR/extraneous-unsafe-attributes.rs:30:19 +error[E0539]: malformed `cfg` macro input + --> $DIR/extraneous-unsafe-attributes.rs:30:14 | LL | let _a = cfg!(unsafe(foo)); - | ^^^^^^^^^^^ + | ^^^^^-----------^ + | | + | valid arguments are `any`, `all`, `not` or `target` + | + = note: for more information, visit +help: must be of the form + | +LL - let _a = cfg!(unsafe(foo)); +LL + let _a = cfg!(predicate); + | error: `ignore` is not an unsafe attribute --> $DIR/extraneous-unsafe-attributes.rs:12:3 @@ -81,4 +90,4 @@ LL | #[unsafe(used)] error: aborting due to 10 previous errors -For more information about this error, try `rustc --explain E0537`. +For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs index 496d196c94ae5..61d0f45437c00 100644 --- a/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs +++ b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs @@ -1,4 +1,4 @@ -#[cfg(foo(bar))] //~ ERROR invalid predicate `foo` +#[cfg(foo(bar))] //~ ERROR malformed `cfg` attribute input [E0539] fn check() {} fn main() {} diff --git a/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr index 2033894b3b4f6..5e15ecd66bcd6 100644 --- a/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr @@ -1,9 +1,18 @@ -error[E0537]: invalid predicate `foo` - --> $DIR/cfg-attr-invalid-predicate.rs:1:7 +error[E0539]: malformed `cfg` attribute input + --> $DIR/cfg-attr-invalid-predicate.rs:1:1 | LL | #[cfg(foo(bar))] - | ^^^^^^^^ + | ^^^^^^--------^^ + | | + | valid arguments are `any`, `all`, `not` or `target` + | + = note: for more information, visit +help: must be of the form + | +LL - #[cfg(foo(bar))] +LL + #[cfg(predicate)] + | error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0537`. +For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs index 5f319555b9a19..f78353d10991f 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs @@ -34,7 +34,9 @@ struct S5; //~| NOTE for more information, visit struct S6; -#[cfg(a())] //~ ERROR invalid predicate `a` +#[cfg(a())] //~ ERROR malformed `cfg` attribute input +//~| NOTE valid arguments are `any`, `all`, `not` or `target` +//~| NOTE for more information, visit struct S7; #[cfg(a = 10)] //~ ERROR malformed `cfg` attribute input diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index 8098e09fba567..97792a9a151d7 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -89,14 +89,23 @@ LL - #[cfg(a::b)] LL + #[cfg(predicate)] | -error[E0537]: invalid predicate `a` - --> $DIR/cfg-attr-syntax-validation.rs:37:7 +error[E0539]: malformed `cfg` attribute input + --> $DIR/cfg-attr-syntax-validation.rs:37:1 | LL | #[cfg(a())] - | ^^^ + | ^^^^^^---^^ + | | + | valid arguments are `any`, `all`, `not` or `target` + | + = note: for more information, visit +help: must be of the form + | +LL - #[cfg(a())] +LL + #[cfg(predicate)] + | error[E0539]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:40:1 + --> $DIR/cfg-attr-syntax-validation.rs:42:1 | LL | #[cfg(a = 10)] | ^^^^^^^^^^--^^ @@ -111,7 +120,7 @@ LL + #[cfg(predicate)] | error[E0539]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:45:1 + --> $DIR/cfg-attr-syntax-validation.rs:47:1 | LL | #[cfg(a = b"hi")] | ^^^^^^^^^^-^^^^^^ @@ -121,7 +130,7 @@ LL | #[cfg(a = b"hi")] = note: expected a normal string literal, not a byte string literal error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `expr` metavariable - --> $DIR/cfg-attr-syntax-validation.rs:51:25 + --> $DIR/cfg-attr-syntax-validation.rs:53:25 | LL | #[cfg(feature = $expr)] | ^^^^^ @@ -133,5 +142,5 @@ LL | generate_s10!(concat!("nonexistent")); error: aborting due to 10 previous errors -Some errors have detailed explanations: E0537, E0539, E0565, E0805. -For more information about an error, try `rustc --explain E0537`. +Some errors have detailed explanations: E0539, E0565, E0805. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.rs b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.rs index a0f86e3e771fd..907e1b966766f 100644 --- a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.rs +++ b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.rs @@ -16,7 +16,7 @@ struct S5; #[cfg_attr(a::b)] //~ ERROR malformed `cfg_attr` attribute input struct S6; -#[cfg_attr(a())] //~ ERROR invalid predicate `a` +#[cfg_attr(a())] //~ ERROR malformed `cfg_attr` attribute input [E0539] struct S7; #[cfg_attr(a = 10)] //~ ERROR malformed `cfg_attr` attribute input diff --git a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr index 41b2b416509b0..ff7c289ef1f6f 100644 --- a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr @@ -67,11 +67,20 @@ LL - #[cfg_attr(a::b)] LL + #[cfg_attr(predicate, attr1, attr2, ...)] | -error[E0537]: invalid predicate `a` - --> $DIR/cfg_attr-attr-syntax-validation.rs:19:12 +error[E0539]: malformed `cfg_attr` attribute input + --> $DIR/cfg_attr-attr-syntax-validation.rs:19:1 | LL | #[cfg_attr(a())] - | ^^^ + | ^^^^^^^^^^^---^^ + | | + | valid arguments are `any`, `all`, `not` or `target` + | + = note: for more information, visit +help: must be of the form + | +LL - #[cfg_attr(a())] +LL + #[cfg_attr(predicate, attr1, attr2, ...)] + | error[E0539]: malformed `cfg_attr` attribute input --> $DIR/cfg_attr-attr-syntax-validation.rs:22:1 @@ -177,5 +186,5 @@ LL | #[cfg_attr(true, link_section)] error: aborting due to 13 previous errors; 1 warning emitted -Some errors have detailed explanations: E0537, E0539, E0565, E0805. -For more information about an error, try `rustc --explain E0537`. +Some errors have detailed explanations: E0539, E0565, E0805. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/macros/cfg_select.rs b/tests/ui/macros/cfg_select.rs index 99db268bd28b7..0f03a8a99c4fb 100644 --- a/tests/ui/macros/cfg_select.rs +++ b/tests/ui/macros/cfg_select.rs @@ -188,7 +188,7 @@ cfg_select! { cfg_select! { a() => {} - //~^ ERROR invalid predicate `a` [E0537] + //~^ ERROR malformed `cfg_select` macro input [E0539] } cfg_select! { diff --git a/tests/ui/macros/cfg_select.stderr b/tests/ui/macros/cfg_select.stderr index e5871619b957a..1199b1f4d026c 100644 --- a/tests/ui/macros/cfg_select.stderr +++ b/tests/ui/macros/cfg_select.stderr @@ -37,11 +37,11 @@ error[E0565]: malformed `cfg_select` macro input LL | a::b => {} | ^^^^ expected a valid identifier here -error[E0537]: invalid predicate `a` +error[E0539]: malformed `cfg_select` macro input --> $DIR/cfg_select.rs:190:5 | LL | a() => {} - | ^^^ + | ^^^ valid arguments are `any`, `all`, `not` or `target` error: expected one of `(`, `::`, `=>`, or `=`, found `+` --> $DIR/cfg_select.rs:195:7 @@ -185,5 +185,5 @@ LL | cfg!() => {} error: aborting due to 17 previous errors; 7 warnings emitted -Some errors have detailed explanations: E0537, E0565, E0753. -For more information about an error, try `rustc --explain E0537`. +Some errors have detailed explanations: E0539, E0565, E0753. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/span/E0537.rs b/tests/ui/span/E0537.rs deleted file mode 100644 index 4088a9ae53a27..0000000000000 --- a/tests/ui/span/E0537.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[cfg(unknown())] //~ ERROR E0537 -pub fn something() {} - -pub fn main() {} diff --git a/tests/ui/span/E0537.stderr b/tests/ui/span/E0537.stderr deleted file mode 100644 index 4254d3893b83f..0000000000000 --- a/tests/ui/span/E0537.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0537]: invalid predicate `unknown` - --> $DIR/E0537.rs:1:7 - | -LL | #[cfg(unknown())] - | ^^^^^^^^^ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0537`.