]> git.lizzy.rs Git - rust.git/blob - tests/ui/lang-items/lang-item-generic-requirements.rs
Rollup merge of #107692 - Swatinem:printsizeyield, r=compiler-errors
[rust.git] / tests / 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
26 #[lang = "owned_box"]
27 //~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument
28 struct Foo;
29
30 // When the `start` lang item is missing generics very odd things can happen, especially when
31 // it comes to cross-crate monomorphization
32 #[lang = "start"]
33 //~^ ERROR `start` language item must be applied to a function with 1 generic argument [E0718]
34 fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
35     0
36 }
37
38 fn ice() {
39     // Use add
40     let r = 5;
41     let a = 6;
42     r + a;
43
44     // Use drop in place
45     my_ptr_drop();
46
47     // Use index
48     let arr = [0; 5];
49     let _ = arr[2];
50
51     // Use phantomdata
52     let _ = MyPhantomData::<(), i32>;
53
54     // Use Foo
55     let _: () = Foo;
56 }
57
58 // use `start`
59 fn main() {}