]> git.lizzy.rs Git - rust.git/blob - src/test/ui/macros/macros-nonfatal-errors.rs
Rollup merge of #95376 - WaffleLapkin:drain_keep_rest, r=dtolnay
[rust.git] / src / test / ui / macros / macros-nonfatal-errors.rs
1 // normalize-stderr-test: "existed:.*\(" -> "existed: $$FILE_NOT_FOUND_MSG ("
2
3 // test that errors in a (selection) of macros don't kill compilation
4 // immediately, so that we get more errors listed at a time.
5
6 #![feature(trace_macros, concat_idents)]
7 #![feature(stmt_expr_attributes, arbitrary_enum_discriminant)]
8
9 use std::arch::asm;
10
11 #[derive(Default)]
12 struct DefaultInnerAttrStruct {
13     #[default] //~ ERROR the `#[default]` attribute may only be used on unit enum variants
14     foo: (),
15 }
16
17 #[derive(Default)]
18 struct DefaultInnerAttrTupleStruct(#[default] ());
19 //~^ ERROR the `#[default]` attribute may only be used on unit enum variants
20
21 #[derive(Default)]
22 #[default] //~ ERROR the `#[default]` attribute may only be used on unit enum variants
23 struct DefaultOuterAttrStruct {}
24
25 #[derive(Default)]
26 #[default] //~ ERROR the `#[default]` attribute may only be used on unit enum variants
27 enum DefaultOuterAttrEnum {
28     #[default]
29     Foo,
30 }
31
32 #[rustfmt::skip] // needs some work to handle this case
33 #[repr(u8)]
34 #[derive(Default)]
35 enum AttrOnInnerExpression {
36     Foo = #[default] 0, //~ ERROR the `#[default]` attribute may only be used on unit enum variants
37     Bar([u8; #[default] 1]), //~ ERROR the `#[default]` attribute may only be used on unit enum variants
38     #[default]
39     Baz,
40 }
41
42 #[derive(Default)] //~ ERROR no default declared
43 enum NoDeclaredDefault {
44     Foo,
45     Bar,
46 }
47
48 #[derive(Default)] //~ ERROR multiple declared defaults
49 enum MultipleDefaults {
50     #[default]
51     Foo,
52     #[default]
53     Bar,
54     #[default]
55     Baz,
56 }
57
58 #[derive(Default)]
59 enum ExtraDeriveTokens {
60     #[default = 1] //~ ERROR `#[default]` attribute does not accept a value
61     Foo,
62 }
63
64 #[derive(Default)]
65 enum TwoDefaultAttrs {
66     #[default]
67     #[default]
68     Foo, //~ERROR multiple `#[default]` attributes
69     Bar,
70 }
71
72 #[derive(Default)]
73 enum ManyDefaultAttrs {
74     #[default]
75     #[default]
76     #[default]
77     #[default]
78     Foo, //~ERROR multiple `#[default]` attributes
79     Bar,
80 }
81
82 #[derive(Default)]
83 enum DefaultHasFields {
84     #[default]
85     Foo {}, //~ ERROR the `#[default]` attribute may only be used on unit enum variants
86     Bar,
87 }
88
89 #[derive(Default)]
90 enum NonExhaustiveDefault {
91     #[default]
92     #[non_exhaustive]
93     Foo, //~ ERROR default variant must be exhaustive
94     Bar,
95 }
96
97 fn main() {
98     asm!(invalid); //~ ERROR
99     llvm_asm!(invalid); //~ ERROR
100
101     concat_idents!("not", "idents"); //~ ERROR
102
103     option_env!(invalid); //~ ERROR
104     env!(invalid); //~ ERROR
105     env!(foo, abr, baz); //~ ERROR
106     env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); //~ ERROR
107
108     format!(invalid); //~ ERROR
109
110     include!(invalid); //~ ERROR
111
112     include_str!(invalid); //~ ERROR
113     include_str!("i'd be quite surprised if a file with this name existed"); //~ ERROR
114     include_bytes!(invalid); //~ ERROR
115     include_bytes!("i'd be quite surprised if a file with this name existed"); //~ ERROR
116
117     trace_macros!(invalid); //~ ERROR
118 }