File: forbid-macro-with-deny.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (45 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Ensure that when a macro (or normal code) does `#[deny]` inside a `#[forbid]` context, no error
//! is emitted, as both parties agree on the treatment of the lint.
//!
//! However, still emit an error if the macro does `#[allow]` or `#[warn]`.

//@ revisions: forbid deny warn allow
//@[forbid] aux-build:forbid-macro.rs
//@[deny] aux-build:deny-macro.rs
//@[warn] aux-build:warn-macro.rs
//@[allow] aux-build:allow-macro.rs

//@[forbid] check-pass
//@[deny] check-pass

#![forbid(unsafe_code)]

#[cfg(allow)]
extern crate allow_macro;
#[cfg(deny)]
extern crate deny_macro;
#[cfg(forbid)]
extern crate forbid_macro;
#[cfg(warn)]
extern crate warn_macro;

fn main() {
    #[cfg(forbid)]
    forbid_macro::emit_forbid! {} // OK

    #[cfg(deny)]
    deny_macro::emit_deny! {} // OK

    #[cfg(warn)]
    warn_macro::emit_warn! {}
    //[warn]~^ ERROR warn(unsafe_code) incompatible with previous forbid
    //[warn]~| ERROR warn(unsafe_code) incompatible with previous forbid

    #[cfg(allow)]
    allow_macro::emit_allow! {}
    //[allow]~^ ERROR allow(unsafe_code) incompatible with previous forbid
    //[allow]~| ERROR allow(unsafe_code) incompatible with previous forbid

    #[deny(unsafe_code)] // OK
    let _ = 0;
}