Unnamed repository; edit this file 'description' to name the repository.
Use statics + clone instead of const until const can access statics
Lukas Wirth 2024-07-14
parent dd626e7 · commit f2d5107
-rw-r--r--crates/hir-def/src/attr.rs10
-rw-r--r--crates/hir-def/src/body/lower.rs42
-rw-r--r--crates/hir-def/src/builtin_type.rs92
-rw-r--r--crates/hir-def/src/data.rs2
-rw-r--r--crates/hir-def/src/db.rs4
-rw-r--r--crates/hir-def/src/find_path.rs20
-rw-r--r--crates/hir-def/src/item_scope.rs2
-rw-r--r--crates/hir-def/src/item_tree/lower.rs9
-rw-r--r--crates/hir-def/src/lang_item.rs18
-rw-r--r--crates/hir-def/src/nameres/collector.rs36
-rw-r--r--crates/hir-def/src/path/lower.rs6
-rw-r--r--crates/hir-def/src/resolver.rs18
-rw-r--r--crates/hir-expand/src/attrs.rs77
-rw-r--r--crates/hir-expand/src/builtin_fn_macro.rs12
-rw-r--r--crates/hir-expand/src/declarative.rs2
-rw-r--r--crates/hir-expand/src/inert_attr_macro.rs4
-rw-r--r--crates/hir-expand/src/mod_path.rs7
-rw-r--r--crates/hir-expand/src/name.rs17
-rw-r--r--crates/hir-ty/src/autoderef.rs5
-rw-r--r--crates/hir-ty/src/chalk_db.rs21
-rw-r--r--crates/hir-ty/src/diagnostics/expr.rs4
-rw-r--r--crates/hir-ty/src/display.rs5
-rw-r--r--crates/hir-ty/src/infer.rs4
-rw-r--r--crates/hir-ty/src/infer/closure.rs2
-rw-r--r--crates/hir-ty/src/infer/expr.rs4
-rw-r--r--crates/hir-ty/src/infer/mutability.rs4
-rw-r--r--crates/hir-ty/src/infer/path.rs2
-rw-r--r--crates/hir-ty/src/infer/unify.rs2
-rw-r--r--crates/hir-ty/src/lang_items.rs62
-rw-r--r--crates/hir-ty/src/lib.rs2
-rw-r--r--crates/hir-ty/src/mir/eval.rs12
-rw-r--r--crates/hir-ty/src/mir/eval/shim.rs4
-rw-r--r--crates/hir-ty/src/mir/lower/as_place.rs12
-rw-r--r--crates/hir-ty/src/traits.rs6
-rw-r--r--crates/hir/src/lib.rs6
-rw-r--r--crates/hir/src/source_analyzer.rs19
-rw-r--r--crates/ide-assists/src/handlers/convert_bool_then.rs2
-rw-r--r--crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs4
-rw-r--r--crates/ide-assists/src/handlers/generate_is_empty_from_len.rs4
-rw-r--r--crates/ide-assists/src/handlers/inline_call.rs2
-rw-r--r--crates/ide-completion/src/completions.rs3
-rw-r--r--crates/ide-completion/src/completions/dot.rs6
-rw-r--r--crates/ide-completion/src/completions/expr.rs4
-rw-r--r--crates/ide-completion/src/completions/lifetime.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_fields.rs2
-rw-r--r--crates/ide/src/inlay_hints.rs2
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs13
-rw-r--r--crates/intern/src/symbol.rs6
-rw-r--r--crates/intern/src/symbol/symbols.rs159
49 files changed, 395 insertions, 368 deletions
diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs
index a1ffb8c0a7..aacfb07319 100644
--- a/crates/hir-def/src/attr.rs
+++ b/crates/hir-def/src/attr.rs
@@ -9,7 +9,7 @@ use hir_expand::{
attrs::{collect_attrs, Attr, AttrId, RawAttrs},
HirFileId, InFile,
};
-use intern::sym;
+use intern::{sym, Symbol};
use la_arena::{ArenaMap, Idx, RawIdx};
use mbe::DelimiterKind;
use syntax::{
@@ -153,7 +153,7 @@ impl Attrs {
}
pub fn lang_item(&self) -> Option<LangItem> {
- self.by_key("lang").string_value().and_then(LangItem::from_str)
+ self.by_key("lang").string_value().and_then(|it| LangItem::from_symbol(&Symbol::intern(it)))
}
pub fn has_doc_hidden(&self) -> bool {
@@ -200,7 +200,11 @@ impl Attrs {
.segments()
.iter()
.rev()
- .zip([sym::core, sym::prelude, sym::v1, sym::test].iter().rev())
+ .zip(
+ [sym::core.clone(), sym::prelude.clone(), sym::v1.clone(), sym::test.clone()]
+ .iter()
+ .rev(),
+ )
.all(|it| it.0 == it.1)
})
}
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 83ba8f4193..b96745022a 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -188,7 +188,7 @@ impl ExprCollector<'_> {
let is_mutable =
self_param.mut_token().is_some() && self_param.amp_token().is_none();
let binding_id: la_arena::Idx<Binding> = self.alloc_binding(
- Name::new_symbol_root(sym::self_),
+ Name::new_symbol_root(sym::self_.clone()),
BindingAnnotation::new(is_mutable, false),
);
self.body.self_param = Some(binding_id);
@@ -1732,14 +1732,14 @@ impl ExprCollector<'_> {
let Some(new_v1_formatted) = LangItem::FormatArguments.ty_rel_path(
self.db,
self.krate,
- Name::new_symbol_root(sym::new_v1_formatted),
+ Name::new_symbol_root(sym::new_v1_formatted.clone()),
) else {
return self.missing_expr();
};
let Some(unsafe_arg_new) = LangItem::FormatUnsafeArg.ty_rel_path(
self.db,
self.krate,
- Name::new_symbol_root(sym::new),
+ Name::new_symbol_root(sym::new.clone()),
) else {
return self.missing_expr();
};
@@ -1822,10 +1822,10 @@ impl ExprCollector<'_> {
self.db,
self.krate,
match alignment {
- Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left),
- Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right),
- Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center),
- None => Name::new_symbol_root(sym::Unknown),
+ Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left.clone()),
+ Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right.clone()),
+ Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center.clone()),
+ None => Name::new_symbol_root(sym::Unknown.clone()),
},
);
match align {
@@ -1851,7 +1851,7 @@ impl ExprCollector<'_> {
let format_placeholder_new = LangItem::FormatPlaceholder.ty_rel_path(
self.db,
self.krate,
- Name::new_symbol_root(sym::new),
+ Name::new_symbol_root(sym::new.clone()),
);
match format_placeholder_new {
Some(path) => self.alloc_expr_desugared(Expr::Path(path)),
@@ -1899,7 +1899,7 @@ impl ExprCollector<'_> {
let count_is = match LangItem::FormatCount.ty_rel_path(
self.db,
self.krate,
- Name::new_symbol_root(sym::Is),
+ Name::new_symbol_root(sym::Is.clone()),
) {
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
None => self.missing_expr(),
@@ -1921,7 +1921,7 @@ impl ExprCollector<'_> {
let count_param = match LangItem::FormatCount.ty_rel_path(
self.db,
self.krate,
- Name::new_symbol_root(sym::Param),
+ Name::new_symbol_root(sym::Param.clone()),
) {
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
None => self.missing_expr(),
@@ -1940,7 +1940,7 @@ impl ExprCollector<'_> {
None => match LangItem::FormatCount.ty_rel_path(
self.db,
self.krate,
- Name::new_symbol_root(sym::Implied),
+ Name::new_symbol_root(sym::Implied.clone()),
) {
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
None => self.missing_expr(),
@@ -1963,16 +1963,16 @@ impl ExprCollector<'_> {
self.db,
self.krate,
Name::new_symbol_root(match ty {
- Format(Display) => sym::new_display,
- Format(Debug) => sym::new_debug,
- Format(LowerExp) => sym::new_lower_exp,
- Format(UpperExp) => sym::new_upper_exp,
- Format(Octal) => sym::new_octal,
- Format(Pointer) => sym::new_pointer,
- Format(Binary) => sym::new_binary,
- Format(LowerHex) => sym::new_lower_hex,
- Format(UpperHex) => sym::new_upper_hex,
- Usize => sym::from_usize,
+ Format(Display) => sym::new_display.clone(),
+ Format(Debug) => sym::new_debug.clone(),
+ Format(LowerExp) => sym::new_lower_exp.clone(),
+ Format(UpperExp) => sym::new_upper_exp.clone(),
+ Format(Octal) => sym::new_octal.clone(),
+ Format(Pointer) => sym::new_pointer.clone(),
+ Format(Binary) => sym::new_binary.clone(),
+ Format(LowerHex) => sym::new_lower_hex.clone(),
+ Format(UpperHex) => sym::new_upper_hex.clone(),
+ Usize => sym::from_usize.clone(),
}),
) {
Some(new_fn) => self.alloc_expr_desugared(Expr::Path(new_fn)),
diff --git a/crates/hir-def/src/builtin_type.rs b/crates/hir-def/src/builtin_type.rs
index 2243f514fe..6dc1c4546e 100644
--- a/crates/hir-def/src/builtin_type.rs
+++ b/crates/hir-def/src/builtin_type.rs
@@ -49,63 +49,67 @@ pub enum BuiltinType {
impl BuiltinType {
#[rustfmt::skip]
- pub const ALL: &'static [(Name, BuiltinType)] = &[
- (Name::new_symbol_root(sym::char), BuiltinType::Char),
- (Name::new_symbol_root(sym::bool), BuiltinType::Bool),
- (Name::new_symbol_root(sym::str), BuiltinType::Str),
-
- (Name::new_symbol_root(sym::isize), BuiltinType::Int(BuiltinInt::Isize)),
- (Name::new_symbol_root(sym::i8), BuiltinType::Int(BuiltinInt::I8)),
- (Name::new_symbol_root(sym::i16), BuiltinType::Int(BuiltinInt::I16)),
- (Name::new_symbol_root(sym::i32), BuiltinType::Int(BuiltinInt::I32)),
- (Name::new_symbol_root(sym::i64), BuiltinType::Int(BuiltinInt::I64)),
- (Name::new_symbol_root(sym::i128), BuiltinType::Int(BuiltinInt::I128)),
-
- (Name::new_symbol_root(sym::usize), BuiltinType::Uint(BuiltinUint::Usize)),
- (Name::new_symbol_root(sym::u8), BuiltinType::Uint(BuiltinUint::U8)),
- (Name::new_symbol_root(sym::u16), BuiltinType::Uint(BuiltinUint::U16)),
- (Name::new_symbol_root(sym::u32), BuiltinType::Uint(BuiltinUint::U32)),
- (Name::new_symbol_root(sym::u64), BuiltinType::Uint(BuiltinUint::U64)),
- (Name::new_symbol_root(sym::u128), BuiltinType::Uint(BuiltinUint::U128)),
-
- (Name::new_symbol_root(sym::f16), BuiltinType::Float(BuiltinFloat::F16)),
- (Name::new_symbol_root(sym::f32), BuiltinType::Float(BuiltinFloat::F32)),
- (Name::new_symbol_root(sym::f64), BuiltinType::Float(BuiltinFloat::F64)),
- (Name::new_symbol_root(sym::f128), BuiltinType::Float(BuiltinFloat::F128)),
- ];
+ pub fn all_builtin_types() -> [(Name, BuiltinType); 19] {
+ [
+ (Name::new_symbol_root(sym::char.clone()), BuiltinType::Char),
+ (Name::new_symbol_root(sym::bool.clone()), BuiltinType::Bool),
+ (Name::new_symbol_root(sym::str.clone()), BuiltinType::Str),
+
+ (Name::new_symbol_root(sym::isize.clone()), BuiltinType::Int(BuiltinInt::Isize)),
+ (Name::new_symbol_root(sym::i8.clone()), BuiltinType::Int(BuiltinInt::I8)),
+ (Name::new_symbol_root(sym::i16.clone()), BuiltinType::Int(BuiltinInt::I16)),
+ (Name::new_symbol_root(sym::i32.clone()), BuiltinType::Int(BuiltinInt::I32)),
+ (Name::new_symbol_root(sym::i64.clone()), BuiltinType::Int(BuiltinInt::I64)),
+ (Name::new_symbol_root(sym::i128.clone()), BuiltinType::Int(BuiltinInt::I128)),
+
+ (Name::new_symbol_root(sym::usize.clone()), BuiltinType::Uint(BuiltinUint::Usize)),
+ (Name::new_symbol_root(sym::u8.clone()), BuiltinType::Uint(BuiltinUint::U8)),
+ (Name::new_symbol_root(sym::u16.clone()), BuiltinType::Uint(BuiltinUint::U16)),
+ (Name::new_symbol_root(sym::u32.clone()), BuiltinType::Uint(BuiltinUint::U32)),
+ (Name::new_symbol_root(sym::u64.clone()), BuiltinType::Uint(BuiltinUint::U64)),
+ (Name::new_symbol_root(sym::u128.clone()), BuiltinType::Uint(BuiltinUint::U128)),
+
+ (Name::new_symbol_root(sym::f16.clone()), BuiltinType::Float(BuiltinFloat::F16)),
+ (Name::new_symbol_root(sym::f32.clone()), BuiltinType::Float(BuiltinFloat::F32)),
+ (Name::new_symbol_root(sym::f64.clone()), BuiltinType::Float(BuiltinFloat::F64)),
+ (Name::new_symbol_root(sym::f128.clone()), BuiltinType::Float(BuiltinFloat::F128)),
+ ]
+ }
pub fn by_name(name: &Name) -> Option<Self> {
- Self::ALL.iter().find_map(|(n, ty)| if n == name { Some(*ty) } else { None })
+ Self::all_builtin_types()
+ .iter()
+ .find_map(|(n, ty)| if n == name { Some(*ty) } else { None })
}
}
impl AsName for BuiltinType {
fn as_name(&self) -> Name {
match self {
- BuiltinType::Char => Name::new_symbol_root(sym::char),
- BuiltinType::Bool => Name::new_symbol_root(sym::bool),
- BuiltinType::Str => Name::new_symbol_root(sym::str),
+ BuiltinType::Char => Name::new_symbol_root(sym::char.clone()),
+ BuiltinType::Bool => Name::new_symbol_root(sym::bool.clone()),
+ BuiltinType::Str => Name::new_symbol_root(sym::str.clone()),
BuiltinType::Int(it) => match it {
- BuiltinInt::Isize => Name::new_symbol_root(sym::isize),
- BuiltinInt::I8 => Name::new_symbol_root(sym::i8),
- BuiltinInt::I16 => Name::new_symbol_root(sym::i16),
- BuiltinInt::I32 => Name::new_symbol_root(sym::i32),
- BuiltinInt::I64 => Name::new_symbol_root(sym::i64),
- BuiltinInt::I128 => Name::new_symbol_root(sym::i128),
+ BuiltinInt::Isize => Name::new_symbol_root(sym::isize.clone()),
+ BuiltinInt::I8 => Name::new_symbol_root(sym::i8.clone()),
+ BuiltinInt::I16 => Name::new_symbol_root(sym::i16.clone()),
+ BuiltinInt::I32 => Name::new_symbol_root(sym::i32.clone()),
+ BuiltinInt::I64 => Name::new_symbol_root(sym::i64.clone()),
+ BuiltinInt::I128 => Name::new_symbol_root(sym::i128.clone()),
},
BuiltinType::Uint(it) => match it {
- BuiltinUint::Usize => Name::new_symbol_root(sym::usize),
- BuiltinUint::U8 => Name::new_symbol_root(sym::u8),
- BuiltinUint::U16 => Name::new_symbol_root(sym::u16),
- BuiltinUint::U32 => Name::new_symbol_root(sym::u32),
- BuiltinUint::U64 => Name::new_symbol_root(sym::u64),
- BuiltinUint::U128 => Name::new_symbol_root(sym::u128),
+ BuiltinUint::Usize => Name::new_symbol_root(sym::usize.clone()),
+ BuiltinUint::U8 => Name::new_symbol_root(sym::u8.clone()),
+ BuiltinUint::U16 => Name::new_symbol_root(sym::u16.clone()),
+ BuiltinUint::U32 => Name::new_symbol_root(sym::u32.clone()),
+ BuiltinUint::U64 => Name::new_symbol_root(sym::u64.clone()),
+ BuiltinUint::U128 => Name::new_symbol_root(sym::u128.clone()),
},
BuiltinType::Float(it) => match it {
- BuiltinFloat::F16 => Name::new_symbol_root(sym::f16),
- BuiltinFloat::F32 => Name::new_symbol_root(sym::f32),
- BuiltinFloat::F64 => Name::new_symbol_root(sym::f64),
- BuiltinFloat::F128 => Name::new_symbol_root(sym::f128),
+ BuiltinFloat::F16 => Name::new_symbol_root(sym::f16.clone()),
+ BuiltinFloat::F32 => Name::new_symbol_root(sym::f32.clone()),
+ BuiltinFloat::F64 => Name::new_symbol_root(sym::f64.clone()),
+ BuiltinFloat::F128 => Name::new_symbol_root(sym::f128.clone()),
},
}
}
diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs
index f60a433c4d..964a5f04bf 100644
--- a/crates/hir-def/src/data.rs
+++ b/crates/hir-def/src/data.rs
@@ -485,7 +485,7 @@ impl ExternCrateDeclData {
let name = extern_crate.name.clone();
let krate = loc.container.krate();
- let crate_id = if name == sym::self_ {
+ let crate_id = if name == sym::self_.clone() {
Some(krate)
} else {
db.crate_def_map(krate)
diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs
index 0a14904f0b..eac8f0dd74 100644
--- a/crates/hir-def/src/db.rs
+++ b/crates/hir-def/src/db.rs
@@ -262,8 +262,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
let attrs = item_tree.raw_attrs(AttrOwner::TopLevel);
for attr in &**attrs {
match attr.path().as_ident() {
- Some(ident) if *ident == sym::no_std => return true,
- Some(ident) if *ident == sym::cfg_attr => {}
+ Some(ident) if *ident == sym::no_std.clone() => return true,
+ Some(ident) if *ident == sym::cfg_attr.clone() => {}
_ => continue,
}
diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs
index e32add93c5..a3a602c2c1 100644
--- a/crates/hir-def/src/find_path.rs
+++ b/crates/hir-def/src/find_path.rs
@@ -415,13 +415,13 @@ fn select_best_path(
(Unstable, Stable) => return new_path,
_ => {}
}
- const STD_CRATES: [Symbol; 3] = [sym::std, sym::core, sym::alloc];
+ let std_crates: [Symbol; 3] = [sym::std.clone(), sym::core.clone(), sym::alloc.clone()];
let choose = |new: (ModPath, _), old: (ModPath, _)| {
let (new_path, _) = &new;
let (old_path, _) = &old;
- let new_has_prelude = new_path.segments().iter().any(|seg| *seg == sym::prelude);
- let old_has_prelude = old_path.segments().iter().any(|seg| *seg == sym::prelude);
+ let new_has_prelude = new_path.segments().iter().any(|seg| *seg == sym::prelude.clone());
+ let old_has_prelude = old_path.segments().iter().any(|seg| *seg == sym::prelude.clone());
match (new_has_prelude, old_has_prelude, cfg.prefer_prelude) {
(true, false, true) | (false, true, false) => new,
(true, false, false) | (false, true, true) => old,
@@ -443,19 +443,19 @@ fn select_best_path(
match (old_path.0.segments().first(), new_path.0.segments().first()) {
(Some(old), Some(new))
- if STD_CRATES.contains(old.symbol()) && STD_CRATES.contains(new.symbol()) =>
+ if std_crates.contains(old.symbol()) && std_crates.contains(new.symbol()) =>
{
let rank = match cfg.prefer_no_std {
false => |name: &Name| match name {
- name if *name == sym::core => 0,
- name if *name == sym::alloc => 1,
- name if *name == sym::std => 2,
+ name if *name == sym::core.clone() => 0,
+ name if *name == sym::alloc.clone() => 1,
+ name if *name == sym::std.clone() => 2,
_ => unreachable!(),
},
true => |name: &Name| match name {
- name if *name == sym::core => 2,
- name if *name == sym::alloc => 1,
- name if *name == sym::std => 0,
+ name if *name == sym::core.clone() => 2,
+ name if *name == sym::alloc.clone() => 1,
+ name if *name == sym::std.clone() => 0,
_ => unreachable!(),
},
};
diff --git a/crates/hir-def/src/item_scope.rs b/crates/hir-def/src/item_scope.rs
index d86c0667a0..092c0a1dfd 100644
--- a/crates/hir-def/src/item_scope.rs
+++ b/crates/hir-def/src/item_scope.rs
@@ -119,7 +119,7 @@ struct DeriveMacroInvocation {
}
pub(crate) static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| {
- BuiltinType::ALL
+ BuiltinType::all_builtin_types()
.iter()
.map(|(name, ty)| (name.clone(), PerNs::types((*ty).into(), Visibility::Public, None)))
.collect()
diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs
index 496686b4f9..5c80da9304 100644
--- a/crates/hir-def/src/item_tree/lower.rs
+++ b/crates/hir-def/src/item_tree/lower.rs
@@ -324,7 +324,8 @@ impl<'a> Ctx<'a> {
let self_type = match self_param.ty() {
Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
None => {
- let self_type = TypeRef::Path(Name::new_symbol_root(sym::Self_).into());
+ let self_type =
+ TypeRef::Path(Name::new_symbol_root(sym::Self_.clone()).into());
match self_param.kind() {
ast::SelfParamKind::Owned => self_type,
ast::SelfParamKind::Ref => TypeRef::Reference(
@@ -670,7 +671,7 @@ impl<'a> Ctx<'a> {
// Traits and trait aliases get the Self type as an implicit first type parameter.
generics.type_or_consts.alloc(
TypeParamData {
- name: Some(Name::new_symbol_root(sym::Self_)),
+ name: Some(Name::new_symbol_root(sym::Self_.clone())),
default: None,
provenance: TypeParamProvenance::TraitSelf,
}
@@ -681,7 +682,7 @@ impl<'a> Ctx<'a> {
generics.fill_bounds(
&self.body_ctx,
bounds,
- Either::Left(TypeRef::Path(Name::new_symbol_root(sym::Self_).into())),
+ Either::Left(TypeRef::Path(Name::new_symbol_root(sym::Self_.clone()).into())),
);
}
@@ -746,7 +747,7 @@ fn desugar_future_path(orig: TypeRef) -> Path {
let mut generic_args: Vec<_> =
std::iter::repeat(None).take(path.segments().len() - 1).collect();
let binding = AssociatedTypeBinding {
- name: Name::new_symbol_root(sym::Output),
+ name: Name::new_symbol_root(sym::Output.clone()),
args: None,
type_ref: Some(orig),
bounds: Box::default(),
diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs
index 4d17650285..07b27659ab 100644
--- a/crates/hir-def/src/lang_item.rs
+++ b/crates/hir-def/src/lang_item.rs
@@ -192,8 +192,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(
@@ -261,18 +260,9 @@ macro_rules! language_item_table {
}
/// Opposite of [`LangItem::name`]
- #[allow(clippy::should_implement_trait)]
- pub fn from_str(name: &str) -> Option<Self> {
- match name {
- $( stringify!($name) => Some(LangItem::$variant), )*
- _ => None,
- }
- }
-
- /// Opposite of [`LangItem::name`]
- pub fn from_symbol(sym: Symbol) -> Option<Self> {
+ pub fn from_symbol(sym: &Symbol) -> Option<Self> {
match sym {
- $(sym if sym == $module::$name => Some(LangItem::$variant), )*
+ $(sym if *sym == $module::$name => Some(LangItem::$variant), )*
_ => None,
}
}
@@ -283,7 +273,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> {
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index 30d4a79a80..f14679f6c2 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -294,24 +294,24 @@ impl DefCollector<'_> {
let Some(attr_name) = attr.path.as_ident() else { continue };
match () {
- () if *attr_name == sym::recursion_limit => {
+ () if *attr_name == sym::recursion_limit.clone() => {
if let Some(limit) = attr.string_value() {
if let Ok(limit) = limit.parse() {
crate_data.recursion_limit = Some(limit);
}
}
}
- () if *attr_name == sym::crate_type => {
+ () if *attr_name == sym::crate_type.clone() => {
if let Some("proc-macro") = attr.string_value() {
self.is_proc_macro = true;
}
}
- () if *attr_name == sym::no_core => crate_data.no_core = true,
- () if *attr_name == sym::no_std => crate_data.no_std = true,
- () if *attr_name == sym::rustc_coherence_is_core => {
+ () if *attr_name == sym::no_core.clone() => crate_data.no_core = true,
+ () if *attr_name == sym::no_std.clone() => crate_data.no_std = true,
+ () if *attr_name == sym::rustc_coherence_is_core.clone() => {
crate_data.rustc_coherence_is_core = true;
}
- () if *attr_name == sym::feature => {
+ () if *attr_name == sym::feature.clone() => {
let features = attr
.parse_path_comma_token_tree(self.db.upcast())
.into_iter()
@@ -322,13 +322,13 @@ impl DefCollector<'_> {
});
crate_data.unstable_features.extend(features);
}
- () if *attr_name == sym::register_attr => {
+ () if *attr_name == sym::register_attr.clone() => {
if let Some(ident) = attr.single_ident_value() {
crate_data.registered_attrs.push(ident.text.clone());
cov_mark::hit!(register_attr);
}
}
- () if *attr_name == sym::register_tool => {
+ () if *attr_name == sym::register_tool.clone() => {
if let Some(ident) = attr.single_ident_value() {
crate_data.registered_tools.push(ident.text.clone());
cov_mark::hit!(register_tool);
@@ -538,20 +538,20 @@ impl DefCollector<'_> {
}
let krate = if self.def_map.data.no_std {
- Name::new_symbol_root(sym::core)
- } else if self.def_map.extern_prelude().any(|(name, _)| *name == sym::std) {
- Name::new_symbol_root(sym::std)
+ Name::new_symbol_root(sym::core.clone())
+ } else if self.def_map.extern_prelude().any(|(name, _)| *name == sym::std.clone()) {
+ Name::new_symbol_root(sym::std.clone())
} else {
// If `std` does not exist for some reason, fall back to core. This mostly helps
// keep r-a's own tests minimal.
- Name::new_symbol_root(sym::core)
+ Name::new_symbol_root(sym::core.clone())
};
let edition = match self.def_map.data.edition {
- Edition::Edition2015 => Name::new_symbol_root(sym::rust_2015),
- Edition::Edition2018 => Name::new_symbol_root(sym::rust_2018),
- Edition::Edition2021 => Name::new_symbol_root(sym::rust_2021),
- Edition::Edition2024 => Name::new_symbol_root(sym::rust_2024),
+ Edition::Edition2015 => Name::new_symbol_root(sym::rust_2015.clone()),
+ Edition::Edition2018 => Name::new_symbol_root(sym::rust_2018.clone()),
+ Edition::Edition2021 => Name::new_symbol_root(sym::rust_2021.clone()),
+ Edition::Edition2024 => Name::new_symbol_root(sym::rust_2024.clone()),
};
let path_kind = match self.def_map.data.edition {
@@ -560,7 +560,7 @@ impl DefCollector<'_> {
};
let path = ModPath::from_segments(
path_kind,
- [krate, Name::new_symbol_root(sym::prelude), edition],
+ [krate, Name::new_symbol_root(sym::prelude.clone()), edition],
);
let (per_ns, _) =
@@ -844,7 +844,7 @@ impl DefCollector<'_> {
}
fn resolve_extern_crate(&self, name: &Name) -> Option<CrateRootModuleId> {
- if *name == sym::self_ {
+ if *name == sym::self_.clone() {
cov_mark::hit!(extern_crate_self_as);
Some(self.def_map.crate_root())
} else {
diff --git a/crates/hir-def/src/path/lower.rs b/crates/hir-def/src/path/lower.rs
index 22397df961..7c39773aa6 100644
--- a/crates/hir-def/src/path/lower.rs
+++ b/crates/hir-def/src/path/lower.rs
@@ -60,7 +60,7 @@ pub(super) fn lower_path(ctx: &LowerCtx<'_>, mut path: ast::Path) -> Option<Path
segments.push(name);
}
ast::PathSegmentKind::SelfTypeKw => {
- segments.push(Name::new_symbol_root(sym::Self_));
+ segments.push(Name::new_symbol_root(sym::Self_.clone()));
}
ast::PathSegmentKind::Type { type_ref, trait_ref } => {
assert!(path.qualifier().is_none()); // this can only occur at the first segment
@@ -268,7 +268,7 @@ fn lower_generic_args_from_fn_path(
let bindings = if let Some(ret_type) = ret_type {
let type_ref = TypeRef::from_ast_opt(ctx, ret_type.ty());
Box::new([AssociatedTypeBinding {
- name: Name::new_symbol_root(sym::Output),
+ name: Name::new_symbol_root(sym::Output.clone()),
args: None,
type_ref: Some(type_ref),
bounds: Box::default(),
@@ -277,7 +277,7 @@ fn lower_generic_args_from_fn_path(
// -> ()
let type_ref = TypeRef::Tuple(Vec::new());
Box::new([AssociatedTypeBinding {
- name: Name::new_symbol_root(sym::Output),
+ name: Name::new_symbol_root(sym::Output.clone()),
args: None,
type_ref: Some(type_ref),
bounds: Box::default(),
diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs
index 4931418546..c196f00281 100644
--- a/crates/hir-def/src/resolver.rs
+++ b/crates/hir-def/src/resolver.rs
@@ -194,12 +194,12 @@ impl Resolver {
}
}
&Scope::ImplDefScope(impl_) => {
- if *first_name == sym::Self_ {
+ if *first_name == sym::Self_.clone() {
return Some((TypeNs::SelfType(impl_), remaining_idx(), None));
}
}
&Scope::AdtScope(adt) => {
- if *first_name == sym::Self_ {
+ if *first_name == sym::Self_.clone() {
return Some((TypeNs::AdtSelfType(adt), remaining_idx(), None));
}
}
@@ -291,7 +291,7 @@ impl Resolver {
}
};
let n_segments = path.segments().len();
- let tmp = Name::new_symbol_root(sym::Self_);
+ let tmp = Name::new_symbol_root(sym::self_.clone());
let first_name = if path.is_self() { &tmp } else { path.segments().first()? };
let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
if skip_to_mod {
@@ -322,7 +322,7 @@ impl Resolver {
}
}
&Scope::ImplDefScope(impl_) => {
- if *first_name == sym::Self_ {
+ if *first_name == sym::Self_.clone() {
return Some(ResolveValueResult::ValueNs(
ValueNs::ImplSelf(impl_),
None,
@@ -349,7 +349,7 @@ impl Resolver {
}
}
&Scope::ImplDefScope(impl_) => {
- if *first_name == sym::Self_ {
+ if *first_name == sym::Self_.clone() {
return Some(ResolveValueResult::Partial(
TypeNs::SelfType(impl_),
1,
@@ -358,7 +358,7 @@ impl Resolver {
}
}
Scope::AdtScope(adt) => {
- if *first_name == sym::Self_ {
+ if *first_name == sym::Self_.clone() {
let ty = TypeNs::AdtSelfType(*adt);
return Some(ResolveValueResult::Partial(ty, 1, None));
}
@@ -422,7 +422,7 @@ impl Resolver {
}
pub fn resolve_lifetime(&self, lifetime: &LifetimeRef) -> Option<LifetimeNs> {
- if lifetime.name == sym::tick_static {
+ if lifetime.name == sym::tick_static.clone() {
return Some(LifetimeNs::Static);
}
@@ -778,10 +778,10 @@ impl Scope {
}
}
Scope::ImplDefScope(i) => {
- acc.add(&Name::new_symbol_root(sym::Self_), ScopeDef::ImplSelfType(*i));
+ acc.add(&Name::new_symbol_root(sym::Self_.clone()), ScopeDef::ImplSelfType(*i));
}
Scope::AdtScope(i) => {
- acc.add(&Name::new_symbol_root(sym::Self_), ScopeDef::AdtSelfType(*i));
+ acc.add(&Name::new_symbol_root(sym::Self_.clone()), ScopeDef::AdtSelfType(*i));
}
Scope::ExprScope(scope) => {
if let Some((label, name)) = scope.expr_scopes.label(scope.scope_id) {
diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs
index 6afa7a40f1..36636a228f 100644
--- a/crates/hir-expand/src/attrs.rs
+++ b/crates/hir-expand/src/attrs.rs
@@ -59,7 +59,10 @@ impl RawAttrs {
text: SmolStr::new(format_smolstr!("\"{}\"", Self::escape_chars(doc))),
span,
}))),
- path: Interned::new(ModPath::from(Name::new_symbol(sym::doc, span.ctx))),
+ path: Interned::new(ModPath::from(Name::new_symbol(
+ sym::doc.clone(),
+ span.ctx,
+ ))),
ctxt: span.ctx,
}
}),
@@ -116,47 +119,47 @@ impl RawAttrs {
pub fn filter(self, db: &dyn ExpandDatabase, krate: CrateId) -> RawAttrs {
let has_cfg_attrs = self
.iter()
- .any(|attr| attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr));
+ .any(|attr| attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr.clone()));
if !has_cfg_attrs {
return self;
}
let crate_graph = db.crate_graph();
- let new_attrs = self
- .iter()
- .flat_map(|attr| -> SmallVec<[_; 1]> {
- let is_cfg_attr = attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr);
- if !is_cfg_attr {
- return smallvec![attr.clone()];
- }
-
- let subtree = match attr.token_tree_value() {
- Some(it) => it,
- _ => return smallvec![attr.clone()],
- };
+ let new_attrs =
+ self.iter()
+ .flat_map(|attr| -> SmallVec<[_; 1]> {
+ let is_cfg_attr =
+ attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr.clone());
+ if !is_cfg_attr {
+ return smallvec![attr.clone()];
+ }
- let (cfg, parts) = match parse_cfg_attr_input(subtree) {
- Some(it) => it,
- None => return smallvec![attr.clone()],
- };
- let index = attr.id;
- let attrs = parts
- .enumerate()
- .take(1 << AttrId::CFG_ATTR_BITS)
- .filter_map(|(idx, attr)| Attr::from_tt(db, attr, index.with_cfg_attr(idx)));
-
- let cfg_options = &crate_graph[krate].cfg_options;
- let cfg = Subtree { delimiter: subtree.delimiter, token_trees: Box::from(cfg) };
- let cfg = CfgExpr::parse(&cfg);
- if cfg_options.check(&cfg) == Some(false) {
- smallvec![]
- } else {
- cov_mark::hit!(cfg_attr_active);
-
- attrs.collect()
- }
- })
- .collect::<Vec<_>>();
+ let subtree = match attr.token_tree_value() {
+ Some(it) => it,
+ _ => return smallvec![attr.clone()],
+ };
+
+ let (cfg, parts) = match parse_cfg_attr_input(subtree) {
+ Some(it) => it,
+ None => return smallvec![attr.clone()],
+ };
+ let index = attr.id;
+ let attrs = parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(
+ |(idx, attr)| Attr::from_tt(db, attr, index.with_cfg_attr(idx)),
+ );
+
+ let cfg_options = &crate_graph[krate].cfg_options;
+ let cfg = Subtree { delimiter: subtree.delimiter, token_trees: Box::from(cfg) };
+ let cfg = CfgExpr::parse(&cfg);
+ if cfg_options.check(&cfg) == Some(false) {
+ smallvec![]
+ } else {
+ cov_mark::hit!(cfg_attr_active);
+
+ attrs.collect()
+ }
+ })
+ .collect::<Vec<_>>();
let entries = if new_attrs.is_empty() {
None
} else {
@@ -384,7 +387,7 @@ impl Attr {
}
pub fn cfg(&self) -> Option<CfgExpr> {
- if *self.path.as_ident()? == sym::cfg {
+ if *self.path.as_ident()? == sym::cfg.clone() {
self.token_tree_value().map(CfgExpr::parse)
} else {
None
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index e5de5975a2..97867dfc66 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -367,7 +367,11 @@ fn panic_expand(
let dollar_crate = dollar_crate(span);
let call_site_span = span_with_call_site_ctxt(db, span, id);
- let mac = if use_panic_2021(db, call_site_span) { sym::panic_2021 } else { sym::panic_2015 };
+ let mac = if use_panic_2021(db, call_site_span) {
+ sym::panic_2021.clone()
+ } else {
+ sym::panic_2015.clone()
+ };
// Expand to a macro call `$crate::panic::panic_{edition}`
let mut call = quote!(call_site_span =>#dollar_crate::panic::#mac!);
@@ -396,9 +400,9 @@ fn unreachable_expand(
let call_site_span = span_with_call_site_ctxt(db, span, id);
let mac = if use_panic_2021(db, call_site_span) {
- sym::unreachable_2021
+ sym::unreachable_2021.clone()
} else {
- sym::unreachable_2015
+ sym::unreachable_2015.clone()
};
// Expand to a macro call `$crate::panic::panic_{edition}`
@@ -431,7 +435,7 @@ fn use_panic_2021(db: &dyn ExpandDatabase, span: Span) -> bool {
// FIXME: Record allow_internal_unstable in the macro def (not been done yet because it
// would consume quite a bit extra memory for all call locs...)
// if let Some(features) = expn.def.allow_internal_unstable {
- // if features.iter().any(|&f| f == sym::edition_panic) {
+ // if features.iter().any(|&f| f == sym::edition_panic.clone()) {
// span = expn.call_site;
// continue;
// }
diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs
index b920d2127a..2e7865ed3b 100644
--- a/crates/hir-expand/src/declarative.rs
+++ b/crates/hir-expand/src/declarative.rs
@@ -114,7 +114,7 @@ impl DeclarativeMacroExpander {
.find(|it| {
it.path
.as_ident()
- .map(|it| *it == sym::rustc_macro_transparency)
+ .map(|it| *it == sym::rustc_macro_transparency.clone())
.unwrap_or(false)
})?
.token_tree_value()?
diff --git a/crates/hir-expand/src/inert_attr_macro.rs b/crates/hir-expand/src/inert_attr_macro.rs
index 7ead7e9390..0c112554e1 100644
--- a/crates/hir-expand/src/inert_attr_macro.rs
+++ b/crates/hir-expand/src/inert_attr_macro.rs
@@ -553,7 +553,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
),
BuiltinAttribute {
- // name: sym::rustc_diagnostic_item,
+ // name: sym::rustc_diagnostic_item.clone(),
name: "rustc_diagnostic_item",
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
// only_local: false,
@@ -562,7 +562,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
// duplicates: ErrorFollowing,
// gate: Gated(
// Stability::Unstable,
- // sym::rustc_attrs,
+ // sym::rustc_attrs.clone(),
// "diagnostic items compiler internal support for linting",
// cfg_fn!(rustc_attrs),
// ),
diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs
index 7ff8b797fa..ed7d551888 100644
--- a/crates/hir-expand/src/mod_path.rs
+++ b/crates/hir-expand/src/mod_path.rs
@@ -120,7 +120,8 @@ impl ModPath {
#[allow(non_snake_case)]
pub fn is_Self(&self) -> bool {
- self.kind == PathKind::Plain && matches!(&*self.segments, [name] if *name == sym::Self_)
+ self.kind == PathKind::Plain
+ && matches!(&*self.segments, [name] if *name == sym::Self_.clone())
}
/// If this path is a single identifier, like `foo`, return its name.
@@ -264,7 +265,7 @@ fn convert_path(
}
ast::PathSegmentKind::SelfTypeKw => ModPath::from_segments(
PathKind::Plain,
- Some(Name::new_symbol(sym::Self_, SyntaxContextId::ROOT)),
+ Some(Name::new_symbol(sym::Self_.clone(), SyntaxContextId::ROOT)),
),
ast::PathSegmentKind::CrateKw => ModPath::from_segments(PathKind::Crate, iter::empty()),
ast::PathSegmentKind::SelfKw => handle_super_kw(0)?,
@@ -396,7 +397,7 @@ macro_rules! __path {
($start:ident $(:: $seg:ident)*) => ({
$crate::__known_path!($start $(:: $seg)*);
$crate::mod_path::ModPath::from_segments($crate::mod_path::PathKind::Abs, vec![
- $crate::name::Name::new_symbol_root(intern::sym::$start), $($crate::name::Name::new_symbol_root(intern::sym::$seg),)*
+ $crate::name::Name::new_symbol_root(intern::sym::$start.clone()), $($crate::name::Name::new_symbol_root(intern::sym::$seg.clone()),)*
])
});
}
diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs
index da0adbef16..67e73f7fc2 100644
--- a/crates/hir-expand/src/name.rs
+++ b/crates/hir-expand/src/name.rs
@@ -2,7 +2,7 @@
use std::fmt;
-use intern::{sym::MISSING_NAME, Symbol};
+use intern::{sym, Symbol};
use span::SyntaxContextId;
use syntax::{ast, format_smolstr, utils::is_raw_identifier, SmolStr};
@@ -13,12 +13,21 @@ use syntax::{ast, format_smolstr, utils::is_raw_identifier, SmolStr};
/// Note that `Name` holds and prints escaped name i.e. prefixed with "r#" when it
/// is a raw identifier. Use [`unescaped()`][Name::unescaped] when you need the
/// name without "r#".
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Name {
symbol: Symbol,
ctx: (),
}
+impl fmt::Debug for Name {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Name")
+ .field("symbol", &self.symbol.as_str())
+ .field("ctx", &self.ctx)
+ .finish()
+ }
+}
+
impl Ord for Name {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.symbol.as_str().cmp(other.symbol.as_str())
@@ -116,8 +125,8 @@ impl Name {
/// Ideally, we want a `gensym` semantics for missing names -- each missing
/// name is equal only to itself. It's not clear how to implement this in
/// salsa though, so we punt on that bit for a moment.
- pub const fn missing() -> Name {
- Name { symbol: MISSING_NAME, ctx: () }
+ pub fn missing() -> Name {
+ Name { symbol: sym::MISSING_NAME.clone(), ctx: () }
}
/// Returns true if this is a fake name for things missing in the source code. See
diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs
index 736379a3d8..ecfc1ff99e 100644
--- a/crates/hir-ty/src/autoderef.rs
+++ b/crates/hir-ty/src/autoderef.rs
@@ -152,8 +152,9 @@ pub(crate) fn deref_by_trait(
let deref_trait =
db.lang_item(table.trait_env.krate, LangItem::Deref).and_then(|l| l.as_trait())?;
- let target =
- db.trait_data(deref_trait).associated_type_by_name(&Name::new_symbol_root(sym::Target))?;
+ let target = db
+ .trait_data(deref_trait)
+ .associated_type_by_name(&Name::new_symbol_root(sym::Target.clone()))?;
let projection = {
let b = TyBuilder::subst_for_def(db, deref_trait, None);
diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs
index 868827b2b6..d506e00ca1 100644
--- a/crates/hir-ty/src/chalk_db.rs
+++ b/crates/hir-ty/src/chalk_db.rs
@@ -289,17 +289,16 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
chalk_ir::Binders::new(binders, bound)
}
crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => {
- if let Some((future_trait, future_output)) = self
- .db
- .lang_item(self.krate, LangItem::Future)
- .and_then(|item| item.as_trait())
- .and_then(|trait_| {
- let alias = self
- .db
- .trait_data(trait_)
- .associated_type_by_name(&Name::new_symbol_root(sym::Output))?;
- Some((trait_, alias))
- })
+ if let Some((future_trait, future_output)) =
+ self.db
+ .lang_item(self.krate, LangItem::Future)
+ .and_then(|item| item.as_trait())
+ .and_then(|trait_| {
+ let alias = self.db.trait_data(trait_).associated_type_by_name(
+ &Name::new_symbol_root(sym::Output.clone()),
+ )?;
+ Some((trait_, alias))
+ })
{
// Making up Symbol’s value as variable is void: AsyncBlock<T>:
//
diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs
index 048bdd2c38..e52fae06d7 100644
--- a/crates/hir-ty/src/diagnostics/expr.rs
+++ b/crates/hir-ty/src/diagnostics/expr.rs
@@ -423,7 +423,9 @@ impl FilterMapNextChecker {
ItemContainerId::TraitId(iterator_trait_id) => {
let iterator_trait_items = &db.trait_data(iterator_trait_id).items;
iterator_trait_items.iter().find_map(|(name, it)| match it {
- &AssocItemId::FunctionId(id) if *name == sym::filter_map => Some(id),
+ &AssocItemId::FunctionId(id) if *name == sym::filter_map.clone() => {
+ Some(id)
+ }
_ => None,
})
}
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index 2a644de1fb..f15f6575b7 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -1171,8 +1171,9 @@ impl HirDisplay for Ty {
.lang_item(body.module(db.upcast()).krate(), LangItem::Future)
.and_then(LangItemTarget::as_trait);
let output = future_trait.and_then(|t| {
- db.trait_data(t)
- .associated_type_by_name(&Name::new_symbol_root(sym::Output))
+ db.trait_data(t).associated_type_by_name(&Name::new_symbol_root(
+ sym::Output.clone(),
+ ))
});
write!(f, "impl ")?;
if let Some(t) = future_trait {
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 928a3f5e49..82f4ad01e0 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -1425,7 +1425,9 @@ impl<'a> InferenceContext<'a> {
}
fn resolve_output_on(&self, trait_: TraitId) -> Option<TypeAliasId> {
- self.db.trait_data(trait_).associated_type_by_name(&Name::new_symbol_root(sym::Output))
+ self.db
+ .trait_data(trait_)
+ .associated_type_by_name(&Name::new_symbol_root(sym::Output.clone()))
}
fn resolve_lang_trait(&self, lang: LangItem) -> Option<TraitId> {
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs
index f54081a276..417fca5dcd 100644
--- a/crates/hir-ty/src/infer/closure.rs
+++ b/crates/hir-ty/src/infer/closure.rs
@@ -623,7 +623,7 @@ impl InferenceContext<'_> {
if let Some(deref_fn) = self
.db
.trait_data(deref_trait)
- .method_by_name(&Name::new_symbol_root(sym::deref_mut))
+ .method_by_name(&Name::new_symbol_root(sym::deref_mut.clone()))
{
break 'b deref_fn == f;
}
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index a0c3f48642..7857d207be 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -650,7 +650,7 @@ impl InferenceContext<'_> {
if let Some(deref_fn) = self
.db
.trait_data(deref_trait)
- .method_by_name(&Name::new_symbol_root(sym::deref))
+ .method_by_name(&Name::new_symbol_root(sym::deref.clone()))
{
// FIXME: this is wrong in multiple ways, subst is empty, and we emit it even for builtin deref (note that
// the mutability is not wrong, and will be fixed in `self.infer_mut`).
@@ -791,7 +791,7 @@ impl InferenceContext<'_> {
if let Some(func) = self
.db
.trait_data(index_trait)
- .method_by_name(&Name::new_symbol_root(sym::index))
+ .method_by_name(&Name::new_symbol_root(sym::index.clone()))
{
let substs = TyBuilder::subst_for_def(self.db, index_trait, None)
.push(self_ty.clone())
diff --git a/crates/hir-ty/src/infer/mutability.rs b/crates/hir-ty/src/infer/mutability.rs
index ca8996fb89..abb702d150 100644
--- a/crates/hir-ty/src/infer/mutability.rs
+++ b/crates/hir-ty/src/infer/mutability.rs
@@ -112,7 +112,7 @@ impl InferenceContext<'_> {
if let Some(index_fn) = self
.db
.trait_data(index_trait)
- .method_by_name(&Name::new_symbol_root(sym::index_mut))
+ .method_by_name(&Name::new_symbol_root(sym::index_mut.clone()))
{
*f = index_fn;
let base_adjustments = self
@@ -145,7 +145,7 @@ impl InferenceContext<'_> {
if let Some(deref_fn) = self
.db
.trait_data(deref_trait)
- .method_by_name(&Name::new_symbol_root(sym::deref_mut))
+ .method_by_name(&Name::new_symbol_root(sym::deref_mut.clone()))
{
*f = deref_fn;
}
diff --git a/crates/hir-ty/src/infer/path.rs b/crates/hir-ty/src/infer/path.rs
index 67a0ec60f1..0b44bbec70 100644
--- a/crates/hir-ty/src/infer/path.rs
+++ b/crates/hir-ty/src/infer/path.rs
@@ -228,7 +228,7 @@ impl InferenceContext<'_> {
Path::LangItem(..) => (
PathSegment {
name: {
- _d = Name::new_symbol_root(sym::Unknown);
+ _d = Name::new_symbol_root(sym::Unknown.clone());
&_d
},
args_and_bindings: None,
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index 800b06afbd..7ee63af1c2 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -783,7 +783,7 @@ impl<'a> InferenceTable<'a> {
let fn_once_trait = FnTrait::FnOnce.get_id(self.db, krate)?;
let trait_data = self.db.trait_data(fn_once_trait);
let output_assoc_type =
- trait_data.associated_type_by_name(&Name::new_symbol_root(sym::Output))?;
+ trait_data.associated_type_by_name(&Name::new_symbol_root(sym::Output.clone()))?;
let mut arg_tys = Vec::with_capacity(num_args);
let arg_ty = TyBuilder::tuple(num_args)
diff --git a/crates/hir-ty/src/lang_items.rs b/crates/hir-ty/src/lang_items.rs
index 69ff03eb49..f704b59d30 100644
--- a/crates/hir-ty/src/lang_items.rs
+++ b/crates/hir-ty/src/lang_items.rs
@@ -21,43 +21,53 @@ pub fn lang_items_for_bin_op(op: syntax::ast::BinaryOp) -> Option<(Name, LangIte
Some(match op {
BinaryOp::LogicOp(_) => return None,
BinaryOp::ArithOp(aop) => match aop {
- ArithOp::Add => (Name::new_symbol_root(sym::add), LangItem::Add),
- ArithOp::Mul => (Name::new_symbol_root(sym::mul), LangItem::Mul),
- ArithOp::Sub => (Name::new_symbol_root(sym::sub), LangItem::Sub),
- ArithOp::Div => (Name::new_symbol_root(sym::div), LangItem::Div),
- ArithOp::Rem => (Name::new_symbol_root(sym::rem), LangItem::Rem),
- ArithOp::Shl => (Name::new_symbol_root(sym::shl), LangItem::Shl),
- ArithOp::Shr => (Name::new_symbol_root(sym::shr), LangItem::Shr),
- ArithOp::BitXor => (Name::new_symbol_root(sym::bitxor), LangItem::BitXor),
- ArithOp::BitOr => (Name::new_symbol_root(sym::bitor), LangItem::BitOr),
- ArithOp::BitAnd => (Name::new_symbol_root(sym::bitand), LangItem::BitAnd),
+ ArithOp::Add => (Name::new_symbol_root(sym::add.clone()), LangItem::Add),
+ ArithOp::Mul => (Name::new_symbol_root(sym::mul.clone()), LangItem::Mul),
+ ArithOp::Sub => (Name::new_symbol_root(sym::sub.clone()), LangItem::Sub),
+ ArithOp::Div => (Name::new_symbol_root(sym::div.clone()), LangItem::Div),
+ ArithOp::Rem => (Name::new_symbol_root(sym::rem.clone()), LangItem::Rem),
+ ArithOp::Shl => (Name::new_symbol_root(sym::shl.clone()), LangItem::Shl),
+ ArithOp::Shr => (Name::new_symbol_root(sym::shr.clone()), LangItem::Shr),
+ ArithOp::BitXor => (Name::new_symbol_root(sym::bitxor.clone()), LangItem::BitXor),
+ ArithOp::BitOr => (Name::new_symbol_root(sym::bitor.clone()), LangItem::BitOr),
+ ArithOp::BitAnd => (Name::new_symbol_root(sym::bitand.clone()), LangItem::BitAnd),
},
BinaryOp::Assignment { op: Some(aop) } => match aop {
- ArithOp::Add => (Name::new_symbol_root(sym::add_assign), LangItem::AddAssign),
- ArithOp::Mul => (Name::new_symbol_root(sym::mul_assign), LangItem::MulAssign),
- ArithOp::Sub => (Name::new_symbol_root(sym::sub_assign), LangItem::SubAssign),
- ArithOp::Div => (Name::new_symbol_root(sym::div_assign), LangItem::DivAssign),
- ArithOp::Rem => (Name::new_symbol_root(sym::rem_assign), LangItem::RemAssign),
- ArithOp::Shl => (Name::new_symbol_root(sym::shl_assign), LangItem::ShlAssign),
- ArithOp::Shr => (Name::new_symbol_root(sym::shr_assign), LangItem::ShrAssign),
- ArithOp::BitXor => (Name::new_symbol_root(sym::bitxor_assign), LangItem::BitXorAssign),
- ArithOp::BitOr => (Name::new_symbol_root(sym::bitor_assign), LangItem::BitOrAssign),
- ArithOp::BitAnd => (Name::new_symbol_root(sym::bitand_assign), LangItem::BitAndAssign),
+ ArithOp::Add => (Name::new_symbol_root(sym::add_assign.clone()), LangItem::AddAssign),
+ ArithOp::Mul => (Name::new_symbol_root(sym::mul_assign.clone()), LangItem::MulAssign),
+ ArithOp::Sub => (Name::new_symbol_root(sym::sub_assign.clone()), LangItem::SubAssign),
+ ArithOp::Div => (Name::new_symbol_root(sym::div_assign.clone()), LangItem::DivAssign),
+ ArithOp::Rem => (Name::new_symbol_root(sym::rem_assign.clone()), LangItem::RemAssign),
+ ArithOp::Shl => (Name::new_symbol_root(sym::shl_assign.clone()), LangItem::ShlAssign),
+ ArithOp::Shr => (Name::new_symbol_root(sym::shr_assign.clone()), LangItem::ShrAssign),
+ ArithOp::BitXor => {
+ (Name::new_symbol_root(sym::bitxor_assign.clone()), LangItem::BitXorAssign)
+ }
+ ArithOp::BitOr => {
+ (Name::new_symbol_root(sym::bitor_assign.clone()), LangItem::BitOrAssign)
+ }
+ ArithOp::BitAnd => {
+ (Name::new_symbol_root(sym::bitand_assign.clone()), LangItem::BitAndAssign)
+ }
},
BinaryOp::CmpOp(cop) => match cop {
- CmpOp::Eq { negated: false } => (Name::new_symbol_root(sym::eq), LangItem::PartialEq),
- CmpOp::Eq { negated: true } => (Name::new_symbol_root(sym::ne), LangItem::PartialEq),
+ CmpOp::Eq { negated: false } => {
+ (Name::new_symbol_root(sym::eq.clone()), LangItem::PartialEq)
+ }
+ CmpOp::Eq { negated: true } => {
+ (Name::new_symbol_root(sym::ne.clone()), LangItem::PartialEq)
+ }
CmpOp::Ord { ordering: Ordering::Less, strict: false } => {
- (Name::new_symbol_root(sym::le), LangItem::PartialOrd)
+ (Name::new_symbol_root(sym::le.clone()), LangItem::PartialOrd)
}
CmpOp::Ord { ordering: Ordering::Less, strict: true } => {
- (Name::new_symbol_root(sym::lt), LangItem::PartialOrd)
+ (Name::new_symbol_root(sym::lt.clone()), LangItem::PartialOrd)
}
CmpOp::Ord { ordering: Ordering::Greater, strict: false } => {
- (Name::new_symbol_root(sym::ge), LangItem::PartialOrd)
+ (Name::new_symbol_root(sym::ge.clone()), LangItem::PartialOrd)
}
CmpOp::Ord { ordering: Ordering::Greater, strict: true } => {
- (Name::new_symbol_root(sym::gt), LangItem::PartialOrd)
+ (Name::new_symbol_root(sym::gt.clone()), LangItem::PartialOrd)
}
},
BinaryOp::Assignment { op: None } => return None,
diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs
index 60447ac582..aabf11f268 100644
--- a/crates/hir-ty/src/lib.rs
+++ b/crates/hir-ty/src/lib.rs
@@ -897,7 +897,7 @@ pub fn callable_sig_from_fn_trait(
let fn_once_trait = FnTrait::FnOnce.get_id(db, krate)?;
let output_assoc_type = db
.trait_data(fn_once_trait)
- .associated_type_by_name(&Name::new_symbol_root(sym::Output))?;
+ .associated_type_by_name(&Name::new_symbol_root(sym::Output.clone()))?;
let mut table = InferenceTable::new(db, trait_env.clone());
let b = TyBuilder::trait_ref(db, fn_once_trait);
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 982080c5ff..32b7d6dc11 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -631,18 +631,20 @@ impl Evaluator<'_> {
cached_fn_trait_func: db
.lang_item(crate_id, LangItem::Fn)
.and_then(|x| x.as_trait())
- .and_then(|x| db.trait_data(x).method_by_name(&Name::new_symbol_root(sym::call))),
+ .and_then(|x| {
+ db.trait_data(x).method_by_name(&Name::new_symbol_root(sym::call.clone()))
+ }),
cached_fn_mut_trait_func: db
.lang_item(crate_id, LangItem::FnMut)
.and_then(|x| x.as_trait())
.and_then(|x| {
- db.trait_data(x).method_by_name(&Name::new_symbol_root(sym::call_mut))
+ db.trait_data(x).method_by_name(&Name::new_symbol_root(sym::call_mut.clone()))
}),
cached_fn_once_trait_func: db
.lang_item(crate_id, LangItem::FnOnce)
.and_then(|x| x.as_trait())
.and_then(|x| {
- db.trait_data(x).method_by_name(&Name::new_symbol_root(sym::call_once))
+ db.trait_data(x).method_by_name(&Name::new_symbol_root(sym::call_once.clone()))
}),
})
}
@@ -2694,7 +2696,7 @@ impl Evaluator<'_> {
) -> Result<()> {
let Some(drop_fn) = (|| {
let drop_trait = self.db.lang_item(self.crate_id, LangItem::Drop)?.as_trait()?;
- self.db.trait_data(drop_trait).method_by_name(&Name::new_symbol_root(sym::drop))
+ self.db.trait_data(drop_trait).method_by_name(&Name::new_symbol_root(sym::drop.clone()))
})() else {
// in some tests we don't have drop trait in minicore, and
// we can ignore drop in them.
@@ -2803,7 +2805,7 @@ pub fn render_const_using_debug_impl(
not_supported!("core::fmt::Debug not found");
};
let Some(debug_fmt_fn) =
- db.trait_data(debug_trait).method_by_name(&Name::new_symbol_root(sym::fmt))
+ db.trait_data(debug_trait).method_by_name(&Name::new_symbol_root(sym::fmt.clone()))
else {
not_supported!("core::fmt::Debug::fmt not found");
};
diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs
index 67e102b1ed..6818759310 100644
--- a/crates/hir-ty/src/mir/eval/shim.rs
+++ b/crates/hir-ty/src/mir/eval/shim.rs
@@ -319,7 +319,7 @@ impl Evaluator<'_> {
return Some(LangItem::BeginPanic);
}
- let candidate = attrs.by_key("lang").string_value().and_then(LangItem::from_str)?;
+ let candidate = attrs.lang_item()?;
// We want to execute these functions with special logic
// `PanicFmt` is not detected here as it's redirected later.
if [BeginPanic, SliceLen, DropInPlace].contains(&candidate) {
@@ -1279,7 +1279,7 @@ impl Evaluator<'_> {
if let Some(def) = target.as_trait().and_then(|it| {
self.db
.trait_data(it)
- .method_by_name(&Name::new_symbol_root(sym::call_once))
+ .method_by_name(&Name::new_symbol_root(sym::call_once.clone()))
}) {
self.exec_fn_trait(
def,
diff --git a/crates/hir-ty/src/mir/lower/as_place.rs b/crates/hir-ty/src/mir/lower/as_place.rs
index 5e8a2dfb73..424ee1160c 100644
--- a/crates/hir-ty/src/mir/lower/as_place.rs
+++ b/crates/hir-ty/src/mir/lower/as_place.rs
@@ -189,10 +189,10 @@ impl MirLowerCtx<'_> {
if let Some(deref_trait) =
self.resolve_lang_item(LangItem::DerefMut)?.as_trait()
{
- if let Some(deref_fn) = self
- .db
- .trait_data(deref_trait)
- .method_by_name(&Name::new_symbol_root(sym::deref_mut))
+ if let Some(deref_fn) =
+ self.db.trait_data(deref_trait).method_by_name(
+ &Name::new_symbol_root(sym::deref_mut.clone()),
+ )
{
break 'b deref_fn == f;
}
@@ -327,14 +327,14 @@ impl MirLowerCtx<'_> {
(
Mutability::Not,
LangItem::Deref,
- Name::new_symbol_root(sym::deref),
+ Name::new_symbol_root(sym::deref.clone()),
BorrowKind::Shared,
)
} else {
(
Mutability::Mut,
LangItem::DerefMut,
- Name::new_symbol_root(sym::deref_mut),
+ Name::new_symbol_root(sym::deref_mut.clone()),
BorrowKind::Mut { kind: MutBorrowKind::Default },
)
};
diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs
index ce9ffa284c..c46382a0ea 100644
--- a/crates/hir-ty/src/traits.rs
+++ b/crates/hir-ty/src/traits.rs
@@ -257,9 +257,9 @@ impl FnTrait {
pub fn method_name(self) -> Name {
match self {
- FnTrait::FnOnce => Name::new_symbol_root(sym::call_once),
- FnTrait::FnMut => Name::new_symbol_root(sym::call_mut),
- FnTrait::Fn => Name::new_symbol_root(sym::call),
+ FnTrait::FnOnce => Name::new_symbol_root(sym::call_once.clone()),
+ FnTrait::FnMut => Name::new_symbol_root(sym::call_mut.clone()),
+ FnTrait::Fn => Name::new_symbol_root(sym::call.clone()),
}
}
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index f90656c75f..c868357ff9 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1827,7 +1827,7 @@ impl DefWithBody {
continue;
}
let mut need_mut = &mol[local];
- if body[binding_id].name == sym::self_
+ if body[binding_id].name == sym::self_.clone()
&& need_mut == &mir::MutabilityReason::Unused
{
need_mut = &mir::MutabilityReason::Not;
@@ -2589,7 +2589,7 @@ pub struct StaticLifetime;
impl StaticLifetime {
pub fn name(self) -> Name {
- Name::new_symbol_root(sym::tick_static)
+ Name::new_symbol_root(sym::tick_static.clone())
}
}
@@ -3249,7 +3249,7 @@ impl Local {
}
pub fn is_self(self, db: &dyn HirDatabase) -> bool {
- self.name(db) == sym::self_
+ self.name(db) == sym::self_.clone()
}
pub fn is_mut(self, db: &dyn HirDatabase) -> bool {
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 45401702e9..be0116862b 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -366,7 +366,7 @@ impl SourceAnalyzer {
let items = into_future_trait.items(db);
let into_future_type = items.into_iter().find_map(|item| match item {
AssocItem::TypeAlias(alias)
- if alias.name(db) == Name::new_symbol_root(sym::IntoFuture) =>
+ if alias.name(db) == Name::new_symbol_root(sym::IntoFuture.clone()) =>
{
Some(alias)
}
@@ -395,8 +395,11 @@ impl SourceAnalyzer {
// This can be either `Deref::deref` or `DerefMut::deref_mut`.
// Since deref kind is inferenced and stored in `InferenceResult.method_resolution`,
// use that result to find out which one it is.
- let (deref_trait, deref) =
- self.lang_trait_fn(db, LangItem::Deref, &Name::new_symbol_root(sym::deref))?;
+ let (deref_trait, deref) = self.lang_trait_fn(
+ db,
+ LangItem::Deref,
+ &Name::new_symbol_root(sym::deref.clone()),
+ )?;
self.infer
.as_ref()
.and_then(|infer| {
@@ -405,7 +408,7 @@ impl SourceAnalyzer {
let (deref_mut_trait, deref_mut) = self.lang_trait_fn(
db,
LangItem::DerefMut,
- &Name::new_symbol_root(sym::deref_mut),
+ &Name::new_symbol_root(sym::deref_mut.clone()),
)?;
if func == deref_mut {
Some((deref_mut_trait, deref_mut))
@@ -416,10 +419,10 @@ impl SourceAnalyzer {
.unwrap_or((deref_trait, deref))
}
ast::UnaryOp::Not => {
- self.lang_trait_fn(db, LangItem::Not, &Name::new_symbol_root(sym::not))?
+ self.lang_trait_fn(db, LangItem::Not, &Name::new_symbol_root(sym::not.clone()))?
}
ast::UnaryOp::Neg => {
- self.lang_trait_fn(db, LangItem::Neg, &Name::new_symbol_root(sym::neg))?
+ self.lang_trait_fn(db, LangItem::Neg, &Name::new_symbol_root(sym::neg.clone()))?
}
};
@@ -441,7 +444,7 @@ impl SourceAnalyzer {
let index_ty = self.ty_of_expr(db, &index_expr.index()?)?;
let (index_trait, index_fn) =
- self.lang_trait_fn(db, LangItem::Index, &Name::new_symbol_root(sym::index))?;
+ self.lang_trait_fn(db, LangItem::Index, &Name::new_symbol_root(sym::index.clone()))?;
let (op_trait, op_fn) = self
.infer
.as_ref()
@@ -451,7 +454,7 @@ impl SourceAnalyzer {
let (index_mut_trait, index_mut_fn) = self.lang_trait_fn(
db,
LangItem::IndexMut,
- &Name::new_symbol_root(sym::index_mut),
+ &Name::new_symbol_root(sym::index_mut.clone()),
)?;
if func == index_mut_fn {
Some((index_mut_trait, index_mut_fn))
diff --git a/crates/ide-assists/src/handlers/convert_bool_then.rs b/crates/ide-assists/src/handlers/convert_bool_then.rs
index 27e39f6f8a..77f9c66b35 100644
--- a/crates/ide-assists/src/handlers/convert_bool_then.rs
+++ b/crates/ide-assists/src/handlers/convert_bool_then.rs
@@ -223,7 +223,7 @@ fn option_variants(
let fam = FamousDefs(sema, sema.scope(expr)?.krate());
let option_variants = fam.core_option_Option()?.variants(sema.db);
match &*option_variants {
- &[variant0, variant1] => Some(if variant0.name(sema.db) == sym::None {
+ &[variant0, variant1] => Some(if variant0.name(sema.db) == sym::None.clone() {
(variant0, variant1)
} else {
(variant1, variant0)
diff --git a/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs b/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs
index d85147e84b..e86ff0dbeb 100644
--- a/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs
+++ b/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs
@@ -150,9 +150,9 @@ fn is_ref_and_impls_iter_method(
_ => return None,
};
let wanted_method = Name::new_symbol_root(if ref_expr.mut_token().is_some() {
- sym::iter_mut
+ sym::iter_mut.clone()
} else {
- sym::iter
+ sym::iter.clone()
});
let expr_behind_ref = ref_expr.expr()?;
let ty = sema.type_of_expr(&expr_behind_ref)?.adjusted();
diff --git a/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs b/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs
index 05210e66ac..ad422b25c3 100644
--- a/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs
+++ b/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs
@@ -54,13 +54,13 @@ pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext<
}
let impl_ = fn_node.syntax().ancestors().find_map(ast::Impl::cast)?;
- let len_fn = get_impl_method(ctx, &impl_, &Name::new_symbol_root(sym::len))?;
+ let len_fn = get_impl_method(ctx, &impl_, &Name::new_symbol_root(sym::len.clone()))?;
if !len_fn.ret_type(ctx.sema.db).is_usize() {
cov_mark::hit!(len_fn_different_return_type);
return None;
}
- if get_impl_method(ctx, &impl_, &Name::new_symbol_root(sym::is_empty)).is_some() {
+ if get_impl_method(ctx, &impl_, &Name::new_symbol_root(sym::is_empty.clone())).is_some() {
cov_mark::hit!(is_empty_already_implemented);
return None;
}
diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs
index 137b8d1317..d0382499b9 100644
--- a/crates/ide-assists/src/handlers/inline_call.rs
+++ b/crates/ide-assists/src/handlers/inline_call.rs
@@ -430,7 +430,7 @@ fn inline(
let ty = sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);
- let is_self = param.name(sema.db).is_some_and(|name| name == sym::self_);
+ let is_self = param.name(sema.db).is_some_and(|name| name == sym::self_.clone());
if is_self {
let mut this_pat = make::ident_pat(false, false, make::name("this"));
diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs
index 4a8ea17180..ee27d8611e 100644
--- a/crates/ide-completion/src/completions.rs
+++ b/crates/ide-completion/src/completions.rs
@@ -618,7 +618,8 @@ fn enum_variants_with_paths(
let mut process_variant = |variant: Variant| {
let self_path = hir::ModPath::from_segments(
hir::PathKind::Plain,
- iter::once(Name::new_symbol_root(sym::Self_)).chain(iter::once(variant.name(ctx.db))),
+ iter::once(Name::new_symbol_root(sym::Self_.clone()))
+ .chain(iter::once(variant.name(ctx.db))),
);
cb(acc, ctx, variant, self_path);
diff --git a/crates/ide-completion/src/completions/dot.rs b/crates/ide-completion/src/completions/dot.rs
index d3290db4ef..a07daf4c4e 100644
--- a/crates/ide-completion/src/completions/dot.rs
+++ b/crates/ide-completion/src/completions/dot.rs
@@ -91,13 +91,13 @@ pub(crate) fn complete_undotted_self(
in_breakable: expr_ctx.in_breakable,
},
},
- Some(Name::new_symbol_root(sym::self_)),
+ Some(Name::new_symbol_root(sym::self_.clone())),
field,
&ty,
)
},
|acc, field, ty| {
- acc.add_tuple_field(ctx, Some(Name::new_symbol_root(sym::self_)), field, &ty)
+ acc.add_tuple_field(ctx, Some(Name::new_symbol_root(sym::self_.clone())), field, &ty)
},
true,
false,
@@ -115,7 +115,7 @@ pub(crate) fn complete_undotted_self(
},
},
func,
- Some(Name::new_symbol_root(sym::self_)),
+ Some(Name::new_symbol_root(sym::self_.clone())),
None,
)
});
diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs
index 72b36922da..71ff6b5aea 100644
--- a/crates/ide-completion/src/completions/expr.rs
+++ b/crates/ide-completion/src/completions/expr.rs
@@ -190,7 +190,7 @@ pub(crate) fn complete_expr_path(
path_ctx,
strukt,
None,
- Some(Name::new_symbol_root(sym::Self_)),
+ Some(Name::new_symbol_root(sym::Self_.clone())),
);
}
}
@@ -214,7 +214,7 @@ pub(crate) fn complete_expr_path(
ctx,
un,
None,
- Some(Name::new_symbol_root(sym::Self_)),
+ Some(Name::new_symbol_root(sym::Self_.clone())),
);
}
}
diff --git a/crates/ide-completion/src/completions/lifetime.rs b/crates/ide-completion/src/completions/lifetime.rs
index 541ccf2d19..f31352f49f 100644
--- a/crates/ide-completion/src/completions/lifetime.rs
+++ b/crates/ide-completion/src/completions/lifetime.rs
@@ -47,7 +47,7 @@ pub(crate) fn complete_lifetime(
}
});
if param_lifetime.is_none() {
- acc.add_lifetime(ctx, Name::new_symbol_root(sym::tick_static));
+ acc.add_lifetime(ctx, Name::new_symbol_root(sym::tick_static.clone()));
}
}
diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs
index 4cdb279a21..a41bf457a9 100644
--- a/crates/ide-diagnostics/src/handlers/missing_fields.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs
@@ -210,7 +210,7 @@ fn get_default_constructor(
let has_new_func = ty
.iterate_assoc_items(ctx.sema.db, krate, |assoc_item| {
if let AssocItem::Function(func) = assoc_item {
- if func.name(ctx.sema.db) == sym::new
+ if func.name(ctx.sema.db) == sym::new.clone()
&& func.assoc_fn_params(ctx.sema.db).is_empty()
{
return Some(());
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 0692f0d700..ce1a56e450 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -633,7 +633,7 @@ fn hint_iterator(
if ty.impls_trait(db, iter_trait, &[]) {
let assoc_type_item = iter_trait.items(db).into_iter().find_map(|item| match item {
- hir::AssocItem::TypeAlias(alias) if alias.name(db) == sym::Item => Some(alias),
+ hir::AssocItem::TypeAlias(alias) if alias.name(db) == sym::Item.clone() => Some(alias),
_ => None,
})?;
if let Some(ty) = ty.normalize_trait_assoc_type(db, &[], assoc_type_item) {
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index c73b6acb0d..291073f877 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -6,6 +6,7 @@ use ide_db::{
defs::{Definition, IdentClass, NameClass, NameRefClass},
FxHashMap, RootDatabase, SymbolKind,
};
+use stdx::hash_once;
use syntax::{
ast, match_ast, AstNode, AstToken, NodeOrToken,
SyntaxKind::{self, *},
@@ -358,17 +359,7 @@ fn highlight_name(
}
fn calc_binding_hash(name: &hir::Name, shadow_count: u32) -> u64 {
- fn hash<T: std::hash::Hash + std::fmt::Debug>(x: T) -> u64 {
- use ide_db::FxHasher;
-
- use std::hash::Hasher;
-
- let mut hasher = FxHasher::default();
- x.hash(&mut hasher);
- hasher.finish()
- }
-
- hash((name, shadow_count))
+ hash_once::<ide_db::FxHasher>((name.as_str(), shadow_count))
}
pub(super) fn highlight_def(
diff --git a/crates/intern/src/symbol.rs b/crates/intern/src/symbol.rs
index 9f7a788d00..9e27571387 100644
--- a/crates/intern/src/symbol.rs
+++ b/crates/intern/src/symbol.rs
@@ -91,7 +91,7 @@ impl TaggedArcPtr {
}
#[inline]
- const fn pack_arc(ptr: NonNull<*const str>) -> NonNull<*const str> {
+ fn pack_arc(ptr: NonNull<*const str>) -> NonNull<*const str> {
let packed_tag = true as usize;
// can't use this strict provenance stuff here due to trait methods not being const
@@ -112,7 +112,7 @@ impl TaggedArcPtr {
// }
// so what follows is roughly what the above looks like but inlined
- let self_addr = unsafe { core::mem::transmute::<*const _, usize>(ptr.as_ptr()) };
+ let self_addr = ptr.as_ptr() as *const *const str as usize;
let addr = self_addr | packed_tag;
let dest_addr = addr as isize;
let offset = dest_addr.wrapping_sub(self_addr as isize);
@@ -222,7 +222,7 @@ impl Symbol {
.try_as_arc_owned()
.unwrap(),
);
- debug_assert_eq!(Arc::count(&arc), 1);
+ debug_assert_eq!(Arc::count(arc), 1);
// Shrink the backing storage if the shard is less than 50% occupied.
if shard.len() * 2 < shard.capacity() {
diff --git a/crates/intern/src/symbol/symbols.rs b/crates/intern/src/symbol/symbols.rs
index af1af0536c..6304155ed7 100644
--- a/crates/intern/src/symbol/symbols.rs
+++ b/crates/intern/src/symbol/symbols.rs
@@ -14,10 +14,10 @@ use crate::{
macro_rules! define_symbols {
(@WITH_NAME: $($alias:ident = $value:literal),* $(,)? @PLAIN: $($name:ident),* $(,)?) => {
$(
- pub const $name: Symbol = Symbol { repr: TaggedArcPtr::non_arc(&stringify!($name)) };
+ pub static $name: Symbol = Symbol { repr: TaggedArcPtr::non_arc(&stringify!($name)) };
)*
$(
- pub const $alias: Symbol = Symbol { repr: TaggedArcPtr::non_arc(&$value) };
+ pub static $alias: Symbol = Symbol { repr: TaggedArcPtr::non_arc(&$value) };
)*
@@ -78,10 +78,13 @@ define_symbols! {
@PLAIN:
add_assign,
add,
+ align_offset,
+ alloc_layout,
alloc,
as_str,
asm,
assert,
+ begin_panic,
bench,
bitand_assign,
bitand,
@@ -89,88 +92,13 @@ define_symbols! {
bitor,
bitxor_assign,
bitxor,
- transmute_opts,
- transmute_trait,
- coerce_unsized,
- dispatch_from_dyn,destruct,
bool,
- panic,
- begin_panic,
- panic_nounwind,
- panic_fmt,
- panic_misaligned_pointer_dereference,
- panic_display,
- const_panic_fmt,
- panic_bounds_check,
- panic_info,
- panic_location,
- panic_impl,
- panic_cannot_unwind,
- sized,
- unsize,
- format_alignment,
- start,
- format_argument,
- format_arguments,
- format_count,
- format_placeholder,
- format_unsafe_arg,
- exchange_malloc,
box_free,
- drop_in_place,
- alloc_layout,
- eh_personality,
- eh_catch_typeinfo,
- phantom_data,
- manually_drop,
- maybe_uninit,
- align_offset,
- termination,
- tuple_trait,
- slice_len_fn,
- from_residual,
- from_output,
- from_yeet,
- pointer_like,
- const_param_ty,
- Poll,
- Ready,
- Pending,
- ResumeTy,
- get_context,
- Context,
- Some,
- Err,
- Continue,
- Break,
- into_iter,
- new_unchecked,
- range_inclusive_new,
- CStr,
- fn_ptr_trait,
- freeze,
- coroutine_state,
- c_void,
- coroutine,
- unpin,
- pin,
- fn_ptr_addr,
- structural_teq,
- fn_once_output,
- copy,
- clone,
- sync,
- discriminant_kind,
Box,
- structural_peq,
boxed,
branch,
- discriminant_type,
- pointee_trait,
- metadata_type,
- dyn_metadata,
- deref_target,
- receiver,
+ Break,
+ c_void,
call_mut,
call_once,
call,
@@ -180,31 +108,51 @@ define_symbols! {
cfg_eval,
cfg,
char,
+ clone,
Clone,
+ coerce_unsized,
column,
compile_error,
concat_bytes,
concat_idents,
concat,
const_format_args,
+ const_panic_fmt,
+ const_param_ty,
+ Context,
+ Continue,
+ copy,
Copy,
core_panic,
core,
+ coroutine_state,
+ coroutine,
crate_type,
+ CStr,
Debug,
default,
Default,
deref_mut,
+ deref_target,
deref,
derive_const,
derive,
+ discriminant_kind,
+ discriminant_type,
+ dispatch_from_dyn,destruct,
div_assign,
div,
doc,
+ drop_in_place,
drop,
+ dyn_metadata,
+ eh_catch_typeinfo,
+ eh_personality,
env,
eq,
Eq,
+ Err,
+ exchange_malloc,
f128,
f16,
f32,
@@ -214,15 +162,29 @@ define_symbols! {
filter_map,
fmt,
fn_mut,
+ fn_once_output,
fn_once,
+ fn_ptr_addr,
+ fn_ptr_trait,
+ format_alignment,
format_args_nl,
format_args,
+ format_argument,
+ format_arguments,
+ format_count,
+ format_placeholder,
+ format_unsafe_arg,
format,
+ freeze,
+ from_output,
+ from_residual,
from_usize,
+ from_yeet,
future_trait,
future,
Future,
ge,
+ get_context,
global_allocator,
global_asm,
gt,
@@ -240,6 +202,7 @@ define_symbols! {
index,
Index,
into_future,
+ into_iter,
IntoFuture,
IntoIter,
IntoIterator,
@@ -258,6 +221,9 @@ define_symbols! {
log_syntax,
lt,
macro_rules,
+ manually_drop,
+ maybe_uninit,
+ metadata_type,
module_path,
mul_assign,
mul,
@@ -271,6 +237,7 @@ define_symbols! {
new_lower_hex,
new_octal,
new_pointer,
+ new_unchecked,
new_upper_exp,
new_upper_hex,
new_v1_formatted,
@@ -293,21 +260,39 @@ define_symbols! {
owned_box,
panic_2015,
panic_2021,
+ panic_bounds_check,
+ panic_cannot_unwind,
+ panic_display,
+ panic_fmt,
+ panic_impl,
+ panic_info,
+ panic_location,
+ panic_misaligned_pointer_dereference,
+ panic_nounwind,
+ panic,
Param,
partial_ord,
PartialEq,
PartialOrd,
+ Pending,
+ phantom_data,
pieces,
+ pin,
+ pointee_trait,
+ pointer_like,
poll,
+ Poll,
prelude,
quote,
- r#fn,
+ range_inclusive_new,
Range,
RangeFrom,
RangeFull,
RangeInclusive,
RangeTo,
RangeToInclusive,
+ Ready,
+ receiver,
recursion_limit,
register_attr,
register_tool,
@@ -315,6 +300,7 @@ define_symbols! {
rem,
result,
Result,
+ ResumeTy,
Right,
rust_2015,
rust_2018,
@@ -327,30 +313,43 @@ define_symbols! {
shl,
shr_assign,
shr,
+ sized,
+ slice_len_fn,
+ Some,
+ start,
std_panic,
std,
str,
string,
String,
stringify,
+ structural_peq,
+ structural_teq,
sub_assign,
sub,
+ sync,
Target,
+ termination,
test_case,
test,
trace_macros,
+ transmute_opts,
+ transmute_trait,
transparent,
Try,
+ tuple_trait,
u128,
u16,
u32,
u64,
u8,
Unknown,
+ unpin,
unreachable_2015,
unreachable_2021,
unreachable,
unsafe_cell,
+ unsize,
usize,
v1,
va_list