diff options
| author | Jonathan Brouwer <jonathantbrouwer@gmail.com> | 2025-07-07 09:10:54 +0200 |
|---|---|---|
| committer | Jonathan Brouwer <jonathantbrouwer@gmail.com> | 2025-07-15 09:21:27 +0200 |
| commit | 7a7c74ad89df9f87824fa17fbbe0448d9ab6f7cc (patch) | |
| tree | 635bf7b454df9fe8fbb5d76d8f75102f59e33b6b | |
| parent | c7f5ddc09871dc74c9f451435b042707eef5dc6c (diff) | |
| download | rust-7a7c74ad89df9f87824fa17fbbe0448d9ab6f7cc.tar.gz rust-7a7c74ad89df9f87824fa17fbbe0448d9ab6f7cc.zip | |
New example for E0536
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0536.md | 16 | ||||
| -rw-r--r-- | tests/ui/span/E0536.rs | 7 | ||||
| -rw-r--r-- | tests/ui/span/E0536.stderr | 6 |
3 files changed, 13 insertions, 16 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0536.md b/compiler/rustc_error_codes/src/error_codes/E0536.md index c081a3d9cfa..f00d1773944 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0536.md +++ b/compiler/rustc_error_codes/src/error_codes/E0536.md @@ -3,22 +3,20 @@ The `not` cfg-predicate was malformed. Erroneous code example: ```compile_fail,E0536 -#[cfg(not())] // error: expected 1 cfg-pattern -pub fn something() {} - -pub fn main() {} +pub fn main() { + if cfg!(not()) { } +} ``` The `not` predicate expects one cfg-pattern. Example: ``` -#[cfg(not(target_os = "linux"))] // ok! -pub fn something() {} - -pub fn main() {} +pub fn main() { + if cfg!(not(target_os = "linux")) { } // ok! +} ``` -For more information about the `cfg` attribute, read the section on +For more information about the `cfg` macro, read the section on [Conditional Compilation][conditional-compilation] in the Reference. [conditional-compilation]: https://doc.rust-lang.org/reference/conditional-compilation.html diff --git a/tests/ui/span/E0536.rs b/tests/ui/span/E0536.rs index 72de7b6f453..ae073363354 100644 --- a/tests/ui/span/E0536.rs +++ b/tests/ui/span/E0536.rs @@ -1,4 +1,3 @@ -#[cfg(not())] //~ ERROR E0536 -pub fn something() {} - -pub fn main() {} +pub fn main() { + if cfg!(not()) { } //~ ERROR E0536 +} diff --git a/tests/ui/span/E0536.stderr b/tests/ui/span/E0536.stderr index b0f652208c4..6c25f9140a1 100644 --- a/tests/ui/span/E0536.stderr +++ b/tests/ui/span/E0536.stderr @@ -1,8 +1,8 @@ error[E0536]: expected 1 cfg-pattern - --> $DIR/E0536.rs:1:7 + --> $DIR/E0536.rs:2:13 | -LL | #[cfg(not())] - | ^^^^^ +LL | if cfg!(not()) { } + | ^^^^^ error: aborting due to 1 previous error |
