2022-04-06 02:45:07 +00:00
|
|
|
// Checks that declaring a lang item with the wrong number of generic arguments errors rather than
|
|
|
|
// crashing (issue #83474, #83893, #87573, part of #9307, #79559).
|
2021-08-15 01:38:37 +00:00
|
|
|
|
|
|
|
#![feature(lang_items, no_core)]
|
|
|
|
#![no_core]
|
|
|
|
|
|
|
|
#[lang = "sized"]
|
|
|
|
trait MySized {}
|
|
|
|
|
|
|
|
#[lang = "add"]
|
|
|
|
trait MyAdd<'a, T> {}
|
2024-04-17 10:30:45 +00:00
|
|
|
//~^^ ERROR: `add` lang item must be applied to a trait with 1 generic argument [E0718]
|
2021-08-15 01:38:37 +00:00
|
|
|
|
|
|
|
#[lang = "drop_in_place"]
|
2024-04-17 10:30:45 +00:00
|
|
|
//~^ ERROR `drop_in_place` lang item must be applied to a function with at least 1 generic
|
2021-08-15 01:38:37 +00:00
|
|
|
fn my_ptr_drop() {}
|
|
|
|
|
|
|
|
#[lang = "index"]
|
|
|
|
trait MyIndex<'a, T> {}
|
2024-04-17 10:30:45 +00:00
|
|
|
//~^^ ERROR: `index` lang item must be applied to a trait with 1 generic argument [E0718]
|
2021-08-15 01:38:37 +00:00
|
|
|
|
|
|
|
#[lang = "phantom_data"]
|
2024-04-17 10:30:45 +00:00
|
|
|
//~^ ERROR `phantom_data` lang item must be applied to a struct with 1 generic argument
|
2021-08-15 01:38:37 +00:00
|
|
|
struct MyPhantomData<T, U>;
|
2023-10-31 13:45:26 +00:00
|
|
|
//~^ ERROR `T` is never used
|
|
|
|
//~| ERROR `U` is never used
|
2021-08-15 01:38:37 +00:00
|
|
|
|
2022-04-06 02:45:07 +00:00
|
|
|
#[lang = "owned_box"]
|
2024-04-17 10:30:45 +00:00
|
|
|
//~^ ERROR `owned_box` lang item must be applied to a struct with at least 1 generic argument
|
2022-04-06 02:45:07 +00:00
|
|
|
struct Foo;
|
|
|
|
|
2021-09-06 07:35:37 +00:00
|
|
|
// When the `start` lang item is missing generics very odd things can happen, especially when
|
|
|
|
// it comes to cross-crate monomorphization
|
|
|
|
#[lang = "start"]
|
2024-04-17 10:30:45 +00:00
|
|
|
//~^ ERROR `start` lang item must be applied to a function with 1 generic argument [E0718]
|
2021-09-06 07:35:37 +00:00
|
|
|
fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2021-08-15 01:38:37 +00:00
|
|
|
fn ice() {
|
|
|
|
// Use add
|
|
|
|
let r = 5;
|
|
|
|
let a = 6;
|
2023-10-31 13:45:26 +00:00
|
|
|
r + a; //~ ERROR cannot add
|
2021-08-15 01:38:37 +00:00
|
|
|
|
|
|
|
// Use drop in place
|
|
|
|
my_ptr_drop();
|
|
|
|
|
|
|
|
// Use index
|
|
|
|
let arr = [0; 5];
|
|
|
|
let _ = arr[2];
|
|
|
|
|
|
|
|
// Use phantomdata
|
|
|
|
let _ = MyPhantomData::<(), i32>;
|
2022-04-06 02:45:07 +00:00
|
|
|
|
|
|
|
// Use Foo
|
|
|
|
let _: () = Foo;
|
2021-08-15 01:38:37 +00:00
|
|
|
}
|
2021-09-06 07:35:37 +00:00
|
|
|
|
|
|
|
// use `start`
|
|
|
|
fn main() {}
|