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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::ty::{self, TyCtxt};
use rustc_hir::def_id::DefId;
use rustc_hir::LangItem;
use rustc_span::Span;
use rustc_target::spec::PanicStrategy;
impl<'tcx> TyCtxt<'tcx> {
pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId {
self.lang_items().require(lang_item).unwrap_or_else(|err| {
if let Some(span) = span {
self.sess.span_fatal(span, err.to_string())
} else {
self.sess.fatal(err.to_string())
}
})
}
pub fn fn_trait_kind_from_lang_item(self, id: DefId) -> Option<ty::ClosureKind> {
let items = self.lang_items();
match Some(id) {
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),
x if x == items.fn_mut_trait() => Some(ty::ClosureKind::FnMut),
x if x == items.fn_once_trait() => Some(ty::ClosureKind::FnOnce),
_ => None,
}
}
pub fn is_weak_lang_item(self, item_def_id: DefId) -> bool {
self.lang_items().is_weak_lang_item(item_def_id)
}
}
pub fn required(tcx: TyCtxt<'_>, lang_item: LangItem) -> bool {
match tcx.sess.panic_strategy() {
PanicStrategy::Abort => {
lang_item != LangItem::EhPersonality && lang_item != LangItem::EhCatchTypeinfo
}
PanicStrategy::Unwind => true,
}
}