]> git.proxmox.com Git - rustc.git/blob - src/test/ui/lang-items/lang-item-generic-requirements.rs
New upstream version 1.57.0+dfsg1
[rustc.git] / src / test / ui / lang-items / lang-item-generic-requirements.rs
1 // Checks that declaring a lang item with the wrong number
2 // of generic arguments errors rather than crashing (issue #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 // When the `start` lang item is missing generics very odd things can happen, especially when
29 // it comes to cross-crate monomorphization
30 #[lang = "start"]
31 //~^ ERROR `start` language item must be applied to a function with 1 generic argument [E0718]
32 fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
33 0
34 }
35
36 fn ice() {
37 // Use add
38 let r = 5;
39 let a = 6;
40 r + a;
41
42 // Use drop in place
43 my_ptr_drop();
44
45 // Use index
46 let arr = [0; 5];
47 let _ = arr[2];
48
49 // Use phantomdata
50 let _ = MyPhantomData::<(), i32>;
51 }
52
53 // use `start`
54 fn main() {}