File: assoc-lang-items.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (35 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Check that associated items can be marked as lang items, so that they don't have to be looked up
//! by name or by definition order indirectly.
//!
//! This test is not *quite* high-fidelity: it checks that you can use lang items on associated
//! items by looking at the error message *as a proxy*. That is, the error message is about
//! undefined lang items and not invalid attribute target, indicating that it has reached lang item
//! machinery (which is relying on knowing the implementation detail). However, it's annoying to
//! write a full-fidelity test for this, so I think this is acceptable even though it's not *great*.
//!
//! This was implemented in <https://github.com/rust-lang/rust/pull/72559> to help with
//! <https://github.com/rust-lang/rust/issues/70718>, which is itself relevant for e.g. `Fn::Output`
//! or `Future::Output` or specific use cases like [Use `T`'s discriminant type in
//! `mem::Discriminant<T>` instead of `u64`](https://github.com/rust-lang/rust/pull/70705).

#![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() {}