Skip to content

Commit 2ae05d3

Browse files
committed
Auto merge of #32264 - GuillaumeGomez:lang_item, r=nikomatsakis
Lang item Fixes #32033
2 parents 8fc0554 + b2fd882 commit 2ae05d3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc/diagnostics.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,23 @@ each method; it is not possible to annotate the entire impl with an `#[inline]`
19621962
attribute.
19631963
"##,
19641964

1965+
E0522: r##"
1966+
The lang attribute is intended for marking special items that are built-in to
1967+
Rust itself. This includes special traits (like `Copy` and `Sized`) that affect
1968+
how the compiler behaves, as well as special functions that may be automatically
1969+
invoked (such as the handler for out-of-bounds accesses when indexing a slice).
1970+
Erroneous code example:
1971+
1972+
```compile_fail
1973+
#![feature(lang_items)]
1974+
1975+
#[lang = "cookie"]
1976+
fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
1977+
loop {}
1978+
}
1979+
```
1980+
"##,
1981+
19651982
}
19661983

19671984

src/librustc/middle/lang_items.rs

+5
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ impl<'a, 'v, 'tcx> Visitor<'v> for LanguageItemCollector<'a, 'tcx> {
158158

159159
if let Some(item_index) = item_index {
160160
self.collect_item(item_index, self.ast_map.local_def_id(item.id))
161+
} else {
162+
let span = self.ast_map.span(item.id);
163+
span_err!(self.session, span, E0522,
164+
"definition of an unknown language item: `{}`.",
165+
&value[..]);
161166
}
162167
}
163168
}

0 commit comments

Comments
 (0)