2019-11-23 09:58:01 +00:00
|
|
|
//! Collects lang items: items marked with `#[lang = "..."]` attribute.
|
|
|
|
//!
|
|
|
|
//! This attribute to tell the compiler about semi built-in std library
|
|
|
|
//! features, such as Fn family of traits.
|
2023-09-06 13:21:41 +00:00
|
|
|
use hir_expand::name::Name;
|
2024-07-12 13:57:54 +00:00
|
|
|
use intern::{sym, Symbol};
|
2019-11-23 09:58:01 +00:00
|
|
|
use rustc_hash::FxHashMap;
|
2023-05-02 14:12:22 +00:00
|
|
|
use triomphe::Arc;
|
2019-11-23 09:58:01 +00:00
|
|
|
|
|
|
|
use crate::{
|
2023-03-08 17:28:52 +00:00
|
|
|
db::DefDatabase, path::Path, AdtId, AssocItemId, AttrDefId, CrateId, EnumId, EnumVariantId,
|
|
|
|
FunctionId, ImplId, ModuleDefId, StaticId, StructId, TraitId, TypeAliasId, UnionId,
|
2019-11-23 09:58:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
|
|
pub enum LangItemTarget {
|
|
|
|
EnumId(EnumId),
|
2023-01-21 16:29:07 +00:00
|
|
|
Function(FunctionId),
|
|
|
|
ImplDef(ImplId),
|
|
|
|
Static(StaticId),
|
|
|
|
Struct(StructId),
|
|
|
|
Union(UnionId),
|
|
|
|
TypeAlias(TypeAliasId),
|
|
|
|
Trait(TraitId),
|
|
|
|
EnumVariant(EnumVariantId),
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 16:38:37 +00:00
|
|
|
impl LangItemTarget {
|
|
|
|
pub fn as_enum(self) -> Option<EnumId> {
|
|
|
|
match self {
|
|
|
|
LangItemTarget::EnumId(id) => Some(id),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_function(self) -> Option<FunctionId> {
|
|
|
|
match self {
|
2023-01-21 16:29:07 +00:00
|
|
|
LangItemTarget::Function(id) => Some(id),
|
2019-12-29 16:38:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 20:24:40 +00:00
|
|
|
pub fn as_impl_def(self) -> Option<ImplId> {
|
2019-12-29 16:38:37 +00:00
|
|
|
match self {
|
2023-01-21 16:29:07 +00:00
|
|
|
LangItemTarget::ImplDef(id) => Some(id),
|
2019-12-29 16:38:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_static(self) -> Option<StaticId> {
|
|
|
|
match self {
|
2023-01-21 16:29:07 +00:00
|
|
|
LangItemTarget::Static(id) => Some(id),
|
2019-12-29 16:38:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_struct(self) -> Option<StructId> {
|
|
|
|
match self {
|
2023-01-21 16:29:07 +00:00
|
|
|
LangItemTarget::Struct(id) => Some(id),
|
2019-12-29 16:38:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_trait(self) -> Option<TraitId> {
|
|
|
|
match self {
|
2023-01-21 16:29:07 +00:00
|
|
|
LangItemTarget::Trait(id) => Some(id),
|
2019-12-29 16:38:37 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2021-08-07 19:56:42 +00:00
|
|
|
|
|
|
|
pub fn as_enum_variant(self) -> Option<EnumVariantId> {
|
|
|
|
match self {
|
2023-01-21 16:29:07 +00:00
|
|
|
LangItemTarget::EnumVariant(id) => Some(id),
|
2021-08-07 19:56:42 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2024-08-22 11:35:39 +00:00
|
|
|
|
|
|
|
pub fn as_type_alias(self) -> Option<TypeAliasId> {
|
|
|
|
match self {
|
|
|
|
LangItemTarget::TypeAlias(id) => Some(id),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2019-12-29 16:38:37 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 09:58:01 +00:00
|
|
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub struct LangItems {
|
2023-01-21 16:29:07 +00:00
|
|
|
items: FxHashMap<LangItem, LangItemTarget>,
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LangItems {
|
2023-01-21 16:29:07 +00:00
|
|
|
pub fn target(&self, item: LangItem) -> Option<LangItemTarget> {
|
|
|
|
self.items.get(&item).copied()
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Salsa query. This will look for lang items in a specific crate.
|
2024-01-09 20:06:21 +00:00
|
|
|
pub(crate) fn crate_lang_items_query(
|
|
|
|
db: &dyn DefDatabase,
|
|
|
|
krate: CrateId,
|
|
|
|
) -> Option<Arc<LangItems>> {
|
2024-06-06 23:52:25 +00:00
|
|
|
let _p = tracing::info_span!("crate_lang_items_query").entered();
|
2020-04-10 18:25:55 +00:00
|
|
|
|
2019-11-23 09:58:01 +00:00
|
|
|
let mut lang_items = LangItems::default();
|
|
|
|
|
|
|
|
let crate_def_map = db.crate_def_map(krate);
|
|
|
|
|
2021-01-20 14:41:18 +00:00
|
|
|
for (_, module_data) in crate_def_map.modules() {
|
2020-12-16 23:26:01 +00:00
|
|
|
for impl_def in module_data.scope.impls() {
|
2023-01-21 16:29:07 +00:00
|
|
|
lang_items.collect_lang_item(db, impl_def, LangItemTarget::ImplDef);
|
|
|
|
for assoc in db.impl_data(impl_def).items.iter().copied() {
|
|
|
|
match assoc {
|
|
|
|
AssocItemId::FunctionId(f) => {
|
|
|
|
lang_items.collect_lang_item(db, f, LangItemTarget::Function)
|
|
|
|
}
|
|
|
|
AssocItemId::TypeAliasId(t) => {
|
|
|
|
lang_items.collect_lang_item(db, t, LangItemTarget::TypeAlias)
|
|
|
|
}
|
|
|
|
AssocItemId::ConstId(_) => (),
|
|
|
|
}
|
|
|
|
}
|
2020-12-16 23:26:01 +00:00
|
|
|
}
|
2019-11-23 09:58:01 +00:00
|
|
|
|
2020-12-16 23:26:01 +00:00
|
|
|
for def in module_data.scope.declarations() {
|
|
|
|
match def {
|
|
|
|
ModuleDefId::TraitId(trait_) => {
|
2023-01-21 16:29:07 +00:00
|
|
|
lang_items.collect_lang_item(db, trait_, LangItemTarget::Trait);
|
2024-08-22 11:30:54 +00:00
|
|
|
db.trait_data(trait_).items.iter().for_each(
|
|
|
|
|&(_, assoc_id)| match assoc_id {
|
|
|
|
AssocItemId::FunctionId(f) => {
|
|
|
|
lang_items.collect_lang_item(db, f, LangItemTarget::Function);
|
|
|
|
}
|
|
|
|
AssocItemId::TypeAliasId(alias) => lang_items.collect_lang_item(
|
|
|
|
db,
|
|
|
|
alias,
|
|
|
|
LangItemTarget::TypeAlias,
|
|
|
|
),
|
|
|
|
AssocItemId::ConstId(_) => {}
|
|
|
|
},
|
|
|
|
);
|
2020-12-16 23:26:01 +00:00
|
|
|
}
|
|
|
|
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
|
2021-08-07 19:56:42 +00:00
|
|
|
lang_items.collect_lang_item(db, e, LangItemTarget::EnumId);
|
2024-01-15 09:58:05 +00:00
|
|
|
crate_def_map.enum_definitions[&e].iter().for_each(|&id| {
|
2024-01-15 09:24:14 +00:00
|
|
|
lang_items.collect_lang_item(db, id, LangItemTarget::EnumVariant);
|
2021-08-07 19:56:42 +00:00
|
|
|
});
|
2020-12-16 23:26:01 +00:00
|
|
|
}
|
|
|
|
ModuleDefId::AdtId(AdtId::StructId(s)) => {
|
2023-01-21 16:29:07 +00:00
|
|
|
lang_items.collect_lang_item(db, s, LangItemTarget::Struct);
|
|
|
|
}
|
|
|
|
ModuleDefId::AdtId(AdtId::UnionId(u)) => {
|
|
|
|
lang_items.collect_lang_item(db, u, LangItemTarget::Union);
|
2020-12-16 23:26:01 +00:00
|
|
|
}
|
|
|
|
ModuleDefId::FunctionId(f) => {
|
2023-01-21 16:29:07 +00:00
|
|
|
lang_items.collect_lang_item(db, f, LangItemTarget::Function);
|
2020-12-16 23:26:01 +00:00
|
|
|
}
|
|
|
|
ModuleDefId::StaticId(s) => {
|
2023-01-21 16:29:07 +00:00
|
|
|
lang_items.collect_lang_item(db, s, LangItemTarget::Static);
|
|
|
|
}
|
|
|
|
ModuleDefId::TypeAliasId(t) => {
|
|
|
|
lang_items.collect_lang_item(db, t, LangItemTarget::TypeAlias);
|
2020-12-16 23:26:01 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
2020-12-16 23:26:01 +00:00
|
|
|
|
2024-01-09 20:06:21 +00:00
|
|
|
if lang_items.items.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(Arc::new(lang_items))
|
|
|
|
}
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Salsa query. Look for a lang item, starting from the specified crate and recursively
|
|
|
|
/// traversing its dependencies.
|
|
|
|
pub(crate) fn lang_item_query(
|
2020-03-13 15:05:46 +00:00
|
|
|
db: &dyn DefDatabase,
|
2019-11-23 09:58:01 +00:00
|
|
|
start_crate: CrateId,
|
2023-01-21 16:29:07 +00:00
|
|
|
item: LangItem,
|
2019-11-23 09:58:01 +00:00
|
|
|
) -> Option<LangItemTarget> {
|
2024-06-06 23:52:25 +00:00
|
|
|
let _p = tracing::info_span!("lang_item_query").entered();
|
2024-01-09 20:06:21 +00:00
|
|
|
if let Some(target) =
|
|
|
|
db.crate_lang_items(start_crate).and_then(|it| it.items.get(&item).copied())
|
|
|
|
{
|
2022-01-06 12:31:36 +00:00
|
|
|
return Some(target);
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
2020-03-09 10:11:59 +00:00
|
|
|
db.crate_graph()[start_crate]
|
2020-03-09 09:26:46 +00:00
|
|
|
.dependencies
|
|
|
|
.iter()
|
2023-01-21 16:29:07 +00:00
|
|
|
.find_map(|dep| db.lang_item(dep.crate_id, item))
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn collect_lang_item<T>(
|
|
|
|
&mut self,
|
2020-03-13 15:05:46 +00:00
|
|
|
db: &dyn DefDatabase,
|
2019-11-23 09:58:01 +00:00
|
|
|
item: T,
|
|
|
|
constructor: fn(T) -> LangItemTarget,
|
|
|
|
) where
|
|
|
|
T: Into<AttrDefId> + Copy,
|
|
|
|
{
|
2024-06-06 23:52:25 +00:00
|
|
|
let _p = tracing::info_span!("collect_lang_item").entered();
|
2024-01-16 15:15:56 +00:00
|
|
|
if let Some(lang_item) = lang_attr(db, item.into()) {
|
2023-01-21 16:29:07 +00:00
|
|
|
self.items.entry(lang_item).or_insert_with(|| constructor(item));
|
2019-11-23 09:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-22 13:55:15 +00:00
|
|
|
|
2024-01-16 15:15:56 +00:00
|
|
|
pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangItem> {
|
2024-07-14 10:19:19 +00:00
|
|
|
db.attrs(item).lang_item()
|
2020-05-22 13:55:15 +00:00
|
|
|
}
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2024-01-16 15:15:56 +00:00
|
|
|
pub(crate) fn notable_traits_in_deps(
|
|
|
|
db: &dyn DefDatabase,
|
|
|
|
krate: CrateId,
|
|
|
|
) -> Arc<[Arc<[TraitId]>]> {
|
2024-06-06 23:52:25 +00:00
|
|
|
let _p = tracing::info_span!("notable_traits_in_deps", ?krate).entered();
|
2024-01-16 15:15:56 +00:00
|
|
|
let crate_graph = db.crate_graph();
|
|
|
|
|
|
|
|
Arc::from_iter(
|
|
|
|
crate_graph.transitive_deps(krate).filter_map(|krate| db.crate_notable_traits(krate)),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: CrateId) -> Option<Arc<[TraitId]>> {
|
2024-06-06 23:52:25 +00:00
|
|
|
let _p = tracing::info_span!("crate_notable_traits", ?krate).entered();
|
2024-01-16 15:15:56 +00:00
|
|
|
|
|
|
|
let mut traits = Vec::new();
|
|
|
|
|
|
|
|
let crate_def_map = db.crate_def_map(krate);
|
|
|
|
|
|
|
|
for (_, module_data) in crate_def_map.modules() {
|
|
|
|
for def in module_data.scope.declarations() {
|
|
|
|
if let ModuleDefId::TraitId(trait_) = def {
|
|
|
|
if db.attrs(trait_.into()).has_doc_notable_trait() {
|
|
|
|
traits.push(trait_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if traits.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(traits.into_iter().collect())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-21 16:29:07 +00:00
|
|
|
pub enum GenericRequirement {
|
|
|
|
None,
|
|
|
|
Minimum(usize),
|
|
|
|
Exact(usize),
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! language_item_table {
|
|
|
|
(
|
2023-05-18 10:03:15 +00:00
|
|
|
$( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )*
|
2023-01-21 16:29:07 +00:00
|
|
|
) => {
|
|
|
|
|
|
|
|
/// A representation of all the valid language items in Rust.
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub enum LangItem {
|
|
|
|
$(
|
|
|
|
#[doc = concat!("The `", stringify!($name), "` lang item.")]
|
|
|
|
$(#[$attr])*
|
|
|
|
$variant,
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LangItem {
|
2024-07-16 10:05:16 +00:00
|
|
|
pub fn name(self) -> &'static str {
|
2023-01-21 16:29:07 +00:00
|
|
|
match self {
|
2024-07-16 10:05:16 +00:00
|
|
|
$( LangItem::$variant => stringify!($name), )*
|
2023-01-21 16:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Opposite of [`LangItem::name`]
|
2024-07-14 10:19:19 +00:00
|
|
|
pub fn from_symbol(sym: &Symbol) -> Option<Self> {
|
2024-07-12 13:57:54 +00:00
|
|
|
match sym {
|
2024-07-14 10:19:19 +00:00
|
|
|
$(sym if *sym == $module::$name => Some(LangItem::$variant), )*
|
2024-07-12 13:57:54 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2023-01-21 16:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-08 17:28:52 +00:00
|
|
|
impl LangItem {
|
|
|
|
/// Opposite of [`LangItem::name`]
|
|
|
|
pub fn from_name(name: &hir_expand::name::Name) -> Option<Self> {
|
2024-07-14 10:19:19 +00:00
|
|
|
Self::from_symbol(name.symbol())
|
2023-03-08 17:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn path(&self, db: &dyn DefDatabase, start_crate: CrateId) -> Option<Path> {
|
|
|
|
let t = db.lang_item(start_crate, *self)?;
|
2023-09-06 13:21:41 +00:00
|
|
|
Some(Path::LangItem(t, None))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ty_rel_path(
|
|
|
|
&self,
|
|
|
|
db: &dyn DefDatabase,
|
|
|
|
start_crate: CrateId,
|
|
|
|
seg: Name,
|
|
|
|
) -> Option<Path> {
|
|
|
|
let t = db.lang_item(start_crate, *self)?;
|
|
|
|
Some(Path::LangItem(t, Some(seg)))
|
2023-03-08 17:28:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-21 16:29:07 +00:00
|
|
|
language_item_table! {
|
|
|
|
// Variant name, Name, Getter method name, Target Generic requirements;
|
2023-05-18 10:03:15 +00:00
|
|
|
Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
|
2023-01-21 16:29:07 +00:00
|
|
|
/// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").
|
2023-05-18 10:03:15 +00:00
|
|
|
StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
/// Trait injected by `#[derive(Eq)]`, (i.e. "Total EQ"; no, I will not apologize).
|
2023-05-18 10:03:15 +00:00
|
|
|
StructuralTeq, sym::structural_teq, structural_teq_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
/// The associated item of the [`DiscriminantKind`] trait.
|
2023-05-18 10:03:15 +00:00
|
|
|
Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
Metadata, sym::metadata_type, metadata_type, Target::AssocTy, GenericRequirement::None;
|
|
|
|
DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
FnPtrAddr, sym::fn_ptr_addr, fn_ptr_addr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
|
|
|
|
CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);
|
|
|
|
DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
|
|
|
// language items relating to transmutability
|
2023-05-18 10:03:15 +00:00
|
|
|
TransmuteOpts, sym::transmute_opts, transmute_opts, Target::Struct, GenericRequirement::Exact(0);
|
|
|
|
TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(3);
|
|
|
|
|
|
|
|
Add, sym::add, add_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Sub, sym::sub, sub_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Mul, sym::mul, mul_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Div, sym::div, div_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Rem, sym::rem, rem_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Neg, sym::neg, neg_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
Not, sym::not, not_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
BitXor, sym::bitxor, bitxor_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
BitAnd, sym::bitand, bitand_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
BitOr, sym::bitor, bitor_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Shl, sym::shl, shl_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Shr, sym::shr, shr_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
AddAssign, sym::add_assign, add_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
SubAssign, sym::sub_assign, sub_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
MulAssign, sym::mul_assign, mul_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
DivAssign, sym::div_assign, div_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
RemAssign, sym::rem_assign, rem_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
BitXorAssign, sym::bitxor_assign, bitxor_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
BitAndAssign, sym::bitand_assign, bitand_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
BitOrAssign, sym::bitor_assign, bitor_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
ShlAssign, sym::shl_assign, shl_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
ShrAssign, sym::shr_assign, shr_assign_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
Index, sym::index, index_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
IndexMut, sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
|
|
|
|
UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None;
|
|
|
|
VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None;
|
|
|
|
|
|
|
|
Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None;
|
|
|
|
Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
|
2024-07-12 13:57:54 +00:00
|
|
|
Fn, sym::fn_, fn_trait, Target::Trait, GenericRequirement::Exact(1);
|
2023-05-18 10:03:15 +00:00
|
|
|
FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
|
|
|
|
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
|
|
|
|
|
|
|
|
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
2023-12-25 22:12:45 +00:00
|
|
|
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
|
|
|
|
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
|
2023-05-18 10:03:15 +00:00
|
|
|
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
|
|
|
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
|
|
|
|
|
|
|
PartialEq, sym::eq, eq_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait, GenericRequirement::Exact(1);
|
|
|
|
CVoid, sym::c_void, c_void, Target::Enum, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
|
|
|
// A number of panic-related lang items. The `panic` item corresponds to divide-by-zero and
|
|
|
|
// various panic cases with `match`. The `panic_bounds_check` item is for indexing arrays.
|
|
|
|
//
|
|
|
|
// The `begin_unwind` lang item has a predefined symbol name and is sort of a "weak lang item"
|
|
|
|
// in the sense that a crate is not required to have it defined to use it, but a final product
|
|
|
|
// is required to define it somewhere. Additionally, there are restrictions on crates that use
|
|
|
|
// a weak lang item, but do not have it defined.
|
2023-05-18 10:03:15 +00:00
|
|
|
Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);
|
|
|
|
PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0);
|
|
|
|
PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None;
|
|
|
|
PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;
|
|
|
|
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;
|
|
|
|
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);
|
|
|
|
PanicMisalignedPointerDereference, sym::panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference_fn, Target::Fn, GenericRequirement::Exact(0);
|
|
|
|
PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None;
|
|
|
|
PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None;
|
|
|
|
PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None;
|
|
|
|
PanicCannotUnwind, sym::panic_cannot_unwind, panic_cannot_unwind, Target::Fn, GenericRequirement::Exact(0);
|
2023-01-21 16:29:07 +00:00
|
|
|
/// libstd panic entry point. Necessary for const eval to be able to catch it
|
2023-05-18 10:03:15 +00:00
|
|
|
BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None;
|
|
|
|
|
|
|
|
// Lang items needed for `format_args!()`.
|
|
|
|
FormatAlignment, sym::format_alignment, format_alignment, Target::Enum, GenericRequirement::None;
|
|
|
|
FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None;
|
|
|
|
FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None;
|
|
|
|
FormatCount, sym::format_count, format_count, Target::Enum, GenericRequirement::None;
|
|
|
|
FormatPlaceholder, sym::format_placeholder, format_placeholder, Target::Struct, GenericRequirement::None;
|
|
|
|
FormatUnsafeArg, sym::format_unsafe_arg, format_unsafe_arg, Target::Struct, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None;
|
|
|
|
BoxFree, sym::box_free, box_free_fn, Target::Fn, GenericRequirement::Minimum(1);
|
|
|
|
DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1);
|
|
|
|
AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Start, sym::start, start_fn, Target::Fn, GenericRequirement::Exact(1);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
EhPersonality, sym::eh_personality, eh_personality, Target::Fn, GenericRequirement::None;
|
|
|
|
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
|
|
|
/// Align offset for stride != 1; must not panic.
|
2023-05-18 10:03:15 +00:00
|
|
|
AlignOffset, sym::align_offset, align_offset_fn, Target::Fn, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Termination, sym::termination, termination, Target::Trait, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Tuple, sym::tuple_trait, tuple_trait, Target::Trait, GenericRequirement::Exact(0);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
SliceLen, sym::slice_len_fn, slice_len_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
|
|
|
// Language items from AST lowering
|
2023-05-18 10:03:15 +00:00
|
|
|
TryTraitFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
|
|
|
TryTraitFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
|
|
|
TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
|
|
|
TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0);
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
|
|
|
|
|
|
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
|
|
|
|
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;
|
|
|
|
PollPending, sym::Pending, poll_pending_variant, Target::Variant, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
|
|
|
// FIXME(swatinem): the following lang items are used for async lowering and
|
|
|
|
// should become obsolete eventually.
|
2023-05-18 10:03:15 +00:00
|
|
|
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
|
|
|
|
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
|
|
|
|
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
2024-08-22 11:33:35 +00:00
|
|
|
FutureOutput, sym::future_output, future_output, Target::TypeAlias, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
Option, sym::Option, option_type, Target::Enum, GenericRequirement::None;
|
|
|
|
OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
|
|
|
|
OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
ResultOk, sym::Ok, result_ok_variant, Target::Variant, GenericRequirement::None;
|
|
|
|
ResultErr, sym::Err, result_err_variant, Target::Variant, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
ControlFlowContinue, sym::Continue, cf_continue_variant, Target::Variant, GenericRequirement::None;
|
|
|
|
ControlFlowBreak, sym::Break, cf_break_variant, Target::Variant, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
IntoFutureIntoFuture, sym::into_future, into_future_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
|
|
|
IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
|
|
|
IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}), GenericRequirement::None;
|
2024-08-22 11:33:35 +00:00
|
|
|
Iterator, sym::iterator, iterator, Target::Trait, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
PinNewUnchecked, sym::new_unchecked, new_unchecked_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
RangeFrom, sym::RangeFrom, range_from_struct, Target::Struct, GenericRequirement::None;
|
|
|
|
RangeFull, sym::RangeFull, range_full_struct, Target::Struct, GenericRequirement::None;
|
|
|
|
RangeInclusiveStruct, sym::RangeInclusive, range_inclusive_struct, Target::Struct, GenericRequirement::None;
|
|
|
|
RangeInclusiveNew, sym::range_inclusive_new, range_inclusive_new_method, Target::Method(MethodKind::Inherent), GenericRequirement::None;
|
|
|
|
Range, sym::Range, range_struct, Target::Struct, GenericRequirement::None;
|
|
|
|
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None;
|
|
|
|
RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
|
2023-05-18 10:03:15 +00:00
|
|
|
String, sym::String, string, Target::Struct, GenericRequirement::None;
|
|
|
|
CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None;
|
2023-01-21 16:29:07 +00:00
|
|
|
}
|