Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)) => {
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0537.md
Original file line number Diff line number Diff line change
@@ -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() {}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
17 changes: 13 additions & 4 deletions tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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
Expand Down Expand Up @@ -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`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(foo(bar))] //~ ERROR invalid predicate `foo`
#[cfg(foo(bar))] //~ ERROR malformed `cfg` attribute input [E0539]
fn check() {}

fn main() {}
17 changes: 13 additions & 4 deletions tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
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)]
| ^^^^^^^^^^--^^
Expand All @@ -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")]
| ^^^^^^^^^^-^^^^^^
Expand All @@ -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)]
| ^^^^^
Expand All @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
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
Expand Down Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion tests/ui/macros/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ cfg_select! {

cfg_select! {
a() => {}
//~^ ERROR invalid predicate `a` [E0537]
//~^ ERROR malformed `cfg_select` macro input [E0539]
}

cfg_select! {
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/macros/cfg_select.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.
4 changes: 0 additions & 4 deletions tests/ui/span/E0537.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/span/E0537.stderr

This file was deleted.

Loading