Implement associated lang items
Fixes #70718 This commit allows making associated items (e.g. associated functions and types) into lang items via the `#[lang]` attribute. This allows such items to be accessed directly, rather than by iterating over the parent item's associated items. I've added `FnOnce::Output` as a lang item, and updated one old usage to use the new lang item. The remaining uses can be updated separately.
This commit is contained in:
parent
d8ed1b03c2
commit
a13d4678fe
7 changed files with 94 additions and 28 deletions
21
src/test/ui/assoc-lang-items.rs
Normal file
21
src/test/ui/assoc-lang-items.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#![feature(lang_items)]
|
||||
|
||||
trait Foo {
|
||||
#[lang = "dummy_lang_item_1"] //~ ERROR definition
|
||||
fn foo() {}
|
||||
|
||||
#[lang = "dummy_lang_item_2"] //~ ERROR definition
|
||||
fn bar();
|
||||
|
||||
#[lang = "dummy_lang_item_3"] //~ ERROR definition
|
||||
type MyType;
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl Bar {
|
||||
#[lang = "dummy_lang_item_4"] //~ ERROR definition
|
||||
fn test() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
27
src/test/ui/assoc-lang-items.stderr
Normal file
27
src/test/ui/assoc-lang-items.stderr
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
error[E0522]: definition of an unknown language item: `dummy_lang_item_1`
|
||||
--> $DIR/assoc-lang-items.rs:4:5
|
||||
|
|
||||
LL | #[lang = "dummy_lang_item_1"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_1`
|
||||
|
||||
error[E0522]: definition of an unknown language item: `dummy_lang_item_2`
|
||||
--> $DIR/assoc-lang-items.rs:7:5
|
||||
|
|
||||
LL | #[lang = "dummy_lang_item_2"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_2`
|
||||
|
||||
error[E0522]: definition of an unknown language item: `dummy_lang_item_3`
|
||||
--> $DIR/assoc-lang-items.rs:10:5
|
||||
|
|
||||
LL | #[lang = "dummy_lang_item_3"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_3`
|
||||
|
||||
error[E0522]: definition of an unknown language item: `dummy_lang_item_4`
|
||||
--> $DIR/assoc-lang-items.rs:17:5
|
||||
|
|
||||
LL | #[lang = "dummy_lang_item_4"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_4`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0522`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue