Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/lang_item.rs')
-rw-r--r--crates/hir-def/src/lang_item.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs
index 6d7836d5ae..a09fd658ae 100644
--- a/crates/hir-def/src/lang_item.rs
+++ b/crates/hir-def/src/lang_item.rs
@@ -3,8 +3,8 @@
//! This attribute to tell the compiler about semi built-in std library
//! features, such as Fn family of traits.
use hir_expand::name::Name;
+use intern::{sym, Symbol};
use rustc_hash::FxHashMap;
-use syntax::SmolStr;
use triomphe::Arc;
use crate::{
@@ -191,8 +191,7 @@ impl LangItems {
}
pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangItem> {
- let attrs = db.attrs(item);
- attrs.by_key("lang").string_value().and_then(LangItem::from_str)
+ db.attrs(item).lang_item()
}
pub(crate) fn notable_traits_in_deps(
@@ -253,17 +252,16 @@ macro_rules! language_item_table {
}
impl LangItem {
- pub fn name(self) -> SmolStr {
+ pub fn name(self) -> &'static str {
match self {
- $( LangItem::$variant => SmolStr::new(stringify!($name)), )*
+ $( LangItem::$variant => stringify!($name), )*
}
}
/// Opposite of [`LangItem::name`]
- #[allow(clippy::should_implement_trait)]
- pub fn from_str(name: &str) -> Option<Self> {
- match name {
- $( stringify!($name) => Some(LangItem::$variant), )*
+ pub fn from_symbol(sym: &Symbol) -> Option<Self> {
+ match sym {
+ $(sym if *sym == $module::$name => Some(LangItem::$variant), )*
_ => None,
}
}
@@ -274,7 +272,7 @@ macro_rules! language_item_table {
impl LangItem {
/// Opposite of [`LangItem::name`]
pub fn from_name(name: &hir_expand::name::Name) -> Option<Self> {
- Self::from_str(name.as_str()?)
+ Self::from_symbol(name.symbol())
}
pub fn path(&self, db: &dyn DefDatabase, start_crate: CrateId) -> Option<Path> {
@@ -360,7 +358,7 @@ language_item_table! {
DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None;
Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None;
- Fn, kw::fn, fn_trait, Target::Trait, GenericRequirement::Exact(1);
+ Fn, sym::fn_, fn_trait, Target::Trait, GenericRequirement::Exact(1);
FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1);