| 1 | //! Defines lang items. |
| 2 | //! |
| 3 | //! Language items are items that represent concepts intrinsic to the language |
| 4 | //! 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. |
| 9 | |
| 10 | use rustc_ast::attr::AttributeExt; |
| 11 | use rustc_data_structures::fx::FxIndexMap; |
| 12 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; |
| 13 | use rustc_macros::{Decodable, Encodable, HashStable_Generic}; |
| 14 | use rustc_span::{Span, Symbol, kw, sym}; |
| 15 | |
| 16 | use crate::def_id::DefId; |
| 17 | use crate::{MethodKind, Target}; |
| 18 | |
| 19 | /// All of the lang items, defined or not. |
| 20 | /// Defined lang items can come from the current crate or its dependencies. |
| 21 | #[derive (HashStable_Generic, Debug)] |
| 22 | pub 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 | } |
| 30 | |
| 31 | impl 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 | } |
| 40 | |
| 41 | pub fn get(&self, item: LangItem) -> Option<DefId> { |
| 42 | self.items[item as usize] |
| 43 | } |
| 44 | |
| 45 | 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); |
| 48 | |
| 49 | // 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 | } |
| 58 | |
| 59 | pub fn from_def_id(&self, def_id: DefId) -> Option<LangItem> { |
| 60 | self.reverse_items.get(&def_id).copied() |
| 61 | } |
| 62 | |
| 63 | pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> { |
| 64 | self.items |
| 65 | .iter() |
| 66 | .enumerate() |
| 67 | .filter_map(|(i, id)| id.map(|id| (LangItem::from_u32(i as u32).unwrap(), id))) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // The actual lang items defined come at the end of this file in one handy table. |
| 72 | // So you probably just want to nip down to the end. |
| 73 | macro_rules! language_item_table { |
| 74 | ( |
| 75 | $( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )* |
| 76 | ) => { |
| 77 | /// A representation of all the valid lang items in Rust. |
| 78 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)] |
| 79 | pub enum LangItem { |
| 80 | $( |
| 81 | #[doc = concat!("The `" , stringify!($name), "` lang item." )] |
| 82 | $(#[$attr])* |
| 83 | $variant, |
| 84 | )* |
| 85 | } |
| 86 | |
| 87 | impl LangItem { |
| 88 | fn from_u32(u: u32) -> Option<LangItem> { |
| 89 | // This implementation is clumsy, but makes no assumptions |
| 90 | // about how discriminant tags are allocated within the |
| 91 | // range `0 .. std::mem::variant_count::<LangItem>()`. |
| 92 | $(if u == LangItem::$variant as u32 { |
| 93 | return Some(LangItem::$variant) |
| 94 | })* |
| 95 | None |
| 96 | } |
| 97 | |
| 98 | /// Returns the `name` symbol in `#[lang = "$name"]`. |
| 99 | /// For example, [`LangItem::PartialEq`]`.name()` |
| 100 | /// would result in [`sym::eq`] since it is `#[lang = "eq"]`. |
| 101 | pub fn name(self) -> Symbol { |
| 102 | match self { |
| 103 | $( LangItem::$variant => $module::$name, )* |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /// Opposite of [`LangItem::name`] |
| 108 | pub fn from_name(name: Symbol) -> Option<Self> { |
| 109 | match name { |
| 110 | $( $module::$name => Some(LangItem::$variant), )* |
| 111 | _ => None, |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /// Returns the name of the `LangItem` enum variant. |
| 116 | // This method is used by Clippy for internal lints. |
| 117 | pub fn variant_name(self) -> &'static str { |
| 118 | match self { |
| 119 | $( LangItem::$variant => stringify!($variant), )* |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | pub fn target(self) -> Target { |
| 124 | match self { |
| 125 | $( LangItem::$variant => $target, )* |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | pub fn required_generics(&self) -> GenericRequirement { |
| 130 | match self { |
| 131 | $( LangItem::$variant => $generics, )* |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | impl LanguageItems { |
| 137 | $( |
| 138 | #[doc = concat!("Returns the [`DefId`] of the `" , stringify!($name), "` lang item if it is defined." )] |
| 139 | pub fn $method(&self) -> Option<DefId> { |
| 140 | self.items[LangItem::$variant as usize] |
| 141 | } |
| 142 | )* |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | impl<CTX> HashStable<CTX> for LangItem { |
| 148 | fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { |
| 149 | ::std::hash::Hash::hash(self, state:hasher); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /// Extracts the first `lang = "$name"` out of a list of attributes. |
| 154 | /// The `#[panic_handler]` attribute is also extracted out when found. |
| 155 | pub fn extract(attrs: &[impl AttributeExt]) -> Option<(Symbol, Span)> { |
| 156 | attrs.iter().find_map(|attr: &impl AttributeExt| { |
| 157 | Some(match attr { |
| 158 | _ if attr.has_name(sym::lang) => (attr.value_str()?, attr.span()), |
| 159 | _ if attr.has_name(sym::panic_handler) => (sym::panic_impl, attr.span()), |
| 160 | _ => return None, |
| 161 | }) |
| 162 | }) |
| 163 | } |
| 164 | |
| 165 | language_item_table! { |
| 166 | // Variant name, Name, Getter method name, Target Generic requirements; |
| 167 | Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0); |
| 168 | Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1); |
| 169 | /// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ"). |
| 170 | StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None; |
| 171 | Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0); |
| 172 | Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None; |
| 173 | CloneFn, sym::clone_fn, clone_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 174 | UseCloned, sym::use_cloned, use_cloned_trait, Target::Trait, GenericRequirement::None; |
| 175 | Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0); |
| 176 | DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None; |
| 177 | /// The associated item of the `DiscriminantKind` trait. |
| 178 | Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None; |
| 179 | |
| 180 | PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None; |
| 181 | Metadata, sym::metadata_type, metadata_type, Target::AssocTy, GenericRequirement::None; |
| 182 | DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None; |
| 183 | |
| 184 | Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0); |
| 185 | |
| 186 | FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0); |
| 187 | FnPtrAddr, sym::fn_ptr_addr, fn_ptr_addr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 188 | |
| 189 | Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None; |
| 190 | Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None; |
| 191 | |
| 192 | AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::Exact(0); |
| 193 | AsyncDestruct, sym::async_destruct, async_destruct_trait, Target::Trait, GenericRequirement::Exact(0); |
| 194 | AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1); |
| 195 | SurfaceAsyncDropInPlace, sym::surface_async_drop_in_place, surface_async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1); |
| 196 | AsyncDropSurfaceDropInPlace, sym::async_drop_surface_drop_in_place, async_drop_surface_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1); |
| 197 | AsyncDropSlice, sym::async_drop_slice, async_drop_slice_fn, Target::Fn, GenericRequirement::Exact(1); |
| 198 | AsyncDropChain, sym::async_drop_chain, async_drop_chain_fn, Target::Fn, GenericRequirement::Exact(2); |
| 199 | AsyncDropNoop, sym::async_drop_noop, async_drop_noop_fn, Target::Fn, GenericRequirement::Exact(0); |
| 200 | AsyncDropDeferredDropInPlace, sym::async_drop_deferred_drop_in_place, async_drop_deferred_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1); |
| 201 | AsyncDropFuse, sym::async_drop_fuse, async_drop_fuse_fn, Target::Fn, GenericRequirement::Exact(1); |
| 202 | AsyncDropDefer, sym::async_drop_defer, async_drop_defer_fn, Target::Fn, GenericRequirement::Exact(1); |
| 203 | AsyncDropEither, sym::async_drop_either, async_drop_either_fn, Target::Fn, GenericRequirement::Exact(3); |
| 204 | |
| 205 | CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1); |
| 206 | DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1); |
| 207 | |
| 208 | // lang items relating to transmutability |
| 209 | TransmuteOpts, sym::transmute_opts, transmute_opts, Target::Struct, GenericRequirement::Exact(0); |
| 210 | TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(2); |
| 211 | |
| 212 | Add, sym::add, add_trait, Target::Trait, GenericRequirement::Exact(1); |
| 213 | Sub, sym::sub, sub_trait, Target::Trait, GenericRequirement::Exact(1); |
| 214 | Mul, sym::mul, mul_trait, Target::Trait, GenericRequirement::Exact(1); |
| 215 | Div, sym::div, div_trait, Target::Trait, GenericRequirement::Exact(1); |
| 216 | Rem, sym::rem, rem_trait, Target::Trait, GenericRequirement::Exact(1); |
| 217 | Neg, sym::neg, neg_trait, Target::Trait, GenericRequirement::Exact(0); |
| 218 | Not, sym::not, not_trait, Target::Trait, GenericRequirement::Exact(0); |
| 219 | BitXor, sym::bitxor, bitxor_trait, Target::Trait, GenericRequirement::Exact(1); |
| 220 | BitAnd, sym::bitand, bitand_trait, Target::Trait, GenericRequirement::Exact(1); |
| 221 | BitOr, sym::bitor, bitor_trait, Target::Trait, GenericRequirement::Exact(1); |
| 222 | Shl, sym::shl, shl_trait, Target::Trait, GenericRequirement::Exact(1); |
| 223 | Shr, sym::shr, shr_trait, Target::Trait, GenericRequirement::Exact(1); |
| 224 | AddAssign, sym::add_assign, add_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 225 | SubAssign, sym::sub_assign, sub_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 226 | MulAssign, sym::mul_assign, mul_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 227 | DivAssign, sym::div_assign, div_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 228 | RemAssign, sym::rem_assign, rem_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 229 | BitXorAssign, sym::bitxor_assign, bitxor_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 230 | BitAndAssign, sym::bitand_assign, bitand_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 231 | BitOrAssign, sym::bitor_assign, bitor_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 232 | ShlAssign, sym::shl_assign, shl_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 233 | ShrAssign, sym::shr_assign, shr_assign_trait, Target::Trait, GenericRequirement::Exact(1); |
| 234 | Index, sym::index, index_trait, Target::Trait, GenericRequirement::Exact(1); |
| 235 | IndexMut, sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1); |
| 236 | |
| 237 | UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None; |
| 238 | VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None; |
| 239 | |
| 240 | Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0); |
| 241 | DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0); |
| 242 | DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0); |
| 243 | DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None; |
| 244 | Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None; |
| 245 | ReceiverTarget, sym::receiver_target, receiver_target, Target::AssocTy, GenericRequirement::None; |
| 246 | LegacyReceiver, sym::legacy_receiver, legacy_receiver_trait, Target::Trait, GenericRequirement::None; |
| 247 | |
| 248 | Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1); |
| 249 | FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); |
| 250 | FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1); |
| 251 | |
| 252 | AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1); |
| 253 | AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); |
| 254 | AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1); |
| 255 | AsyncFnOnceOutput, sym::async_fn_once_output, async_fn_once_output, Target::AssocTy, GenericRequirement::Exact(1); |
| 256 | CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy, GenericRequirement::Exact(1); |
| 257 | CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy, GenericRequirement::Exact(2); |
| 258 | AsyncFnKindHelper, sym::async_fn_kind_helper, async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1); |
| 259 | AsyncFnKindUpvars, sym::async_fn_kind_upvars, async_fn_kind_upvars, Target::AssocTy, GenericRequirement::Exact(5); |
| 260 | |
| 261 | FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None; |
| 262 | |
| 263 | Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0); |
| 264 | FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0); |
| 265 | Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0); |
| 266 | FutureOutput, sym::future_output, future_output, Target::AssocTy, GenericRequirement::Exact(0); |
| 267 | AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0); |
| 268 | |
| 269 | CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None; |
| 270 | Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Exact(1); |
| 271 | CoroutineReturn, sym::coroutine_return, coroutine_return, Target::AssocTy, GenericRequirement::Exact(1); |
| 272 | CoroutineYield, sym::coroutine_yield, coroutine_yield, Target::AssocTy, GenericRequirement::Exact(1); |
| 273 | CoroutineResume, sym::coroutine_resume, coroutine_resume, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 274 | |
| 275 | Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None; |
| 276 | Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None; |
| 277 | |
| 278 | OrderingEnum, sym::Ordering, ordering_enum, Target::Enum, GenericRequirement::Exact(0); |
| 279 | PartialEq, sym::eq, eq_trait, Target::Trait, GenericRequirement::Exact(1); |
| 280 | PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait, GenericRequirement::Exact(1); |
| 281 | CVoid, sym::c_void, c_void, Target::Enum, GenericRequirement::None; |
| 282 | |
| 283 | // A number of panic-related lang items. The `panic` item corresponds to divide-by-zero and |
| 284 | // various panic cases with `match`. The `panic_bounds_check` item is for indexing arrays. |
| 285 | // |
| 286 | // The `begin_unwind` lang item has a predefined symbol name and is sort of a "weak lang item" |
| 287 | // in the sense that a crate is not required to have it defined to use it, but a final product |
| 288 | // is required to define it somewhere. Additionally, there are restrictions on crates that use |
| 289 | // a weak lang item, but do not have it defined. |
| 290 | Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0); |
| 291 | PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0); |
| 292 | PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None; |
| 293 | ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None; |
| 294 | PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0); |
| 295 | PanicMisalignedPointerDereference, sym::panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference_fn, Target::Fn, GenericRequirement::Exact(0); |
| 296 | PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None; |
| 297 | PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None; |
| 298 | PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None; |
| 299 | PanicCannotUnwind, sym::panic_cannot_unwind, panic_cannot_unwind, Target::Fn, GenericRequirement::Exact(0); |
| 300 | PanicInCleanup, sym::panic_in_cleanup, panic_in_cleanup, Target::Fn, GenericRequirement::Exact(0); |
| 301 | /// Constant panic messages, used for codegen of MIR asserts. |
| 302 | PanicAddOverflow, sym::panic_const_add_overflow, panic_const_add_overflow, Target::Fn, GenericRequirement::None; |
| 303 | PanicSubOverflow, sym::panic_const_sub_overflow, panic_const_sub_overflow, Target::Fn, GenericRequirement::None; |
| 304 | PanicMulOverflow, sym::panic_const_mul_overflow, panic_const_mul_overflow, Target::Fn, GenericRequirement::None; |
| 305 | PanicDivOverflow, sym::panic_const_div_overflow, panic_const_div_overflow, Target::Fn, GenericRequirement::None; |
| 306 | PanicRemOverflow, sym::panic_const_rem_overflow, panic_const_rem_overflow, Target::Fn, GenericRequirement::None; |
| 307 | PanicNegOverflow, sym::panic_const_neg_overflow, panic_const_neg_overflow, Target::Fn, GenericRequirement::None; |
| 308 | PanicShrOverflow, sym::panic_const_shr_overflow, panic_const_shr_overflow, Target::Fn, GenericRequirement::None; |
| 309 | PanicShlOverflow, sym::panic_const_shl_overflow, panic_const_shl_overflow, Target::Fn, GenericRequirement::None; |
| 310 | PanicDivZero, sym::panic_const_div_by_zero, panic_const_div_by_zero, Target::Fn, GenericRequirement::None; |
| 311 | PanicRemZero, sym::panic_const_rem_by_zero, panic_const_rem_by_zero, Target::Fn, GenericRequirement::None; |
| 312 | PanicCoroutineResumed, sym::panic_const_coroutine_resumed, panic_const_coroutine_resumed, Target::Fn, GenericRequirement::None; |
| 313 | PanicAsyncFnResumed, sym::panic_const_async_fn_resumed, panic_const_async_fn_resumed, Target::Fn, GenericRequirement::None; |
| 314 | PanicAsyncGenFnResumed, sym::panic_const_async_gen_fn_resumed, panic_const_async_gen_fn_resumed, Target::Fn, GenericRequirement::None; |
| 315 | PanicGenFnNone, sym::panic_const_gen_fn_none, panic_const_gen_fn_none, Target::Fn, GenericRequirement::None; |
| 316 | PanicCoroutineResumedPanic, sym::panic_const_coroutine_resumed_panic, panic_const_coroutine_resumed_panic, Target::Fn, GenericRequirement::None; |
| 317 | PanicAsyncFnResumedPanic, sym::panic_const_async_fn_resumed_panic, panic_const_async_fn_resumed_panic, Target::Fn, GenericRequirement::None; |
| 318 | PanicAsyncGenFnResumedPanic, sym::panic_const_async_gen_fn_resumed_panic, panic_const_async_gen_fn_resumed_panic, Target::Fn, GenericRequirement::None; |
| 319 | PanicGenFnNonePanic, sym::panic_const_gen_fn_none_panic, panic_const_gen_fn_none_panic, Target::Fn, GenericRequirement::None; |
| 320 | PanicNullPointerDereference, sym::panic_null_pointer_dereference, panic_null_pointer_dereference, Target::Fn, GenericRequirement::None; |
| 321 | /// libstd panic entry point. Necessary for const eval to be able to catch it |
| 322 | BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None; |
| 323 | |
| 324 | // Lang items needed for `format_args!()`. |
| 325 | FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None; |
| 326 | FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None; |
| 327 | FormatCount, sym::format_count, format_count, Target::Enum, GenericRequirement::None; |
| 328 | FormatPlaceholder, sym::format_placeholder, format_placeholder, Target::Struct, GenericRequirement::None; |
| 329 | FormatUnsafeArg, sym::format_unsafe_arg, format_unsafe_arg, Target::Struct, GenericRequirement::None; |
| 330 | |
| 331 | ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None; |
| 332 | DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); |
| 333 | FallbackSurfaceDrop, sym::fallback_surface_drop, fallback_surface_drop_fn, Target::Fn, GenericRequirement::None; |
| 334 | AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None; |
| 335 | |
| 336 | /// For all binary crates without `#![no_main]`, Rust will generate a "main" function. |
| 337 | /// The exact name and signature are target-dependent. The "main" function will invoke |
| 338 | /// this lang item, passing it the `argc` and `argv` (or null, if those don't exist |
| 339 | /// on the current target) as well as the user-defined `fn main` from the binary crate. |
| 340 | Start, sym::start, start_fn, Target::Fn, GenericRequirement::Exact(1); |
| 341 | |
| 342 | EhPersonality, sym::eh_personality, eh_personality, Target::Fn, GenericRequirement::None; |
| 343 | EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None; |
| 344 | |
| 345 | OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1); |
| 346 | GlobalAlloc, sym::global_alloc_ty, global_alloc_ty, Target::Struct, GenericRequirement::None; |
| 347 | |
| 348 | // Experimental lang item for Miri |
| 349 | PtrUnique, sym::ptr_unique, ptr_unique, Target::Struct, GenericRequirement::Exact(1); |
| 350 | |
| 351 | PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1); |
| 352 | |
| 353 | ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::None; |
| 354 | BikeshedGuaranteedNoDrop, sym::bikeshed_guaranteed_no_drop, bikeshed_guaranteed_no_drop, Target::Trait, GenericRequirement::Exact(0); |
| 355 | |
| 356 | MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None; |
| 357 | |
| 358 | Termination, sym::termination, termination, Target::Trait, GenericRequirement::None; |
| 359 | |
| 360 | Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None; |
| 361 | |
| 362 | Tuple, sym::tuple_trait, tuple_trait, Target::Trait, GenericRequirement::Exact(0); |
| 363 | |
| 364 | SliceLen, sym::slice_len_fn, slice_len_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None; |
| 365 | |
| 366 | // Language items from AST lowering |
| 367 | TryTraitFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 368 | TryTraitFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 369 | TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 370 | TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None; |
| 371 | |
| 372 | PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0); |
| 373 | |
| 374 | CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0); |
| 375 | |
| 376 | ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0); |
| 377 | UnsizedConstParamTy, sym::unsized_const_param_ty, unsized_const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0); |
| 378 | |
| 379 | Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None; |
| 380 | PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None; |
| 381 | PollPending, sym::Pending, poll_pending_variant, Target::Variant, GenericRequirement::None; |
| 382 | |
| 383 | AsyncGenReady, sym::AsyncGenReady, async_gen_ready, Target::Method(MethodKind::Inherent), GenericRequirement::Exact(1); |
| 384 | AsyncGenPending, sym::AsyncGenPending, async_gen_pending, Target::AssocConst, GenericRequirement::Exact(1); |
| 385 | AsyncGenFinished, sym::AsyncGenFinished, async_gen_finished, Target::AssocConst, GenericRequirement::Exact(1); |
| 386 | |
| 387 | // FIXME(swatinem): the following lang items are used for async lowering and |
| 388 | // should become obsolete eventually. |
| 389 | ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None; |
| 390 | GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None; |
| 391 | |
| 392 | Context, sym::Context, context, Target::Struct, GenericRequirement::None; |
| 393 | FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 394 | |
| 395 | AsyncIteratorPollNext, sym::async_iterator_poll_next, async_iterator_poll_next, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0); |
| 396 | IntoAsyncIterIntoIter, sym::into_async_iter_into_iter, into_async_iter_into_iter, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0); |
| 397 | |
| 398 | Option, sym::Option, option_type, Target::Enum, GenericRequirement::None; |
| 399 | OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None; |
| 400 | OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None; |
| 401 | |
| 402 | ResultOk, sym::Ok, result_ok_variant, Target::Variant, GenericRequirement::None; |
| 403 | ResultErr, sym::Err, result_err_variant, Target::Variant, GenericRequirement::None; |
| 404 | |
| 405 | ControlFlowContinue, sym::Continue, cf_continue_variant, Target::Variant, GenericRequirement::None; |
| 406 | ControlFlowBreak, sym::Break, cf_break_variant, Target::Variant, GenericRequirement::None; |
| 407 | |
| 408 | IntoFutureIntoFuture, sym::into_future, into_future_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 409 | IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; |
| 410 | IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}), GenericRequirement::None; |
| 411 | |
| 412 | PinNewUnchecked, sym::new_unchecked, new_unchecked_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None; |
| 413 | |
| 414 | RangeFrom, sym::RangeFrom, range_from_struct, Target::Struct, GenericRequirement::None; |
| 415 | RangeFull, sym::RangeFull, range_full_struct, Target::Struct, GenericRequirement::None; |
| 416 | RangeInclusiveStruct, sym::RangeInclusive, range_inclusive_struct, Target::Struct, GenericRequirement::None; |
| 417 | RangeInclusiveNew, sym::range_inclusive_new, range_inclusive_new_method, Target::Method(MethodKind::Inherent), GenericRequirement::None; |
| 418 | Range, sym::Range, range_struct, Target::Struct, GenericRequirement::None; |
| 419 | RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None; |
| 420 | RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None; |
| 421 | RangeMax, sym::RangeMax, range_max, Target::AssocConst, GenericRequirement::Exact(0); |
| 422 | RangeMin, sym::RangeMin, range_min, Target::AssocConst, GenericRequirement::Exact(0); |
| 423 | RangeSub, sym::RangeSub, range_sub, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0); |
| 424 | |
| 425 | // `new_range` types that are `Copy + IntoIterator` |
| 426 | RangeFromCopy, sym::RangeFromCopy, range_from_copy_struct, Target::Struct, GenericRequirement::None; |
| 427 | RangeCopy, sym::RangeCopy, range_copy_struct, Target::Struct, GenericRequirement::None; |
| 428 | RangeInclusiveCopy, sym::RangeInclusiveCopy, range_inclusive_copy_struct, Target::Struct, GenericRequirement::None; |
| 429 | |
| 430 | String, sym::String, string, Target::Struct, GenericRequirement::None; |
| 431 | CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None; |
| 432 | |
| 433 | // Experimental lang items for implementing contract pre- and post-condition checking. |
| 434 | ContractBuildCheckEnsures, sym::contract_build_check_ensures, contract_build_check_ensures_fn, Target::Fn, GenericRequirement::None; |
| 435 | ContractCheckRequires, sym::contract_check_requires, contract_check_requires_fn, Target::Fn, GenericRequirement::None; |
| 436 | } |
| 437 | |
| 438 | /// The requirement imposed on the generics of a lang item |
| 439 | pub enum GenericRequirement { |
| 440 | /// No restriction on the generics |
| 441 | None, |
| 442 | /// A minimum number of generics that is demanded on a lang item |
| 443 | Minimum(usize), |
| 444 | /// The number of generics must match precisely as stipulated |
| 445 | Exact(usize), |
| 446 | } |
| 447 | |
| 448 | pub static FN_TRAITS: &'static [LangItem] = &[LangItem::Fn, LangItem::FnMut, LangItem::FnOnce]; |
| 449 | |
| 450 | pub static OPERATORS: &'static [LangItem] = &[ |
| 451 | LangItem::Add, |
| 452 | LangItem::Sub, |
| 453 | LangItem::Mul, |
| 454 | LangItem::Div, |
| 455 | LangItem::Rem, |
| 456 | LangItem::Neg, |
| 457 | LangItem::Not, |
| 458 | LangItem::BitXor, |
| 459 | LangItem::BitAnd, |
| 460 | LangItem::BitOr, |
| 461 | LangItem::Shl, |
| 462 | LangItem::Shr, |
| 463 | LangItem::AddAssign, |
| 464 | LangItem::SubAssign, |
| 465 | LangItem::MulAssign, |
| 466 | LangItem::DivAssign, |
| 467 | LangItem::RemAssign, |
| 468 | LangItem::BitXorAssign, |
| 469 | LangItem::BitAndAssign, |
| 470 | LangItem::BitOrAssign, |
| 471 | LangItem::ShlAssign, |
| 472 | LangItem::ShrAssign, |
| 473 | LangItem::Index, |
| 474 | LangItem::IndexMut, |
| 475 | LangItem::PartialEq, |
| 476 | LangItem::PartialOrd, |
| 477 | ]; |
| 478 | |
| 479 | pub static BINARY_OPERATORS: &'static [LangItem] = &[ |
| 480 | LangItem::Add, |
| 481 | LangItem::Sub, |
| 482 | LangItem::Mul, |
| 483 | LangItem::Div, |
| 484 | LangItem::Rem, |
| 485 | LangItem::BitXor, |
| 486 | LangItem::BitAnd, |
| 487 | LangItem::BitOr, |
| 488 | LangItem::Shl, |
| 489 | LangItem::Shr, |
| 490 | LangItem::AddAssign, |
| 491 | LangItem::SubAssign, |
| 492 | LangItem::MulAssign, |
| 493 | LangItem::DivAssign, |
| 494 | LangItem::RemAssign, |
| 495 | LangItem::BitXorAssign, |
| 496 | LangItem::BitAndAssign, |
| 497 | LangItem::BitOrAssign, |
| 498 | LangItem::ShlAssign, |
| 499 | LangItem::ShrAssign, |
| 500 | LangItem::Index, |
| 501 | LangItem::IndexMut, |
| 502 | LangItem::PartialEq, |
| 503 | LangItem::PartialOrd, |
| 504 | ]; |
| 505 | |