]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lang-items/lang-item-generic-requirements.rs
Rollup merge of #104062 - notriddle:notriddle/sidebar-filler, r=GuillaumeGomez
[rust.git] / src / test / ui / lang-items / lang-item-generic-requirements.rs
1 // Checks that declaring a lang item with the wrong number of generic arguments errors rather than
2 // crashing (issue #83474, #83893, #87573, part of #9307, #79559).
3
4 #![feature(lang_items, no_core)]
5 #![no_core]
6
7 #[lang = "sized"]
8 trait MySized {}
9
10 #[lang = "add"]
11 trait MyAdd<'a, T> {}
12 //~^^ ERROR: `add` language item must be applied to a trait with 1 generic argument [E0718]
13
14 #[lang = "drop_in_place"]
15 //~^ ERROR `drop_in_place` language item must be applied to a function with at least 1 generic
16 fn my_ptr_drop() {}
17
18 #[lang = "index"]
19 trait MyIndex<'a, T> {}
20 //~^^ ERROR: `index` language item must be applied to a trait with 1 generic argument [E0718]
21
22 #[lang = "phantom_data"]
23 //~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
24 struct MyPhantomData<T, U>;
25 //~^ ERROR parameter `T` is never used
26 //~| ERROR parameter `U` is never used
27
28 #[lang = "owned_box"]
29 //~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument
30 struct Foo;
31
32 // When the `start` lang item is missing generics very odd things can happen, especially when
33 // it comes to cross-crate monomorphization
34 #[lang = "start"]
35 //~^ ERROR `start` language item must be applied to a function with 1 generic argument [E0718]
36 fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
37     0
38 }
39
40 fn ice() {
41     // Use add
42     let r = 5;
43     let a = 6;
44     r + a;
45
46     // Use drop in place
47     my_ptr_drop();
48
49     // Use index
50     let arr = [0; 5];
51     let _ = arr[2];
52
53     // Use phantomdata
54     let _ = MyPhantomData::<(), i32>;
55
56     // Use Foo
57     let _: () = Foo;
58 }
59
60 // use `start`
61 fn main() {}