Skip to content

Commit 6cc268e

Browse files
committed
hir: consistent use and naming of lang items
This commit adjusts the naming of various lang items so that they are consistent and don't include prefixes containing the target or "LangItem". In addition, lang item variants are no longer exported from the `lang_items` module. Signed-off-by: David Wood <david@davidtw.co>
1 parent 9d74562 commit 6cc268e

File tree

43 files changed

+277
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+277
-299
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20582058

20592059
hir::GenericBound::LangItemTrait(
20602060
// ::std::future::Future<future_params>
2061-
hir::LangItem::FutureTraitLangItem,
2061+
hir::LangItem::Future,
20622062
span,
20632063
self.next_id(),
20642064
future_args,

src/librustc_codegen_ssa/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_data_structures::profiling::print_time_passes_entry;
3131
use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator};
3232
use rustc_hir as hir;
3333
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
34-
use rustc_hir::lang_items::StartFnLangItem;
34+
use rustc_hir::lang_items::LangItem;
3535
use rustc_index::vec::Idx;
3636
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
3737
use rustc_middle::middle::cstore::EncodedMetadata;
@@ -458,7 +458,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
458458
let (arg_argc, arg_argv) = get_argc_argv(cx, &mut bx);
459459

460460
let (start_fn, args) = if use_start_lang_item {
461-
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None);
461+
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None);
462462
let start_fn = cx.get_fn_addr(
463463
ty::Instance::resolve(
464464
cx.tcx(),

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::traits::*;
1010
use crate::MemFlags;
1111

1212
use rustc_ast as ast;
13-
use rustc_hir::lang_items;
13+
use rustc_hir::lang_items::LangItem;
1414
use rustc_index::vec::Idx;
1515
use rustc_middle::mir;
1616
use rustc_middle::mir::interpret::{AllocId, ConstValue, Pointer, Scalar};
@@ -420,14 +420,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
420420
let index = self.codegen_operand(&mut bx, index).immediate();
421421
// It's `fn panic_bounds_check(index: usize, len: usize)`,
422422
// and `#[track_caller]` adds an implicit third argument.
423-
(lang_items::PanicBoundsCheckFnLangItem, vec![index, len, location])
423+
(LangItem::PanicBoundsCheck, vec![index, len, location])
424424
}
425425
_ => {
426426
let msg_str = Symbol::intern(msg.description());
427427
let msg = bx.const_str(msg_str);
428428
// It's `pub fn panic(expr: &str)`, with the wide reference being passed
429429
// as two arguments, and `#[track_caller]` adds an implicit third argument.
430-
(lang_items::PanicFnLangItem, vec![msg.0, msg.1, location])
430+
(LangItem::Panic, vec![msg.0, msg.1, location])
431431
}
432432
};
433433

@@ -492,8 +492,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
492492

493493
// Obtain the panic entry point.
494494
// FIXME: dedup this with `codegen_assert_terminator` above.
495-
let def_id =
496-
common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem);
495+
let def_id = common::langcall(bx.tcx(), Some(span), "", LangItem::Panic);
497496
let instance = ty::Instance::mono(bx.tcx(), def_id);
498497
let fn_abi = FnAbi::of_instance(bx, instance, &[]);
499498
let llfn = bx.get_fn_addr(instance);

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::traits::*;
88
use crate::MemFlags;
99

1010
use rustc_apfloat::{ieee, Float, Round, Status};
11-
use rustc_hir::lang_items::ExchangeMallocFnLangItem;
11+
use rustc_hir::lang_items::LangItem;
1212
use rustc_middle::mir;
1313
use rustc_middle::ty::cast::{CastTy, IntTy};
1414
use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout};
@@ -507,7 +507,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
507507
let llty_ptr = bx.cx().backend_type(box_layout);
508508

