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