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