-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #87875 - asquared31415:generic-lang-items, r=cjgillot
Improve detection of generics on lang items Adds detection for the required generics for all lang items. Many lang items require an exact or minimum amount of generic arguments and if they don't exist, the compiler will ICE. This does not add any additional validation about bounds on generics or any other lang item restrictions. Fixes one of the ICEs in #87573 cc `@FabianWolff`
- Loading branch information
Showing
12 changed files
with
330 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// build-pass | ||
|
||
#![feature(lang_items,no_core)] | ||
#![no_core] | ||
#![crate_type="lib"] | ||
|
||
#[lang = "sized"] | ||
trait MySized {} | ||
|
||
#[lang = "copy"] | ||
trait MyCopy {} | ||
|
||
#[lang = "drop"] | ||
trait MyDrop<T> {} | ||
|
||
struct S; | ||
|
||
impl<T> MyDrop<T> for S {} | ||
|
||
#[lang = "i32"] | ||
impl<'a> i32 { | ||
fn foo() {} | ||
} | ||
|
||
fn bar() { | ||
i32::foo(); | ||
S; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Checks whether declaring a lang item with the wrong number | ||
// of generic arguments crashes the compiler (issue #83893, #87573, and part of #9307). | ||
|
||
#![feature(lang_items, no_core)] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
#[lang = "sized"] | ||
trait MySized {} | ||
|
||
#[lang = "add"] | ||
trait MyAdd<'a, T> {} | ||
//~^^ ERROR: `add` language item must be applied to a trait with 1 generic argument [E0718] | ||
|
||
#[lang = "drop_in_place"] | ||
//~^ ERROR `drop_in_place` language item must be applied to a function with at least 1 generic | ||
fn my_ptr_drop() {} | ||
|
||
#[lang = "index"] | ||
trait MyIndex<'a, T> {} | ||
//~^^ ERROR: `index` language item must be applied to a trait with 1 generic argument [E0718] | ||
|
||
#[lang = "phantom_data"] | ||
//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument | ||
struct MyPhantomData<T, U>; | ||
//~^ ERROR parameter `T` is never used | ||
//~| ERROR parameter `U` is never used | ||
|
||
fn ice() { | ||
// Use add | ||
let r = 5; | ||
let a = 6; | ||
r + a; | ||
|
||
// Use drop in place | ||
my_ptr_drop(); | ||
|
||
// Use index | ||
let arr = [0; 5]; | ||
let _ = arr[2]; | ||
|
||
// Use phantomdata | ||
let _ = MyPhantomData::<(), i32>; | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/ui/lang-items/lang-item-generic-requirements.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
error[E0718]: `add` language item must be applied to a trait with 1 generic argument | ||
--> $DIR/lang-item-generic-requirements.rs:11:1 | ||
| | ||
LL | #[lang = "add"] | ||
| ^^^^^^^^^^^^^^^ | ||
LL | trait MyAdd<'a, T> {} | ||
| ------- this trait has 2 generic arguments | ||
|
||
error[E0718]: `drop_in_place` language item must be applied to a function with at least 1 generic argument | ||
--> $DIR/lang-item-generic-requirements.rs:15:1 | ||
| | ||
LL | #[lang = "drop_in_place"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | fn my_ptr_drop() {} | ||
| - this function has 0 generic arguments | ||
|
||
error[E0718]: `index` language item must be applied to a trait with 1 generic argument | ||
--> $DIR/lang-item-generic-requirements.rs:19:1 | ||
| | ||
LL | #[lang = "index"] | ||
| ^^^^^^^^^^^^^^^^^ | ||
LL | trait MyIndex<'a, T> {} | ||
| ------- this trait has 2 generic arguments | ||
|
||
error[E0718]: `phantom_data` language item must be applied to a struct with 1 generic argument | ||
--> $DIR/lang-item-generic-requirements.rs:23:1 | ||
| | ||
LL | #[lang = "phantom_data"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | struct MyPhantomData<T, U>; | ||
| ------ this struct has 2 generic arguments | ||
|
||
error[E0392]: parameter `T` is never used | ||
--> $DIR/lang-item-generic-requirements.rs:25:22 | ||
| | ||
LL | struct MyPhantomData<T, U>; | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `T` or referring to it in a field | ||
= help: if you intended `T` to be a const parameter, use `const T: usize` instead | ||
|
||
error[E0392]: parameter `U` is never used | ||
--> $DIR/lang-item-generic-requirements.rs:25:25 | ||
| | ||
LL | struct MyPhantomData<T, U>; | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `U` or referring to it in a field | ||
= help: if you intended `U` to be a const parameter, use `const U: usize` instead | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors have detailed explanations: E0392, E0718. | ||
For more information about an error, try `rustc --explain E0392`. |
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/test/ui/lang-items/wrong-number-generic-args-add.stderr
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.