1//! Defines lang items.2//!3//! Language items are items that represent concepts intrinsic to the language4//! itself. Examples are:5//!6//! * Traits that specify "kinds"; e.g., `Sync`, `Send`.7//! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`.8//! * Functions called by the compiler itself.910use rustc_data_structures::fx::FxIndexMap;11use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};12use rustc_macros::{BlobDecodable, Encodable, PrintAttribute, StableHash};13use rustc_span::def_id::DefId;14use rustc_span::{Symbol, kw, sym};1516use crate::PrintAttribute;17use crate::target::{AssocCtxt, MethodKind, Target};1819/// All of the lang items, defined or not.20/// Defined lang items can come from the current crate or its dependencies.21#[derive(StableHash, Debug)]22pub struct LanguageItems {23 /// Mappings from lang items to their possibly found [`DefId`]s.24 /// The index corresponds to the order in [`LangItem`].25 items: [Option<DefId>; std::mem::variant_count::<LangItem>()],26 reverse_items: FxIndexMap<DefId, LangItem>,27 /// Lang items that were not found during collection.28 pub missing: Vec<LangItem>,29}3031impl LanguageItems {32 /// Construct an empty collection of lang items and no missing ones.33 pub fn new() -> Self {34 Self {35 items: [None; std::mem::variant_count::<LangItem>()],36 reverse_items: FxIndexMap::default(),37 missing: Vec::new(),38 }39 }4041 pub fn get(&self, item: LangItem) -> Option<DefId> {42 self.items[item as usize]43 }4445 pub fn set(&mut self, item: LangItem, def_id: DefId) {46 self.items[item as usize] = Some(def_id);47 let preexisting = self.reverse_items.insert(def_id, item);4849 // This needs to be a bijection.50 if let Some(preexisting) = preexisting {51 panic!(52 "For the bijection of LangItem <=> DefId to work,\53 one item DefId may only be assigned one LangItem. \54 Separate the LangItem definitions for {item:?} and {preexisting:?}."55 );56 }57 }5859 pub fn from_def_id(&self, def_id: DefId) -> Option<LangItem> {60 self.reverse_items.get(&def_id).copied()61 }6263 pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> {64 self.items65 .iter()66 .enumerate()67 .filter_map(|(i, id)| id.map(|id| (LangItem::from_u32(i as u32).unwrap(), id)))68 }6970 /// Remove any missing items from the list that aren't actually missing71 pub fn trim_missing(&mut self) {72 self.missing.retain(|&item| self.items[item as usize].is_none());73 }74}7576// The actual lang items defined come at the end of this file in one handy table.77// So you probably just want to nip down to the end.78macro_rules! language_item_table {79 (80 $( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )*81 ) => {82 /// A representation of all the valid lang items in Rust.83 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, BlobDecodable, PrintAttribute)]84 pub enum LangItem {85 $(86 #[doc = concat!("The `", stringify!($name), "` lang item.")]87 $(#[$attr])*88 $variant,89 )*90 }9192 impl LangItem {93 fn from_u32(u: u32) -> Option<LangItem> {94 // This implementation is clumsy, but makes no assumptions95 // about how discriminant tags are allocated within the96 // range `0 .. std::mem::variant_count::<LangItem>()`.97 $(if u == LangItem::$variant as u32 {98 return Some(LangItem::$variant)99 })*100 None101 }102103 /// Returns the `name` symbol in `#[lang = "$name"]`.104 /// For example, [`LangItem::PartialEq`]`.name()`105 /// would result in [`sym::eq`] since it is `#[lang = "eq"]`.106 pub fn name(self) -> Symbol {107 match self {108 $( LangItem::$variant => $module::$name, )*109 }110 }111112 /// Opposite of [`LangItem::name`]113 pub fn from_name(name: Symbol) -> Option<Self> {114 match name {115 $( $module::$name => Some(LangItem::$variant), )*116 _ => None,117 }118 }119120 /// Returns the name of the `LangItem` enum variant.121 // This method is used by Clippy for internal lints.122 pub fn variant_name(self) -> &'static str {123 match self {124 $( LangItem::$variant => stringify!($variant), )*125 }126 }127128 pub fn target(self) -> Target {129 match self {130 $( LangItem::$variant => $target, )*131 }132 }133134 pub fn required_generics(&self) -> GenericRequirement {135 match self {136 $( LangItem::$variant => $generics, )*137 }138 }139 }140141 impl LanguageItems {142 $(143 #[doc = concat!("Returns the [`DefId`] of the `", stringify!($name), "` lang item if it is defined.")]144 pub fn $method(&self) -> Option<DefId> {145 self.items[LangItem::$variant as usize]146 }147 )*148 }149 }150}151152impl StableHash for LangItem {153 fn stable_hash<Hcx: StableHashCtxt>(&self, _: &mut Hcx, hasher: &mut StableHasher) {154 ::std::hash::Hash::hash(self, hasher);155 }156}157158language_item_table! {159// Variant name, Name, Getter method name, Target Generic requirements;160 Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);161 MetaSized, sym::meta_sized, meta_sized_trait, Target::Trait, GenericRequirement::Exact(0);162 PointeeSized, sym::pointee_sized, pointee_sized_trait, Target::Trait, GenericRequirement::Exact(0);163 Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);164 AlignOf, sym::mem_align_const, align_const, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);165 SizeOf, sym::mem_size_const, size_const, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);166 OffsetOf, sym::offset_of, offset_of, Target::Fn, GenericRequirement::Exact(1);167 /// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").168 StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;169 Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);170 Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;171 CloneFn, sym::clone_fn, clone_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;172 UseCloned, sym::use_cloned, use_cloned_trait, Target::Trait, GenericRequirement::None;173 TrivialClone, sym::trivial_clone, trivial_clone_trait, Target::Trait, GenericRequirement::None;174 Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);175 DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;176 /// The associated item of the `DiscriminantKind` trait.177 Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None;178179 PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None;180 Metadata, sym::metadata_type, metadata_type, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None;181 DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None;182183 NonNull, sym::non_null, non_null_trait, Target::Struct, GenericRequirement::Exact(1);184185 Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0);186 UnsafeUnpin, sym::unsafe_unpin, unsafe_unpin_trait, Target::Trait, GenericRequirement::Exact(0);187188 FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0);189 FnPtrAsPtr, sym::fn_ptr_as_ptr, fn_ptr_as_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;190 FnPtrFromPtr, sym::fn_ptr_from_ptr, fn_ptr_from_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;191 Code, sym::code, code, Target::ForeignTy, GenericRequirement::None;192193 Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None;194 Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None;195 AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::None;196 AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);197198 CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);199 DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);200201 TryAsDyn, sym::try_as_dyn, try_as_dyn, Target::Trait, GenericRequirement::Exact(1);202203 // lang items relating to transmutability204 TransmuteOpts, sym::transmute_opts, transmute_opts, Target::Struct, GenericRequirement::Exact(0);205 TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(2);206207 Add, sym::add, add_trait, Target::Trait, GenericRequirement::Exact(1);208 Sub, sym::sub, sub_trait, Target::Trait, GenericRequirement::Exact(1);209 Mul, sym::mul, mul_trait, Target::Trait, GenericRequirement::Exact(1);210 Div, sym::div, div_trait, Target::Trait, GenericRequirement::Exact(1);211 Rem, sym::rem, rem_trait, Target::Trait, GenericRequirement::Exact(1);212 Neg, sym::neg, neg_trait, Target::Trait, GenericRequirement::Exact(0);213 Not, sym::not, not_trait, Target::Trait, GenericRequirement::Exact(0);214 BitXor, sym::bitxor, bitxor_trait, Target::Trait, GenericRequirement::Exact(1);215 BitAnd, sym::bitand, bitand_trait, Target::Trait, GenericRequirement::Exact(1);216 BitOr, sym::bitor, bitor_trait, Target::Trait, GenericRequirement::Exact(1);217 Shl, sym::shl, shl_trait, Target::Trait, GenericRequirement::Exact(1);218 Shr, sym::shr, shr_trait, Target::Trait, GenericRequirement::Exact(1);219 AddAssign, sym::add_assign, add_assign_trait, Target::Trait, GenericRequirement::Exact(1);220 SubAssign, sym::sub_assign, sub_assign_trait, Target::Trait, GenericRequirement::Exact(1);221 MulAssign, sym::mul_assign, mul_assign_trait, Target::Trait, GenericRequirement::Exact(1);222 DivAssign, sym::div_assign, div_assign_trait, Target::Trait, GenericRequirement::Exact(1);223 RemAssign, sym::rem_assign, rem_assign_trait, Target::Trait, GenericRequirement::Exact(1);224 BitXorAssign, sym::bitxor_assign, bitxor_assign_trait, Target::Trait, GenericRequirement::Exact(1);225 BitAndAssign, sym::bitand_assign, bitand_assign_trait, Target::Trait, GenericRequirement::Exact(1);226 BitOrAssign, sym::bitor_assign, bitor_assign_trait, Target::Trait, GenericRequirement::Exact(1);227 ShlAssign, sym::shl_assign, shl_assign_trait, Target::Trait, GenericRequirement::Exact(1);228 ShrAssign, sym::shr_assign, shr_assign_trait, Target::Trait, GenericRequirement::Exact(1);229 Index, sym::index, index_trait, Target::Trait, GenericRequirement::Exact(1);230 IndexMut, sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1);231232 UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None;233 CovariantUnsafeCell, sym::covariant_unsafe_cell, covariant_unsafe_cell_type, Target::Struct, GenericRequirement::Exact(1);234 UnsafePinned, sym::unsafe_pinned, unsafe_pinned_type, Target::Struct, GenericRequirement::None;235236 VaArgSafe, sym::va_arg_safe, va_arg_safe, Target::Trait, GenericRequirement::None;237 VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None;238239 Complex, sym::complex, complex, Target::Struct, GenericRequirement::Exact(1);240241 Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);242 DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);243 DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0);244 DerefTarget, sym::deref_target, deref_target, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None;245 Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None;246 ReceiverTarget, sym::receiver_target, receiver_target, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None;247 LegacyReceiver, sym::legacy_receiver, legacy_receiver_trait, Target::Trait, GenericRequirement::None;248249 Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1);250 FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);251 FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1);252 FnStatic, sym::fn_static, fn_static_trait, Target::Trait, GenericRequirement::Exact(1);253254 AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);255 AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);256 AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);257 AsyncFnOnceOutput, sym::async_fn_once_output, async_fn_once_output, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1);258 CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1);259 CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(2);260 AsyncFnKindHelper, sym::async_fn_kind_helper, async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);261 AsyncFnKindUpvars, sym::async_fn_kind_upvars, async_fn_kind_upvars, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(5);262263 FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None;264265 Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);266 FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0);267 Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);268 FutureOutput, sym::future_output, future_output, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(0);269 AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);270271 CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;272 Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Exact(1);273 CoroutineReturn, sym::coroutine_return, coroutine_return, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1);274 CoroutineYield, sym::coroutine_yield, coroutine_yield, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1);275 CoroutineResume, sym::coroutine_resume, coroutine_resume, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;276277 Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;278 Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;279280 OrderingEnum, sym::Ordering, ordering_enum, Target::Enum, GenericRequirement::Exact(0);281 PartialEq, sym::eq, eq_trait, Target::Trait, GenericRequirement::Exact(1);282 PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait, GenericRequirement::Exact(1);283 CVoid, sym::c_void, c_void, Target::Enum, GenericRequirement::None;284285 Type, sym::type_info, type_struct, Target::Struct, GenericRequirement::None;286 TypeGeneric, sym::type_info_generic, type_generic, Target::Enum, GenericRequirement::None;287 TypeId, sym::type_id, type_id, Target::Struct, GenericRequirement::None;288289 // A number of panic-related lang items. The `panic` item corresponds to divide-by-zero and290 // various panic cases with `match`. The `panic_bounds_check` item is for indexing arrays.291 //292 // The `begin_unwind` lang item has a predefined symbol name and is sort of a "weak lang item"293 // in the sense that a crate is not required to have it defined to use it, but a final product294 // is required to define it somewhere. Additionally, there are restrictions on crates that use295 // a weak lang item, but do not have it defined.296 Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);297 PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0);298 PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None;299 PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;300 ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;301 PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);302 PanicMisalignedPointerDereference, sym::panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference_fn, Target::Fn, GenericRequirement::Exact(0);303 PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None;304 PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None;305 PanicImpl, sym::panic_impl, panic_impl, Target::ForeignFn, GenericRequirement::None;306 PanicCannotUnwind, sym::panic_cannot_unwind, panic_cannot_unwind, Target::Fn, GenericRequirement::Exact(0);307 PanicInCleanup, sym::panic_in_cleanup, panic_in_cleanup, Target::Fn, GenericRequirement::Exact(0);308 /// Constant panic messages, used for codegen of MIR asserts.309 PanicAddOverflow, sym::panic_const_add_overflow, panic_const_add_overflow, Target::Fn, GenericRequirement::None;310 PanicSubOverflow, sym::panic_const_sub_overflow, panic_const_sub_overflow, Target::Fn, GenericRequirement::None;311 PanicMulOverflow, sym::panic_const_mul_overflow, panic_const_mul_overflow, Target::Fn, GenericRequirement::None;312 PanicDivOverflow, sym::panic_const_div_overflow, panic_const_div_overflow, Target::Fn, GenericRequirement::None;313 PanicRemOverflow, sym::panic_const_rem_overflow, panic_const_rem_overflow, Target::Fn, GenericRequirement::None;314 PanicNegOverflow, sym::panic_const_neg_overflow, panic_const_neg_overflow, Target::Fn, GenericRequirement::None;315 PanicShrOverflow, sym::panic_const_shr_overflow, panic_const_shr_overflow, Target::Fn, GenericRequirement::None;316 PanicShlOverflow, sym::panic_const_shl_overflow, panic_const_shl_overflow, Target::Fn, GenericRequirement::None;317 PanicDivZero, sym::panic_const_div_by_zero, panic_const_div_by_zero, Target::Fn, GenericRequirement::None;318 PanicRemZero, sym::panic_const_rem_by_zero, panic_const_rem_by_zero, Target::Fn, GenericRequirement::None;319 PanicCoroutineResumed, sym::panic_const_coroutine_resumed, panic_const_coroutine_resumed, Target::Fn, GenericRequirement::None;320 PanicAsyncFnResumed, sym::panic_const_async_fn_resumed, panic_const_async_fn_resumed, Target::Fn, GenericRequirement::None;321 PanicAsyncGenFnResumed, sym::panic_const_async_gen_fn_resumed, panic_const_async_gen_fn_resumed, Target::Fn, GenericRequirement::None;322 PanicGenFnNone, sym::panic_const_gen_fn_none, panic_const_gen_fn_none, Target::Fn, GenericRequirement::None;323 PanicCoroutineResumedPanic, sym::panic_const_coroutine_resumed_panic, panic_const_coroutine_resumed_panic, Target::Fn, GenericRequirement::None;324 PanicAsyncFnResumedPanic, sym::panic_const_async_fn_resumed_panic, panic_const_async_fn_resumed_panic, Target::Fn, GenericRequirement::None;325 PanicAsyncGenFnResumedPanic, sym::panic_const_async_gen_fn_resumed_panic, panic_const_async_gen_fn_resumed_panic, Target::Fn, GenericRequirement::None;326 PanicGenFnNonePanic, sym::panic_const_gen_fn_none_panic, panic_const_gen_fn_none_panic, Target::Fn, GenericRequirement::None;327 PanicNullPointerDereference, sym::panic_null_pointer_dereference, panic_null_pointer_dereference, Target::Fn, GenericRequirement::None;328 PanicNullReferenceConstructed, sym::panic_null_reference_constructed, panic_null_reference_constructed, Target::Fn, GenericRequirement::None;329 PanicInvalidEnumConstruction, sym::panic_invalid_enum_construction, panic_invalid_enum_construction, Target::Fn, GenericRequirement::None;330 PanicCoroutineResumedDrop, sym::panic_const_coroutine_resumed_drop, panic_const_coroutine_resumed_drop, Target::Fn, GenericRequirement::None;331 PanicAsyncFnResumedDrop, sym::panic_const_async_fn_resumed_drop, panic_const_async_fn_resumed_drop, Target::Fn, GenericRequirement::None;332 PanicAsyncGenFnResumedDrop, sym::panic_const_async_gen_fn_resumed_drop, panic_const_async_gen_fn_resumed_drop, Target::Fn, GenericRequirement::None;333 PanicGenFnNoneDrop, sym::panic_const_gen_fn_none_drop, panic_const_gen_fn_none_drop, Target::Fn, GenericRequirement::None;334 /// libstd panic entry point. Necessary for const eval to be able to catch it335 BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None;336337 // Lang items needed for `format_args!()`.338 FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None;339 FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None;340341 // Compiler-generated drop glue function, aka `core::ptr::drop_glue`342 DropGlue, sym::drop_glue, drop_glue_fn, Target::Fn, GenericRequirement::Exact(1);343 AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None;344345 /// For all binary crates without `#![no_main]`, Rust will generate a "main" function.346 /// The exact name and signature are target-dependent. The "main" function will invoke347 /// this lang item, passing it the `argc` and `argv` (or null, if those don't exist348 /// on the current target) as well as the user-defined `fn main` from the binary crate.349 Start, sym::start, start_fn, Target::Fn, GenericRequirement::Exact(1);350351 EhPersonality, sym::eh_personality, eh_personality, Target::Fn, GenericRequirement::None;352353 // Profiling markers for move/copy operations (used by -Z annotate-moves)354 CompilerMove, sym::compiler_move, compiler_move_fn, Target::Fn, GenericRequirement::Exact(2);355 CompilerCopy, sym::compiler_copy, compiler_copy_fn, Target::Fn, GenericRequirement::Exact(2);356357 OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);358 GlobalAlloc, sym::global_alloc_ty, global_alloc_ty, Target::Struct, GenericRequirement::None;359360 PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1);361362 ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::Exact(1);363 MaybeDangling, sym::maybe_dangling, maybe_dangling, Target::Struct, GenericRequirement::Exact(1);364 BikeshedGuaranteedNoDrop, sym::bikeshed_guaranteed_no_drop, bikeshed_guaranteed_no_drop, Target::Trait, GenericRequirement::Exact(0);365366 MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None;367368 Termination, sym::termination, termination, Target::Trait, GenericRequirement::None;369370 Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None;371372 Tuple, sym::tuple_trait, tuple_trait, Target::Trait, GenericRequirement::Exact(0);373374 SliceLen, sym::slice_len_fn, slice_len_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None;375376 // Language items from AST lowering377 TryTraitFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;378 TryTraitFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;379 TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;380 TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;381 ResidualIntoTryType, sym::into_try_type, into_try_type_fn, Target::Fn, GenericRequirement::None;382383 CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0);384385 ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);386387 Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;388 PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;389 PollPending, sym::Pending, poll_pending_variant, Target::Variant, GenericRequirement::None;390391 AsyncGenReady, sym::AsyncGenReady, async_gen_ready, Target::Method(MethodKind::Inherent), GenericRequirement::Exact(1);392 AsyncGenPending, sym::AsyncGenPending, async_gen_pending, Target::AssocConst(AssocCtxt::Impl { of_trait: false }), GenericRequirement::Exact(1);393 AsyncGenFinished, sym::AsyncGenFinished, async_gen_finished, Target::AssocConst(AssocCtxt::Impl { of_trait: false }), GenericRequirement::Exact(1);394395 // FIXME(swatinem): the following lang items are used for async lowering and396 // should become obsolete eventually.397 ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;398 GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;399400 Context, sym::Context, context, Target::Struct, GenericRequirement::None;401 FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;402403 AsyncIteratorPollNext, sym::async_iterator_poll_next, async_iterator_poll_next, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0);404 IntoAsyncIterIntoIter, sym::into_async_iter_into_iter, into_async_iter_into_iter, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0);405406 Option, sym::Option, option_type, Target::Enum, GenericRequirement::None;407 OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;408 OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;409410 ResultOk, sym::Ok, result_ok_variant, Target::Variant, GenericRequirement::None;411 ResultErr, sym::Err, result_err_variant, Target::Variant, GenericRequirement::None;412413 ControlFlowContinue, sym::Continue, cf_continue_variant, Target::Variant, GenericRequirement::None;414 ControlFlowBreak, sym::Break, cf_break_variant, Target::Variant, GenericRequirement::None;415416 IntoFutureIntoFuture, sym::into_future, into_future_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;417 IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;418 IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}), GenericRequirement::None;419420 PinNewUnchecked, sym::new_unchecked, new_unchecked_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None;421422 RangeFrom, sym::RangeFrom, range_from_struct, Target::Struct, GenericRequirement::None;423 RangeFull, sym::RangeFull, range_full_struct, Target::Struct, GenericRequirement::None;424 RangeInclusiveStruct, sym::RangeInclusive, range_inclusive_struct, Target::Struct, GenericRequirement::None;425 RangeInclusiveNew, sym::range_inclusive_new, range_inclusive_new_method, Target::Method(MethodKind::Inherent), GenericRequirement::None;426 Range, sym::Range, range_struct, Target::Struct, GenericRequirement::None;427 RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None;428 RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None;429 RangeMax, sym::RangeMax, range_max, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);430 RangeMin, sym::RangeMin, range_min, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);431 RangeSub, sym::RangeSub, range_sub, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0);432433 // `new_range` types that are `Copy + IntoIterator`434 RangeFromCopy, sym::RangeFromCopy, range_from_copy_struct, Target::Struct, GenericRequirement::None;435 RangeCopy, sym::RangeCopy, range_copy_struct, Target::Struct, GenericRequirement::None;436 RangeInclusiveCopy, sym::RangeInclusiveCopy, range_inclusive_copy_struct, Target::Struct, GenericRequirement::None;437 RangeToInclusiveCopy, sym::RangeToInclusiveCopy, range_to_inclusive_copy_struct, Target::Struct, GenericRequirement::None;438439 String, sym::String, string, Target::Struct, GenericRequirement::None;440 CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None;441442 // Experimental lang items for implementing contract pre- and post-condition checking.443 ContractBuildCheckEnsures, sym::contract_build_check_ensures, contract_build_check_ensures_fn, Target::Fn, GenericRequirement::None;444 ContractCheckRequires, sym::contract_check_requires, contract_check_requires_fn, Target::Fn, GenericRequirement::None;445446 // Experimental lang items for `MCP: Low level components for async drop`(https://github.com/rust-lang/compiler-team/issues/727)447 DefaultTrait4, sym::default_trait4, default_trait4_trait, Target::Trait, GenericRequirement::None;448 DefaultTrait3, sym::default_trait3, default_trait3_trait, Target::Trait, GenericRequirement::None;449 DefaultTrait2, sym::default_trait2, default_trait2_trait, Target::Trait, GenericRequirement::None;450 DefaultTrait1, sym::default_trait1, default_trait1_trait, Target::Trait, GenericRequirement::None;451452 ContractCheckEnsures, sym::contract_check_ensures, contract_check_ensures_fn, Target::Fn, GenericRequirement::None;453454 // Reborrowing related lang-items455 Reborrow, sym::reborrow, reborrow, Target::Trait, GenericRequirement::Exact(0);456 CoerceShared, sym::coerce_shared, coerce_shared, Target::Trait, GenericRequirement::Exact(1);457458 // Field representing types.459 FieldRepresentingType, sym::field_representing_type, field_representing_type, Target::Struct, GenericRequirement::Exact(3);460 Field, sym::field, field, Target::Trait, GenericRequirement::Exact(0);461 FieldBase, sym::field_base, field_base, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(0);462 FieldType, sym::field_type, field_type, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(0);463 FieldOffset, sym::field_offset, field_offset, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);464465 // Used to fallback `{float}` to `f32` when `f32: From<{float}>`466 From, sym::From, from_trait, Target::Trait, GenericRequirement::Exact(1);467 FromFn, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;468}469470/// The requirement imposed on the generics of a lang item471pub enum GenericRequirement {472 /// No restriction on the generics473 None,474 /// A minimum number of generics that is demanded on a lang item475 Minimum(usize),476 /// The number of generics must match precisely as stipulated477 Exact(usize),478}479480pub static FN_TRAITS: &'static [LangItem] = &[LangItem::Fn, LangItem::FnMut, LangItem::FnOnce];481482pub static OPERATORS: &'static [LangItem] = &[483 LangItem::Add,484 LangItem::Sub,485 LangItem::Mul,486 LangItem::Div,487 LangItem::Rem,488 LangItem::Neg,489 LangItem::Not,490 LangItem::BitXor,491 LangItem::BitAnd,492 LangItem::BitOr,493 LangItem::Shl,494 LangItem::Shr,495 LangItem::AddAssign,496 LangItem::SubAssign,497 LangItem::MulAssign,498 LangItem::DivAssign,499 LangItem::RemAssign,500 LangItem::BitXorAssign,501 LangItem::BitAndAssign,502 LangItem::BitOrAssign,503 LangItem::ShlAssign,504 LangItem::ShrAssign,505 LangItem::Index,506 LangItem::IndexMut,507 LangItem::PartialEq,508 LangItem::PartialOrd,509];510511pub static BINARY_OPERATORS: &'static [LangItem] = &[512 LangItem::Add,513 LangItem::Sub,514 LangItem::Mul,515 LangItem::Div,516 LangItem::Rem,517 LangItem::BitXor,518 LangItem::BitAnd,519 LangItem::BitOr,520 LangItem::Shl,521 LangItem::Shr,522 LangItem::AddAssign,523 LangItem::SubAssign,524 LangItem::MulAssign,525 LangItem::DivAssign,526 LangItem::RemAssign,527 LangItem::BitXorAssign,528 LangItem::BitAndAssign,529 LangItem::BitOrAssign,530 LangItem::ShlAssign,531 LangItem::ShrAssign,532 LangItem::Index,533 LangItem::IndexMut,534 LangItem::PartialEq,535 LangItem::PartialOrd,536];