509509
// Allocate space:
510-
let def_id = match bx.tcx().lang_items().require(ExchangeMallocFnLangItem) {
510+
let def_id = match bx.tcx().lang_items().require(LangItem::ExchangeMalloc) {
511511
Ok(id) => id,
512512
Err(s) => {
513513
bx.cx().sess().fatal(&format!("allocation of `{}` {}", box_layout.ty, s));

src/librustc_hir/lang_items.rs

Lines changed: 153 additions & 158 deletions
Large diffs are not rendered by default.

src/librustc_hir/weak_lang_items.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ macro_rules! weak_lang_items {
1515
lazy_static! {
1616
pub static ref WEAK_ITEMS_REFS: FxHashMap<Symbol, LangItem> = {
1717
let mut map = FxHashMap::default();
18-
$(map.insert(sym::$name, lang_items::$item);)*
18+
$(map.insert(sym::$name, LangItem::$item);)*
1919
map
2020
};
2121
}
@@ -46,7 +46,7 @@ impl LanguageItems {
4646
) }
4747

4848
weak_lang_items! {
49-
panic_impl, PanicImplLangItem, rust_begin_unwind;
50-
eh_personality, EhPersonalityLangItem, rust_eh_personality;
51-
oom, OomLangItem, rust_oom;
49+
panic_impl, PanicImpl, rust_begin_unwind;
50+
eh_personality, EhPersonality, rust_eh_personality;
51+
oom, Oom, rust_oom;
5252
}

src/librustc_middle/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn required(tcx: TyCtxt<'_>, lang_item: LangItem) -> bool {
5353
// symbols. Other panic runtimes ensure that the relevant symbols are
5454
// available to link things together, but they're never exercised.
5555
match tcx.sess.panic_strategy() {
56-
PanicStrategy::Abort => lang_item != LangItem::EhPersonalityLangItem,
56+
PanicStrategy::Abort => lang_item != LangItem::EhPersonality,
5757
PanicStrategy::Unwind => true,
5858
}
5959
}

src/librustc_middle/ty/adjustment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ty::subst::SubstsRef;
22
use crate::ty::{self, Ty, TyCtxt};
33
use rustc_hir as hir;
44
use rustc_hir::def_id::DefId;
5-
use rustc_hir::lang_items::{DerefMutTraitLangItem, DerefTraitLangItem};
5+
use rustc_hir::lang_items::LangItem;
66
use rustc_macros::HashStable;
77

88
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
@@ -118,8 +118,8 @@ pub struct OverloadedDeref<'tcx> {
118118
impl<'tcx> OverloadedDeref<'tcx> {
119119
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
120120
let trait_def_id = match self.mutbl {
121-
hir::Mutability::Not => tcx.require_lang_item(DerefTraitLangItem, None),
122-
hir::Mutability::Mut => tcx.require_lang_item(DerefMutTraitLangItem, None),
121+
hir::Mutability::Not => tcx.require_lang_item(LangItem::Deref, None),
122+
hir::Mutability::Mut => tcx.require_lang_item(LangItem::DerefMut, None),
123123
};
124124
let method_def_id = tcx
125125
.associated_items(trait_def_id)

src/librustc_middle/ty/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_hir::def::{DefKind, Res};
4040
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
4141
use rustc_hir::definitions::{DefPathHash, Definitions};
4242
use rustc_hir::intravisit::Visitor;
43-
use rustc_hir::lang_items::{self, PanicLocationLangItem};
43+
use rustc_hir::lang_items::LangItem;
4444
use rustc_hir::{HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate};
4545
use rustc_index::vec::{Idx, IndexVec};
4646
use rustc_macros::HashStable;
@@ -1538,7 +1538,7 @@ impl<'tcx> TyCtxt<'tcx> {
15381538
pub fn caller_location_ty(&self) -> Ty<'tcx> {
15391539
self.mk_imm_ref(
15401540
self.lifetimes.re_static,
1541-
self.type_of(self.require_lang_item(PanicLocationLangItem, None))
1541+
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
15421542
.subst(*self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
15431543
)
15441544
}
@@ -2185,12 +2185,12 @@ impl<'tcx> TyCtxt<'tcx> {
21852185

21862186
#[inline]
21872187
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
2188-
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem, None);
2188+
let def_id = self.require_lang_item(LangItem::OwnedBox, None);
21892189
self.mk_generic_adt(def_id, ty)
21902190
}
21912191

21922192
#[inline]
2193-
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Option<Ty<'tcx>> {
2193+
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option<Ty<'tcx>> {
21942194
let def_id = self.lang_items().require(item).ok()?;
21952195
Some(self.mk_generic_adt(def_id, ty))
21962196
}
@@ -2203,7 +2203,7 @@ impl<'tcx> TyCtxt<'tcx> {
22032203

22042204
#[inline]
22052205
pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
2206-
let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
2206+
let def_id = self.require_lang_item(LangItem::MaybeUninit, None);
22072207
self.mk_generic_adt(def_id, ty)
22082208
}
22092209

src/librustc_middle/ty/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
55
use rustc_errors::ErrorReported;
66
use rustc_hir::def::Namespace;
77
use rustc_hir::def_id::{CrateNum, DefId};
8-
use rustc_hir::lang_items::{DropInPlaceFnLangItem, FnOnceTraitLangItem};
8+
use rustc_hir::lang_items::LangItem;
99
use rustc_macros::HashStable;
1010

1111
use std::fmt;
@@ -408,7 +408,7 @@ impl<'tcx> Instance<'tcx> {
408408
}
409409

410410
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
411-
let def_id = tcx.require_lang_item(DropInPlaceFnLangItem, None);
411+
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
412412
let substs = tcx.intern_substs(&[ty.into()]);
413413
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
414414
}
@@ -419,7 +419,7 @@ impl<'tcx> Instance<'tcx> {
419419
substs: ty::SubstsRef<'tcx>,
420420
) -> Instance<'tcx> {
421421
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
422-
let fn_once = tcx.require_lang_item(FnOnceTraitLangItem, None);
422+
let fn_once = tcx.require_lang_item(LangItem::FnOnce, None);
423423
let call_once = tcx
424424
.associated_items(fn_once)
425425
.in_definition_order()

0 commit comments

Comments
 (0)