Skip to content

Commit 3b2bb61

Browse files
Remove unnecessary predefined symbol clones
Now that they're const it's no longer needed. Nothing manual was performed: only a regexp search of `sym::([\w][\w\d]*)\.clone\(\)` and replace by `sym::$1`.
1 parent b290843 commit 3b2bb61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+318
-367
lines changed

src/tools/rust-analyzer/crates/cfg/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct CfgOptions {
3131

3232
impl Default for CfgOptions {
3333
fn default() -> Self {
34-
Self { enabled: FxHashSet::from_iter([CfgAtom::Flag(sym::true_.clone())]) }
34+
Self { enabled: FxHashSet::from_iter([CfgAtom::Flag(sym::true_)]) }
3535
}
3636
}
3737

src/tools/rust-analyzer/crates/hir-def/src/attr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ impl Attrs {
217217
.segments()
218218
.iter()
219219
.rev()
220-
.zip(
221-
[sym::core.clone(), sym::prelude.clone(), sym::v1.clone(), sym::test.clone()]
222-
.iter()
223-
.rev(),
224-
)
220+
.zip([sym::core, sym::prelude, sym::v1, sym::test].iter().rev())
225221
.all(|it| it.0 == it.1)
226222
})
227223
}

src/tools/rust-analyzer/crates/hir-def/src/builtin_type.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,28 @@ impl BuiltinType {
5151
#[rustfmt::skip]
5252
pub fn all_builtin_types() -> [(Name, BuiltinType); 19] {
5353
[
54-
(Name::new_symbol_root(sym::char.clone()), BuiltinType::Char),
55-
(Name::new_symbol_root(sym::bool.clone()), BuiltinType::Bool),
56-
(Name::new_symbol_root(sym::str.clone()), BuiltinType::Str),
57-
58-
(Name::new_symbol_root(sym::isize.clone()), BuiltinType::Int(BuiltinInt::Isize)),
59-
(Name::new_symbol_root(sym::i8.clone()), BuiltinType::Int(BuiltinInt::I8)),
60-
(Name::new_symbol_root(sym::i16.clone()), BuiltinType::Int(BuiltinInt::I16)),
61-
(Name::new_symbol_root(sym::i32.clone()), BuiltinType::Int(BuiltinInt::I32)),
62-
(Name::new_symbol_root(sym::i64.clone()), BuiltinType::Int(BuiltinInt::I64)),
63-
(Name::new_symbol_root(sym::i128.clone()), BuiltinType::Int(BuiltinInt::I128)),
64-
65-
(Name::new_symbol_root(sym::usize.clone()), BuiltinType::Uint(BuiltinUint::Usize)),
66-
(Name::new_symbol_root(sym::u8.clone()), BuiltinType::Uint(BuiltinUint::U8)),
67-
(Name::new_symbol_root(sym::u16.clone()), BuiltinType::Uint(BuiltinUint::U16)),
68-
(Name::new_symbol_root(sym::u32.clone()), BuiltinType::Uint(BuiltinUint::U32)),
69-
(Name::new_symbol_root(sym::u64.clone()), BuiltinType::Uint(BuiltinUint::U64)),
70-
(Name::new_symbol_root(sym::u128.clone()), BuiltinType::Uint(BuiltinUint::U128)),
71-
72-
(Name::new_symbol_root(sym::f16.clone()), BuiltinType::Float(BuiltinFloat::F16)),
73-
(Name::new_symbol_root(sym::f32.clone()), BuiltinType::Float(BuiltinFloat::F32)),
74-
(Name::new_symbol_root(sym::f64.clone()), BuiltinType::Float(BuiltinFloat::F64)),
75-
(Name::new_symbol_root(sym::f128.clone()), BuiltinType::Float(BuiltinFloat::F128)),
54+
(Name::new_symbol_root(sym::char), BuiltinType::Char),
55+
(Name::new_symbol_root(sym::bool), BuiltinType::Bool),
56+
(Name::new_symbol_root(sym::str), BuiltinType::Str),
57+
58+
(Name::new_symbol_root(sym::isize), BuiltinType::Int(BuiltinInt::Isize)),
59+
(Name::new_symbol_root(sym::i8), BuiltinType::Int(BuiltinInt::I8)),
60+
(Name::new_symbol_root(sym::i16), BuiltinType::Int(BuiltinInt::I16)),
61+
(Name::new_symbol_root(sym::i32), BuiltinType::Int(BuiltinInt::I32)),
62+
(Name::new_symbol_root(sym::i64), BuiltinType::Int(BuiltinInt::I64)),
63+
(Name::new_symbol_root(sym::i128), BuiltinType::Int(BuiltinInt::I128)),
64+
65+
(Name::new_symbol_root(sym::usize), BuiltinType::Uint(BuiltinUint::Usize)),
66+
(Name::new_symbol_root(sym::u8), BuiltinType::Uint(BuiltinUint::U8)),
67+
(Name::new_symbol_root(sym::u16), BuiltinType::Uint(BuiltinUint::U16)),
68+
(Name::new_symbol_root(sym::u32), BuiltinType::Uint(BuiltinUint::U32)),
69+
(Name::new_symbol_root(sym::u64), BuiltinType::Uint(BuiltinUint::U64)),
70+
(Name::new_symbol_root(sym::u128), BuiltinType::Uint(BuiltinUint::U128)),
71+
72+
(Name::new_symbol_root(sym::f16), BuiltinType::Float(BuiltinFloat::F16)),
73+
(Name::new_symbol_root(sym::f32), BuiltinType::Float(BuiltinFloat::F32)),
74+
(Name::new_symbol_root(sym::f64), BuiltinType::Float(BuiltinFloat::F64)),
75+
(Name::new_symbol_root(sym::f128), BuiltinType::Float(BuiltinFloat::F128)),
7676
]
7777
}
7878

@@ -86,30 +86,30 @@ impl BuiltinType {
8686
impl AsName for BuiltinType {
8787
fn as_name(&self) -> Name {
8888
match self {
89-
BuiltinType::Char => Name::new_symbol_root(sym::char.clone()),
90-
BuiltinType::Bool => Name::new_symbol_root(sym::bool.clone()),
91-
BuiltinType::Str => Name::new_symbol_root(sym::str.clone()),
89+
BuiltinType::Char => Name::new_symbol_root(sym::char),
90+
BuiltinType::Bool => Name::new_symbol_root(sym::bool),
91+
BuiltinType::Str => Name::new_symbol_root(sym::str),
9292
BuiltinType::Int(it) => match it {
93-
BuiltinInt::Isize => Name::new_symbol_root(sym::isize.clone()),
94-
BuiltinInt::I8 => Name::new_symbol_root(sym::i8.clone()),
95-
BuiltinInt::I16 => Name::new_symbol_root(sym::i16.clone()),
96-
BuiltinInt::I32 => Name::new_symbol_root(sym::i32.clone()),
97-
BuiltinInt::I64 => Name::new_symbol_root(sym::i64.clone()),
98-
BuiltinInt::I128 => Name::new_symbol_root(sym::i128.clone()),
93+
BuiltinInt::Isize => Name::new_symbol_root(sym::isize),
94+
BuiltinInt::I8 => Name::new_symbol_root(sym::i8),
95+
BuiltinInt::I16 => Name::new_symbol_root(sym::i16),
96+
BuiltinInt::I32 => Name::new_symbol_root(sym::i32),
97+
BuiltinInt::I64 => Name::new_symbol_root(sym::i64),
98+
BuiltinInt::I128 => Name::new_symbol_root(sym::i128),
9999
},
100100
BuiltinType::Uint(it) => match it {
101-
BuiltinUint::Usize => Name::new_symbol_root(sym::usize.clone()),
102-
BuiltinUint::U8 => Name::new_symbol_root(sym::u8.clone()),
103-
BuiltinUint::U16 => Name::new_symbol_root(sym::u16.clone()),
104-
BuiltinUint::U32 => Name::new_symbol_root(sym::u32.clone()),
105-
BuiltinUint::U64 => Name::new_symbol_root(sym::u64.clone()),
106-
BuiltinUint::U128 => Name::new_symbol_root(sym::u128.clone()),
101+
BuiltinUint::Usize => Name::new_symbol_root(sym::usize),
102+
BuiltinUint::U8 => Name::new_symbol_root(sym::u8),
103+
BuiltinUint::U16 => Name::new_symbol_root(sym::u16),
104+
BuiltinUint::U32 => Name::new_symbol_root(sym::u32),
105+
BuiltinUint::U64 => Name::new_symbol_root(sym::u64),
106+
BuiltinUint::U128 => Name::new_symbol_root(sym::u128),
107107
},
108108
BuiltinType::Float(it) => match it {
109-
BuiltinFloat::F16 => Name::new_symbol_root(sym::f16.clone()),
110-
BuiltinFloat::F32 => Name::new_symbol_root(sym::f32.clone()),
111-
BuiltinFloat::F64 => Name::new_symbol_root(sym::f64.clone()),
112-
BuiltinFloat::F128 => Name::new_symbol_root(sym::f128.clone()),
109+
BuiltinFloat::F16 => Name::new_symbol_root(sym::f16),
110+
BuiltinFloat::F32 => Name::new_symbol_root(sym::f32),
111+
BuiltinFloat::F64 => Name::new_symbol_root(sym::f64),
112+
BuiltinFloat::F128 => Name::new_symbol_root(sym::f128),
113113
},
114114
}
115115
}

src/tools/rust-analyzer/crates/hir-def/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: Crate) -> bool {
387387
let attrs = item_tree.raw_attrs(AttrOwner::TopLevel);
388388
for attr in &**attrs {
389389
match attr.path().as_ident() {
390-
Some(ident) if *ident == sym::no_std.clone() => return true,
391-
Some(ident) if *ident == sym::cfg_attr.clone() => {}
390+
Some(ident) if *ident == sym::no_std => return true,
391+
Some(ident) if *ident == sym::cfg_attr => {}
392392
_ => continue,
393393
}
394394

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(super) fn lower_body(
105105
let is_mutable =
106106
self_param_syn.mut_token().is_some() && self_param_syn.amp_token().is_none();
107107
let binding_id: la_arena::Idx<Binding> = collector.alloc_binding(
108-
Name::new_symbol_root(sym::self_.clone()),
108+
Name::new_symbol_root(sym::self_),
109109
BindingAnnotation::new(is_mutable, false),
110110
);
111111
self_param = Some(binding_id);
@@ -137,7 +137,7 @@ pub(super) fn lower_body(
137137
let is_mutable =
138138
self_param_syn.mut_token().is_some() && self_param_syn.amp_token().is_none();
139139
let binding_id: la_arena::Idx<Binding> = collector.alloc_binding(
140-
Name::new_symbol_root(sym::self_.clone()),
140+
Name::new_symbol_root(sym::self_),
141141
BindingAnnotation::new(is_mutable, false),
142142
);
143143
let hygiene = self_param_syn
@@ -322,7 +322,7 @@ pub(crate) fn lower_function(
322322
Some(ty) => collector.lower_type_ref(ty, &mut impl_trait_lower_fn),
323323
None => {
324324
let self_type = collector.alloc_type_ref_desugared(TypeRef::Path(
325-
Name::new_symbol_root(sym::Self_.clone()).into(),
325+
Name::new_symbol_root(sym::Self_).into(),
326326
));
327327
let lifetime = param
328328
.lifetime()
@@ -375,7 +375,7 @@ pub(crate) fn lower_function(
375375
let mut generic_args: Vec<_> =
376376
std::iter::repeat_n(None, path.segments().len() - 1).collect();
377377
let binding = AssociatedTypeBinding {
378-
name: Name::new_symbol_root(sym::Output.clone()),
378+
name: Name::new_symbol_root(sym::Output),
379379
args: None,
380380
type_ref: Some(
381381
return_type
@@ -631,7 +631,7 @@ impl ExprCollector<'_> {
631631
match abi.abi_string() {
632632
Some(tok) => Symbol::intern(tok.text_without_quotes()),
633633
// `extern` default to be `extern "C"`.
634-
_ => sym::C.clone(),
634+
_ => sym::C,
635635
}
636636
}
637637

@@ -760,7 +760,7 @@ impl ExprCollector<'_> {
760760
let bindings = if let Some(ret_type) = ret_type {
761761
let type_ref = self.lower_type_ref_opt(ret_type.ty(), impl_trait_lower_fn);
762762
Box::new([AssociatedTypeBinding {
763-
name: Name::new_symbol_root(sym::Output.clone()),
763+
name: Name::new_symbol_root(sym::Output),
764764
args: None,
765765
type_ref: Some(type_ref),
766766
bounds: Box::default(),
@@ -769,7 +769,7 @@ impl ExprCollector<'_> {
769769
// -> ()
770770
let type_ref = self.alloc_type_ref_desugared(TypeRef::unit());
771771
Box::new([AssociatedTypeBinding {
772-
name: Name::new_symbol_root(sym::Output.clone()),
772+
name: Name::new_symbol_root(sym::Output),
773773
args: None,
774774
type_ref: Some(type_ref),
775775
bounds: Box::default(),
@@ -2804,12 +2804,12 @@ impl ExprCollector<'_> {
28042804
let new_v1_formatted = LangItem::FormatArguments.ty_rel_path(
28052805
self.db,
28062806
self.module.krate(),
2807-
Name::new_symbol_root(sym::new_v1_formatted.clone()),
2807+
Name::new_symbol_root(sym::new_v1_formatted),
28082808
);
28092809
let unsafe_arg_new = LangItem::FormatUnsafeArg.ty_rel_path(
28102810
self.db,
28112811
self.module.krate(),
2812-
Name::new_symbol_root(sym::new.clone()),
2812+
Name::new_symbol_root(sym::new),
28132813
);
28142814
let new_v1_formatted =
28152815
self.alloc_expr_desugared(new_v1_formatted.map_or(Expr::Missing, Expr::Path));
@@ -2924,20 +2924,15 @@ impl ExprCollector<'_> {
29242924
Some(BuiltinUint::U32),
29252925
)));
29262926

2927-
let position = RecordLitField {
2928-
name: Name::new_symbol_root(sym::position.clone()),
2929-
expr: position,
2930-
};
2931-
let flags =
2932-
RecordLitField { name: Name::new_symbol_root(sym::flags.clone()), expr: flags };
2927+
let position =
2928+
RecordLitField { name: Name::new_symbol_root(sym::position), expr: position };
2929+
let flags = RecordLitField { name: Name::new_symbol_root(sym::flags), expr: flags };
29332930
let precision = RecordLitField {
2934-
name: Name::new_symbol_root(sym::precision.clone()),
2931+
name: Name::new_symbol_root(sym::precision),
29352932
expr: precision_expr,
29362933
};
2937-
let width = RecordLitField {
2938-
name: Name::new_symbol_root(sym::width.clone()),
2939-
expr: width_expr,
2940-
};
2934+
let width =
2935+
RecordLitField { name: Name::new_symbol_root(sym::width), expr: width_expr };
29412936
self.alloc_expr_desugared(Expr::RecordLit {
29422937
path: LangItem::FormatPlaceholder.path(self.db, self.module.krate()).map(Box::new),
29432938
fields: Box::new([position, flags, precision, width]),
@@ -2948,7 +2943,7 @@ impl ExprCollector<'_> {
29482943
let format_placeholder_new = LangItem::FormatPlaceholder.ty_rel_path(
29492944
self.db,
29502945
self.module.krate(),
2951-
Name::new_symbol_root(sym::new.clone()),
2946+
Name::new_symbol_root(sym::new),
29522947
);
29532948
match format_placeholder_new {
29542949
Some(path) => self.alloc_expr_desugared(Expr::Path(path)),
@@ -2972,10 +2967,10 @@ impl ExprCollector<'_> {
29722967
self.db,
29732968
self.module.krate(),
29742969
match alignment {
2975-
Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left.clone()),
2976-
Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right.clone()),
2977-
Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center.clone()),
2978-
None => Name::new_symbol_root(sym::Unknown.clone()),
2970+
Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left),
2971+
Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right),
2972+
Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center),
2973+
None => Name::new_symbol_root(sym::Unknown),
29792974
},
29802975
);
29812976
match align {
@@ -3024,7 +3019,7 @@ impl ExprCollector<'_> {
30243019
let count_is = match LangItem::FormatCount.ty_rel_path(
30253020
self.db,
30263021
self.module.krate(),
3027-
Name::new_symbol_root(sym::Is.clone()),
3022+
Name::new_symbol_root(sym::Is),
30283023
) {
30293024
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
30303025
None => self.missing_expr(),
@@ -3042,7 +3037,7 @@ impl ExprCollector<'_> {
30423037
let count_param = match LangItem::FormatCount.ty_rel_path(
30433038
self.db,
30443039
self.module.krate(),
3045-
Name::new_symbol_root(sym::Param.clone()),
3040+
Name::new_symbol_root(sym::Param),
30463041
) {
30473042
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
30483043
None => self.missing_expr(),
@@ -3060,7 +3055,7 @@ impl ExprCollector<'_> {
30603055
None => match LangItem::FormatCount.ty_rel_path(
30613056
self.db,
30623057
self.module.krate(),
3063-
Name::new_symbol_root(sym::Implied.clone()),
3058+
Name::new_symbol_root(sym::Implied),
30643059
) {
30653060
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
30663061
None => self.missing_expr(),
@@ -3083,16 +3078,16 @@ impl ExprCollector<'_> {
30833078
self.db,
30843079
self.module.krate(),
30853080
Name::new_symbol_root(match ty {
3086-
Format(Display) => sym::new_display.clone(),
3087-
Format(Debug) => sym::new_debug.clone(),
3088-
Format(LowerExp) => sym::new_lower_exp.clone(),
3089-
Format(UpperExp) => sym::new_upper_exp.clone(),
3090-
Format(Octal) => sym::new_octal.clone(),
3091-
Format(Pointer) => sym::new_pointer.clone(),
3092-
Format(Binary) => sym::new_binary.clone(),
3093-
Format(LowerHex) => sym::new_lower_hex.clone(),
3094-
Format(UpperHex) => sym::new_upper_hex.clone(),
3095-
Usize => sym::from_usize.clone(),
3081+
Format(Display) => sym::new_display,
3082+
Format(Debug) => sym::new_debug,
3083+
Format(LowerExp) => sym::new_lower_exp,
3084+
Format(UpperExp) => sym::new_upper_exp,
3085+
Format(Octal) => sym::new_octal,
3086+
Format(Pointer) => sym::new_pointer,
3087+
Format(Binary) => sym::new_binary,
3088+
Format(LowerHex) => sym::new_lower_hex,
3089+
Format(UpperHex) => sym::new_upper_hex,
3090+
Usize => sym::from_usize,
30963091
}),
30973092
) {
30983093
Some(new_fn) => self.alloc_expr_desugared(Expr::Path(new_fn)),

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'db, 'c> GenericParamsCollector<'db, 'c> {
4343
}
4444

4545
pub(crate) fn fill_self_param(&mut self, bounds: Option<ast::TypeBoundList>) {
46-
let self_ = Name::new_symbol_root(sym::Self_.clone());
46+
let self_ = Name::new_symbol_root(sym::Self_);
4747
let idx = self.type_or_consts.alloc(
4848
TypeParamData {
4949
name: Some(self_.clone()),

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(super) fn lower_path(
105105
push_segment(&segment, &mut segments, name);
106106
}
107107
ast::PathSegmentKind::SelfTypeKw => {
108-
push_segment(&segment, &mut segments, Name::new_symbol_root(sym::Self_.clone()));
108+
push_segment(&segment, &mut segments, Name::new_symbol_root(sym::Self_));
109109
}
110110
ast::PathSegmentKind::Type { type_ref, trait_ref } => {
111111
debug_assert!(path.qualifier().is_none()); // this can only occur at the first segment

src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ fn lower_abi(abi: ast::Abi) -> Symbol {
532532
match abi.abi_string() {
533533
Some(tok) => Symbol::intern(tok.text_without_quotes()),
534534
// `extern` default to be `extern "C"`.
535-
_ => sym::C.clone(),
535+
_ => sym::C,
536536
}
537537
}
538538

0 commit comments

Comments
 (0)