Skip to content

Commit 3fe815b

Browse files
committed
Use Symbol in Name
1 parent 843806b commit 3fe815b

Some content is hidden

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

75 files changed

+756
-761
lines changed

crates/hir-def/src/attr.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use hir_expand::{
99
attrs::{collect_attrs, Attr, AttrId, RawAttrs},
1010
HirFileId, InFile,
1111
};
12+
use intern::sym;
1213
use la_arena::{ArenaMap, Idx, RawIdx};
1314
use mbe::DelimiterKind;
1415
use syntax::{
@@ -199,8 +200,8 @@ impl Attrs {
199200
.segments()
200201
.iter()
201202
.rev()
202-
.zip(["core", "prelude", "v1", "test"].iter().rev())
203-
.all(|it| it.0.as_str() == Some(it.1))
203+
.zip([sym::core, sym::prelude, sym::v1, sym::test].iter().rev())
204+
.all(|it| it.0 == it.1)
204205
})
205206
}
206207

@@ -568,6 +569,10 @@ impl<'attr> AttrQuery<'attr> {
568569
self.attrs().find_map(|attr| attr.string_value())
569570
}
570571

572+
pub fn string_value_with_span(self) -> Option<(&'attr str, span::Span)> {
573+
self.attrs().find_map(|attr| attr.string_value_with_span())
574+
}
575+
571576
pub fn string_value_unescape(self) -> Option<Cow<'attr, str>> {
572577
self.attrs().find_map(|attr| attr.string_value_unescape())
573578
}

crates/hir-def/src/body/lower.rs

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::mem;
55

