]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/crate_in_macro_def.rs
Auto merge of #101969 - reez12g:issue-101306, r=reez12g
[rust.git] / src / tools / clippy / tests / ui / crate_in_macro_def.rs
1 // run-rustfix
2 #![warn(clippy::crate_in_macro_def)]
3
4 mod hygienic {
5     #[macro_export]
6     macro_rules! print_message_hygienic {
7         () => {
8             println!("{}", $crate::hygienic::MESSAGE);
9         };
10     }
11
12     pub const MESSAGE: &str = "Hello!";
13 }
14
15 mod unhygienic {
16     #[macro_export]
17     macro_rules! print_message_unhygienic {
18         () => {
19             println!("{}", crate::unhygienic::MESSAGE);
20         };
21     }
22
23     pub const MESSAGE: &str = "Hello!";
24 }
25
26 mod unhygienic_intentionally {
27     // For cases where the use of `crate` is intentional, applying `allow` to the macro definition
28     // should suppress the lint.
29     #[allow(clippy::crate_in_macro_def)]
30     #[macro_export]
31     macro_rules! print_message_unhygienic_intentionally {
32         () => {
33             println!("{}", crate::CALLER_PROVIDED_MESSAGE);
34         };
35     }
36 }
37
38 #[macro_use]
39 mod not_exported {
40     macro_rules! print_message_not_exported {
41         () => {
42             println!("{}", crate::not_exported::MESSAGE);
43         };
44     }
45
46     pub const MESSAGE: &str = "Hello!";
47 }
48
49 fn main() {
50     print_message_hygienic!();
51     print_message_unhygienic!();
52     print_message_unhygienic_intentionally!();
53     print_message_not_exported!();
54 }
55
56 pub const CALLER_PROVIDED_MESSAGE: &str = "Hello!";