Skip to content

Commit 0fcf295

Browse files
New test for malformed attributes
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 86e05cd commit 0fcf295

File tree

2 files changed

+825
-0
lines changed

2 files changed

+825
-0
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// This file contains a bunch of malformed attributes.
2+
// We enable a bunch of features to not get feature-gate errs in this test.
3+
#![feature(rustc_attrs)]
4+
#![feature(rustc_allow_const_fn_unstable)]
5+
#![feature(allow_internal_unstable)]
6+
#![feature(fn_align)]
7+
#![feature(optimize_attribute)]
8+
#![feature(dropck_eyepatch)]
9+
#![feature(export_stable)]
10+
#![allow(incomplete_features)]
11+
#![feature(min_generic_const_args)]
12+
#![feature(ffi_const, ffi_pure)]
13+
#![feature(coverage_attribute)]
14+
#![feature(no_sanitize)]
15+
#![feature(marker_trait_attr)]
16+
#![feature(thread_local)]
17+
#![feature(must_not_suspend)]
18+
#![feature(coroutines)]
19+
#![feature(linkage)]
20+
#![feature(cfi_encoding, extern_types)]
21+
#![feature(patchable_function_entry)]
22+
#![feature(omit_gdb_pretty_printer_section)]
23+
#![feature(fundamental)]
24+
25+
26+
#![omit_gdb_pretty_printer_section = 1]
27+
//~^ ERROR malformed `omit_gdb_pretty_printer_section` attribute input
28+
29+
#![windows_subsystem]
30+
//~^ ERROR malformed
31+
32+
#[unsafe(export_name)]
33+
//~^ ERROR malformed
34+
//~| ERROR malformed
35+
#[rustc_allow_const_fn_unstable]
36+
//~^ ERROR `rustc_allow_const_fn_unstable` expects a list of feature names
37+
#[allow_internal_unstable]
38+
//~^ ERROR `allow_internal_unstable` expects a list of feature names
39+
#[rustc_confusables]
40+
//~^ ERROR malformed
41+
#[deprecated = 5]
42+
//~^ ERROR malformed
43+
#[doc]
44+
//~^ ERROR valid forms for the attribute are
45+
//~| WARN this was previously accepted by the compiler
46+
#[rustc_macro_transparency]
47+
//~^ ERROR malformed
48+
//~| ERROR malformed
49+
#[repr]
50+
//~^ ERROR malformed
51+
#[rustc_as_ptr = 5]
52+
//~^ ERROR malformed
53+
#[inline = 5]
54+
//~^ ERROR valid forms for the attribute are
55+
//~| WARN this was previously accepted by the compiler
56+
#[align]
57+
//~^ ERROR malformed
58+
#[optimize]
59+
//~^ ERROR malformed
60+
#[cold = 1]
61+
//~^ ERROR malformed
62+
#[must_use()]
63+
//~^ ERROR valid forms for the attribute are
64+
#[no_mangle = 1]
65+
//~^ ERROR malformed
66+
#[unsafe(naked())]
67+
//~^ ERROR malformed
68+
#[track_caller()]
69+
//~^ ERROR malformed
70+
#[export_name()]
71+
//~^ ERROR malformed
72+
//~| ERROR malformed
73+
#[used()]
74+
//~^ ERROR malformed
75+
#[crate_name]
76+
//~^ ERROR malformed
77+
#[doc]
78+
//~^ ERROR valid forms for the attribute are
79+
//~| WARN this was previously accepted by the compiler
80+
#[target_feature]
81+
//~^ ERROR malformed
82+
#[export_stable = 1]
83+
//~^ ERROR malformed
84+
#[link]
85+
//~^ ERROR attribute must be of the form
86+
//~| WARN this was previously accepted by the compiler
87+
#[link_name]
88+
//~^ ERROR malformed
89+
#[link_section]
90+
//~^ ERROR malformed
91+
#[coverage]
92+
//~^ ERROR malformed `coverage` attribute input
93+
#[no_sanitize]
94+
//~^ ERROR malformed
95+
#[ignore()]
96+
//~^ ERROR valid forms for the attribute are
97+
//~| WARN this was previously accepted by the compiler
98+
#[no_implicit_prelude = 23]
99+
//~^ ERROR malformed
100+
#[proc_macro = 18]
101+
//~^ ERROR malformed
102+
//~| ERROR the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
103+
#[cfg]
104+
//~^ ERROR is not followed by parentheses
105+
#[cfg_attr]
106+
//~^ ERROR malformed
107+
#[instruction_set]
108+
//~^ ERROR malformed
109+
#[patchable_function_entry]
110+
//~^ ERROR malformed
111+
fn test() {
112+
#[coroutine = 63] || {}
113+
//~^ ERROR malformed `coroutine` attribute input
114+
//~| ERROR mismatched types [E0308]
115+
}
116+
117+
#[proc_macro_attribute = 19]
118+
//~^ ERROR malformed
119+
//~| ERROR the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type
120+
fn test2() { }
121+
122+
#[proc_macro_derive]
123+
//~^ ERROR malformed `proc_macro_derive` attribute
124+
//~| ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
125+
pub fn test3() {}
126+
127+
#[rustc_layout_scalar_valid_range_start]
128+
//~^ ERROR malformed
129+
#[rustc_layout_scalar_valid_range_end]
130+
//~^ ERROR malformed
131+
#[must_not_suspend()]
132+
//~^ ERROR malformed
133+
#[cfi_encoding]
134+
//~^ ERROR malformed
135+
struct Test;
136+
137+
#[diagnostic::on_unimplemented]
138+
//~^ WARN missing options for `on_unimplemented` attribute
139+
#[diagnostic::on_unimplemented = 1]
140+
//~^ WARN malformed
141+
trait Hey {
142+
#[type_const = 1]
143+
//~^ ERROR malformed
144+
const HEY: usize = 5;
145+
}
146+
147+
struct Empty;
148+
#[diagnostic::do_not_recommend()]
149+
//~^ WARN does not expect any arguments
150+
impl Hey for Empty {
151+
152+
}
153+
154+
#[marker = 3]
155+
//~^ ERROR malformed
156+
#[fundamental()]
157+
//~^ ERROR malformed
158+
trait EmptyTrait {
159+
160+
}
161+
162+
163+
extern "C" {
164+
#[unsafe(ffi_pure = 1)]
165+
//~^ ERROR malformed
166+
#[link_ordinal]
167+
//~^ ERROR malformed
168+
pub fn baz();
169+
170+
#[unsafe(ffi_const = 1)]
171+
//~^ ERROR malformed
172+
#[linkage]
173+
//~^ ERROR malformed
174+
pub fn bar();
175+
}
176+
177+
#[allow]
178+
//~^ ERROR malformed
179+
#[expect]
180+
//~^ ERROR malformed
181+
#[warn]
182+
//~^ ERROR malformed
183+
#[deny]
184+
//~^ ERROR malformed
185+
#[forbid]
186+
//~^ ERROR malformed
187+
#[debugger_visualizer]
188+
//~^ ERROR invalid argument
189+
//~| ERROR malformed `debugger_visualizer` attribute input
190+
#[automatically_derived = 18]
191+
//~^ ERROR malformed
192+
mod yooo {
193+
194+
}
195+
196+
#[non_exhaustive = 1]
197+
//~^ ERROR malformed
198+
enum Slenum {
199+
200+
}
201+
202+
#[thread_local()]
203+
//~^ ERROR malformed
204+
static mut TLS: u8 = 42;
205+
206+
#[no_link()]
207+
//~^ ERROR malformed
208+
#[macro_use = 1]
209+
//~^ ERROR malformed
210+
extern crate wloop;
211+
//~^ ERROR can't find crate for `wloop` [E0463]
212+
213+
#[macro_export = 18]
214+
//~^ ERROR malformed `macro_export` attribute input
215+
#[allow_internal_unsafe = 1]
216+
//~^ ERROR malformed
217+
//~| ERROR allow_internal_unsafe side-steps the unsafe_code lint
218+
macro_rules! slump {
219+
() => {}
220+
}
221+
222+
fn main() {}

0 commit comments

Comments
 (0)