66
use base_db::CrateId;
77
use hir_expand::{
8-
name::{name, AsName, Name},
8+
name::{AsName, Name},
99
ExpandError, InFile,
1010
};
11-
use intern::Interned;
11+
use intern::{sym, Interned};
1212
use rustc_hash::FxHashMap;
1313
use smallvec::SmallVec;
1414
use span::AstIdMap;
@@ -187,8 +187,10 @@ impl ExprCollector<'_> {
187187
{
188188
let is_mutable =
189189
self_param.mut_token().is_some() && self_param.amp_token().is_none();
190-
let binding_id: la_arena::Idx<Binding> =
191-
self.alloc_binding(name![self], BindingAnnotation::new(is_mutable, false));
190+
let binding_id: la_arena::Idx<Binding> = self.alloc_binding(
191+
Name::new_symbol_root(sym::self_),
192+
BindingAnnotation::new(is_mutable, false),
193+
);
192194
self.body.self_param = Some(binding_id);
193195
self.source_map.self_param = Some(self.expander.in_file(AstPtr::new(&self_param)));
194196
}
@@ -1588,18 +1590,22 @@ impl ExprCollector<'_> {
15881590
});
15891591
let mut mappings = vec![];
15901592
let fmt = match template.and_then(|it| self.expand_macros_to_string(it)) {
1591-
Some((s, is_direct_literal)) => format_args::parse(
1592-
&s,
1593-
fmt_snippet,
1594-
args,
1595-
is_direct_literal,
1596-
|name| self.alloc_expr_desugared(Expr::Path(Path::from(name))),
1597-
|name, span| {
1598-
if let Some(span) = span {
1599-
mappings.push((span, name))
1600-
}
1601-
},
1602-
),
1593+
Some((s, is_direct_literal)) => {
1594+
let call_ctx = self.expander.syntax_context();
1595+
format_args::parse(
1596+
&s,
1597+
fmt_snippet,
1598+
args,
1599+
is_direct_literal,
1600+
|name| self.alloc_expr_desugared(Expr::Path(Path::from(name))),
1601+
|name, span| {
1602+
if let Some(span) = span {
1603+
mappings.push((span, name))
1604+
}
1605+
},
1606+
call_ctx,
1607+
)
1608+
}
16031609
None => FormatArgs {
16041610
template: Default::default(),
16051611
arguments: args.finish(),
@@ -1723,14 +1729,18 @@ impl ExprCollector<'_> {
17231729
// unsafe { ::core::fmt::UnsafeArg::new() }
17241730
// )
17251731

1726-
let Some(new_v1_formatted) =
1727-
LangItem::FormatArguments.ty_rel_path(self.db, self.krate, name![new_v1_formatted])
1728-
else {
1732+
let Some(new_v1_formatted) = LangItem::FormatArguments.ty_rel_path(
1733+
self.db,
1734+
self.krate,
1735+
Name::new_symbol_root(sym::new_v1_formatted),
1736+
) else {
17291737
return self.missing_expr();
17301738
};
1731-
let Some(unsafe_arg_new) =
1732-
LangItem::FormatUnsafeArg.ty_rel_path(self.db, self.krate, name![new])
1733-
else {
1739+
let Some(unsafe_arg_new) = LangItem::FormatUnsafeArg.ty_rel_path(
1740+
self.db,
1741+
self.krate,
1742+
Name::new_symbol_root(sym::new),
1743+
) else {
17341744
return self.missing_expr();
17351745
};
17361746
let new_v1_formatted = self.alloc_expr_desugared(Expr::Path(new_v1_formatted));
@@ -1812,10 +1822,10 @@ impl ExprCollector<'_> {
18121822
self.db,
18131823
self.krate,
18141824
match alignment {
1815-
Some(FormatAlignment::Left) => name![Left],
1816-
Some(FormatAlignment::Right) => name![Right],
1817-
Some(FormatAlignment::Center) => name![Center],
1818-
None => name![Unknown],
1825+
Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left),
1826+
Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right),
1827+
Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center),
1828+
None => Name::new_symbol_root(sym::Unknown),
18191829
},
18201830
);
18211831
match align {
@@ -1838,8 +1848,11 @@ impl ExprCollector<'_> {
18381848
let width = self.make_count(width, argmap);
18391849

18401850
let format_placeholder_new = {
1841-
let format_placeholder_new =
1842-
LangItem::FormatPlaceholder.ty_rel_path(self.db, self.krate, name![new]);
1851+
let format_placeholder_new = LangItem::FormatPlaceholder.ty_rel_path(
1852+
self.db,
1853+
self.krate,
1854+
Name::new_symbol_root(sym::new),
1855+
);
18431856
match format_placeholder_new {
18441857
Some(path) => self.alloc_expr_desugared(Expr::Path(path)),
18451858
None => self.missing_expr(),
@@ -1883,11 +1896,14 @@ impl ExprCollector<'_> {
18831896
*n as u128,
18841897
Some(BuiltinUint::Usize),
18851898
)));
1886-
let count_is =
1887-
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Is]) {
1888-
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
1889-
None => self.missing_expr(),
1890-
};
1899+
let count_is = match LangItem::FormatCount.ty_rel_path(
1900+
self.db,
1901+
self.krate,
1902+
Name::new_symbol_root(sym::Is),
1903+
) {
1904+
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
1905+
None => self.missing_expr(),
1906+
};
18911907
self.alloc_expr_desugared(Expr::Call {
18921908
callee: count_is,
18931909
args: Box::new([args]),
@@ -1905,7 +1921,7 @@ impl ExprCollector<'_> {
19051921
let count_param = match LangItem::FormatCount.ty_rel_path(
19061922
self.db,
19071923
self.krate,
1908-
name![Param],
1924+
Name::new_symbol_root(sym::Param),
19091925
) {
19101926
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
19111927
None => self.missing_expr(),
@@ -1921,7 +1937,11 @@ impl ExprCollector<'_> {
19211937
self.missing_expr()
19221938
}
19231939
}
1924-
None => match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Implied]) {
1940+
None => match LangItem::FormatCount.ty_rel_path(
1941+
self.db,
1942+
self.krate,
1943+
Name::new_symbol_root(sym::Implied),
1944+
) {
19251945
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
19261946
None => self.missing_expr(),
19271947
},
@@ -1942,18 +1962,18 @@ impl ExprCollector<'_> {
19421962
let new_fn = match LangItem::FormatArgument.ty_rel_path(
19431963
self.db,
19441964
self.krate,
1945-
match ty {
1946-
Format(Display) => name![new_display],
1947-
Format(Debug) => name![new_debug],
1948-
Format(LowerExp) => name![new_lower_exp],
1949-
Format(UpperExp) => name![new_upper_exp],
1950-
Format(Octal) => name![new_octal],
1951-
Format(Pointer) => name![new_pointer],
1952-
Format(Binary) => name![new_binary],
1953-
Format(LowerHex) => name![new_lower_hex],
1954-
Format(UpperHex) => name![new_upper_hex],
1955-
Usize => name![from_usize],
1956-
},
1965+
Name::new_symbol_root(match ty {
1966+
Format(Display) => sym::new_display,
1967+
Format(Debug) => sym::new_debug,
1968+
Format(LowerExp) => sym::new_lower_exp,
1969+
Format(UpperExp) => sym::new_upper_exp,
1970+
Format(Octal) => sym::new_octal,
1971+
Format(Pointer) => sym::new_pointer,
1972+
Format(Binary) => sym::new_binary,
1973+
Format(LowerHex) => sym::new_lower_hex,
1974+
Format(UpperHex) => sym::new_upper_hex,
1975+
Usize => sym::from_usize,
1976+
}),
19571977
) {
19581978
Some(new_fn) => self.alloc_expr_desugared(Expr::Path(new_fn)),
19591979
None => self.missing_expr(),

crates/hir-def/src/builtin_type.rs

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
66
use std::fmt;
77

8-
use hir_expand::name::{name, AsName, Name};
8+
use hir_expand::name::{AsName, Name};
9+
use intern::sym;
910
/// Different signed int types.
1011
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1112
pub enum BuiltinInt {
@@ -49,28 +50,28 @@ pub enum BuiltinType {
4950
impl BuiltinType {
5051
#[rustfmt::skip]
5152
pub const ALL: &'static [(Name, BuiltinType)] = &[
52-
(name![char], BuiltinType::Char),
53-
(name![bool], BuiltinType::Bool),
54-
(name![str], BuiltinType::Str),
55-
56-
(name![isize], BuiltinType::Int(BuiltinInt::Isize)),
57-
(name![i8], BuiltinType::Int(BuiltinInt::I8)),
58-
(name![i16], BuiltinType::Int(BuiltinInt::I16)),
59-
(name![i32], BuiltinType::Int(BuiltinInt::I32)),
60-
(name![i64], BuiltinType::Int(BuiltinInt::I64)),
61-
(name![i128], BuiltinType::Int(BuiltinInt::I128)),
62-
63-
(name![usize], BuiltinType::Uint(BuiltinUint::Usize)),
64-
(name![u8], BuiltinType::Uint(BuiltinUint::U8)),
65-
(name![u16], BuiltinType::Uint(BuiltinUint::U16)),
66-
(name![u32], BuiltinType::Uint(BuiltinUint::U32)),
67-
(name![u64], BuiltinType::Uint(BuiltinUint::U64)),
68-
(name![u128], BuiltinType::Uint(BuiltinUint::U128)),
69-
70-
(name![f16], BuiltinType::Float(BuiltinFloat::F16)),
71-
(name![f32], BuiltinType::Float(BuiltinFloat::F32)),
72-
(name![f64], BuiltinType::Float(BuiltinFloat::F64)),
73-
(name![f128], BuiltinType::Float(BuiltinFloat::F128)),
53+
(Name::new_symbol_root(sym::char), BuiltinType::Char),
54+
(Name::new_symbol_root(sym::bool), BuiltinType::Bool),
55+
(Name::new_symbol_root(sym::str), BuiltinType::Str),
56+
57+
(Name::new_symbol_root(sym::isize), BuiltinType::Int(BuiltinInt::Isize)),
58+
(Name::new_symbol_root(sym::i8), BuiltinType::Int(BuiltinInt::I8)),
59+
(Name::new_symbol_root(sym::i16), BuiltinType::Int(BuiltinInt::I16)),
60+
(Name::new_symbol_root(sym::i32), BuiltinType::Int(BuiltinInt::I32)),
61+
(Name::new_symbol_root(sym::i64), BuiltinType::Int(BuiltinInt::I64)),
62+
(Name::new_symbol_root(sym::i128), BuiltinType::Int(BuiltinInt::I128)),
63+
64+
(Name::new_symbol_root(sym::usize), BuiltinType::Uint(BuiltinUint::Usize)),
65+
(Name::new_symbol_root(sym::u8), BuiltinType::Uint(BuiltinUint::U8)),
66+
(Name::new_symbol_root(sym::u16), BuiltinType::Uint(BuiltinUint::U16)),
67+
(Name::new_symbol_root(sym::u32), BuiltinType::Uint(BuiltinUint::U32)),
68+
(Name::new_symbol_root(sym::u64), BuiltinType::Uint(BuiltinUint::U64)),
69+
(Name::new_symbol_root(sym::u128), BuiltinType::Uint(BuiltinUint::U128)),
70+
71+
(Name::new_symbol_root(sym::f16), BuiltinType::Float(BuiltinFloat::F16)),
72+
(Name::new_symbol_root(sym::f32), BuiltinType::Float(BuiltinFloat::F32)),
73+
(Name::new_symbol_root(sym::f64), BuiltinType::Float(BuiltinFloat::F64)),
74+
(Name::new_symbol_root(sym::f128), BuiltinType::Float(BuiltinFloat::F128)),
7475
];
7576

7677
pub fn by_name(name: &Name) -> Option<Self> {
@@ -81,30 +82,30 @@ impl BuiltinType {
8182
impl AsName for BuiltinType {
8283
fn as_name(&self) -> Name {
8384
match self {
84-
BuiltinType::Char => name![char],
85-
BuiltinType::Bool => name![bool],
86-
BuiltinType::Str => name![str],
85+
BuiltinType::Char => Name::new_symbol_root(sym::char),
86+
BuiltinType::Bool => Name::new_symbol_root(sym::bool),
87+
BuiltinType::Str => Name::new_symbol_root(sym::str),
8788
BuiltinType::Int(it) => match it {
88-
BuiltinInt::Isize => name![isize],
89-
BuiltinInt::I8 => name![i8],
90-
BuiltinInt::I16 => name![i16],
91-
BuiltinInt::I32 => name![i32],
92-
BuiltinInt::I64 => name![i64],
93-
BuiltinInt::I128 => name![i128],
89+
BuiltinInt::Isize => Name::new_symbol_root(sym::isize),
90+
BuiltinInt::I8 => Name::new_symbol_root(sym::i8),
91+
BuiltinInt::I16 => Name::new_symbol_root(sym::i16),
92+
BuiltinInt::I32 => Name::new_symbol_root(sym::i32),
93+
BuiltinInt::I64 => Name::new_symbol_root(sym::i64),
94+
BuiltinInt::I128 => Name::new_symbol_root(sym::i128),
9495
},
9596
BuiltinType::Uint(it) => match it {
96-
BuiltinUint::Usize => name![usize],
97-
BuiltinUint::U8 => name![u8],
98-
BuiltinUint::U16 => name![u16],
99-
BuiltinUint::U32 => name![u32],
100-
BuiltinUint::U64 => name![u64],
101-
BuiltinUint::U128 => name![u128],
97+
BuiltinUint::Usize => Name::new_symbol_root(sym::usize),
98+
BuiltinUint::U8 => Name::new_symbol_root(sym::u8),
99+
BuiltinUint::U16 => Name::new_symbol_root(sym::u16),
100+
BuiltinUint::U32 => Name::new_symbol_root(sym::u32),
101+
BuiltinUint::U64 => Name::new_symbol_root(sym::u64),
102+
BuiltinUint::U128 => Name::new_symbol_root(sym::u128),
102103
},
103104
BuiltinType::Float(it) => match it {
104-
BuiltinFloat::F16 => name![f16],
105-
BuiltinFloat::F32 => name![f32],
106-
BuiltinFloat::F64 => name![f64],
107-
BuiltinFloat::F128 => name![f128],
105+
BuiltinFloat::F16 => Name::new_symbol_root(sym::f16),
106+
BuiltinFloat::F32 => Name::new_symbol_root(sym::f32),
107+
BuiltinFloat::F64 => Name::new_symbol_root(sym::f64),
108+
BuiltinFloat::F128 => Name::new_symbol_root(sym::f128),
108109
},
109110
}
110111
}

crates/hir-def/src/data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use base_db::CrateId;
66
use hir_expand::{
77
name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefKind,
88
};
9-
use intern::Interned;
9+
use intern::{sym, Interned};
1010
use smallvec::SmallVec;
1111
use syntax::{ast, Parse};
1212
use triomphe::Arc;
@@ -485,7 +485,7 @@ impl ExternCrateDeclData {
485485

486486
let name = extern_crate.name.clone();
487487
let krate = loc.container.krate();
488-
let crate_id = if name == hir_expand::name![self] {
488+
let crate_id = if name == sym::self_ {
489489
Some(krate)
490490
} else {
491491
db.crate_def_map(krate)

crates/hir-def/src/db.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use base_db::{salsa, CrateId, FileId, SourceDatabase, Upcast};
33
use either::Either;
44
use hir_expand::{db::ExpandDatabase, HirFileId, MacroDefId};
5-
use intern::Interned;
5+
use intern::{sym, Interned};
66
use la_arena::ArenaMap;
77
use span::MacroCallId;
88
use syntax::{ast, AstPtr};
@@ -261,9 +261,9 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
261261
let item_tree = db.file_item_tree(file.into());
262262
let attrs = item_tree.raw_attrs(AttrOwner::TopLevel);
263263
for attr in &**attrs {
264-
match attr.path().as_ident().and_then(|id| id.as_text()) {
265-
Some(ident) if ident == "no_std" => return true,
266-
Some(ident) if ident == "cfg_attr" => {}
264+
match attr.path().as_ident() {
265+
Some(ident) if *ident == sym::no_std => return true,
266+
Some(ident) if *ident == sym::cfg_attr => {}
267267
_ => continue,
268268
}
269269

crates/hir-def/src/expander.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use hir_expand::{
1010
InFile, MacroCallId,
1111
};
1212
use limit::Limit;
13+
use span::SyntaxContextId;
1314
use syntax::{ast, Parse};
1415
use triomphe::Arc;
1516

@@ -52,6 +53,11 @@ impl Expander {
5253
self.module.krate
5354
}
5455

56+
pub fn syntax_context(&self) -> SyntaxContextId {
57+
// FIXME:
58+
SyntaxContextId::ROOT
59+
}
60+
5561
pub fn enter_expand<T: ast::AstNode>(
5662
&mut self,
5763
db: &dyn DefDatabase,

0 commit comments

Comments
 (0)