Constify KnownName's

This commit is contained in:
Muhammad Mominul Huque 2019-07-08 03:29:38 +06:00
parent 1b38ca3b87
commit 012fec54dc
No known key found for this signature in database
GPG key ID: 37AF141540DE557D
11 changed files with 75 additions and 157 deletions

10
Cargo.lock generated
View file

@ -1278,7 +1278,7 @@ dependencies = [
"ra_parser 0.1.0", "ra_parser 0.1.0",
"ra_text_edit 0.1.0", "ra_text_edit 0.1.0",
"rowan 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "rowan 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0", "test_utils 0.1.0",
"text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1308,7 +1308,7 @@ dependencies = [
name = "ra_tt" name = "ra_tt"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -1563,7 +1563,7 @@ dependencies = [
"colosseum 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "colosseum 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1722,7 +1722,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "smol_str" name = "smol_str"
version = "0.1.11" version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2280,7 +2280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" "checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
"checksum smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e6507d018aa8dfcaa08aaab587605591cd2109df66a921486a2220e2daf9fa29" "checksum smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "590700be3630457c56f8c73c0ea39881476ad7076cd84057d44f4f38f79914fb"
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
"checksum stacker 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb79482f57cf598af52094ec4cc3b3c42499d3ce5bd426f2ac41515b7e57404b" "checksum stacker 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb79482f57cf598af52094ec4cc3b3c42499d3ce5bd426f2ac41515b7e57404b"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"

View file

@ -19,6 +19,7 @@ use crate::{
TypeAliasId, TypeAliasId,
}, },
impl_block::ImplBlock, impl_block::ImplBlock,
name::{BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, STR, U128, U16, U32, U64, U8, USIZE, SELF_TYPE},
nameres::{CrateModuleId, ImportId, ModuleScope, Namespace}, nameres::{CrateModuleId, ImportId, ModuleScope, Namespace},
resolve::Resolver, resolve::Resolver,
traits::{TraitData, TraitItem}, traits::{TraitData, TraitItem},
@ -28,7 +29,7 @@ use crate::{
}, },
type_ref::Mutability, type_ref::Mutability,
type_ref::TypeRef, type_ref::TypeRef,
AsName, AstDatabase, AstId, DefDatabase, Either, HasSource, HirDatabase, KnownName, Name, Ty, AsName, AstDatabase, AstId, DefDatabase, Either, HasSource, HirDatabase, Name, Ty,
}; };
/// hir::Crate describes a single crate. It's the main interface with which /// hir::Crate describes a single crate. It's the main interface with which
@ -96,27 +97,27 @@ pub enum BuiltinType {
impl BuiltinType { impl BuiltinType {
#[rustfmt::skip] #[rustfmt::skip]
pub(crate) const ALL: &'static [(KnownName, BuiltinType)] = &[ pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[
(KnownName::Char, BuiltinType::Char), (CHAR, BuiltinType::Char),
(KnownName::Bool, BuiltinType::Bool), (BOOL, BuiltinType::Bool),
(KnownName::Str, BuiltinType::Str), (STR, BuiltinType::Str),
(KnownName::Isize, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), (ISIZE, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })),
(KnownName::I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })), (I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })),
(KnownName::I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })), (I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })),
(KnownName::I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })), (I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })),
(KnownName::I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })), (I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })),
(KnownName::I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })), (I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })),
(KnownName::Usize, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), (USIZE, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })),
(KnownName::U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), (U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })),
(KnownName::U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), (U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })),
(KnownName::U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), (U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })),
(KnownName::U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), (U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })),
(KnownName::U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), (U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })),
(KnownName::F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), (F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })),
(KnownName::F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })), (F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })),
]; ];
} }
@ -560,7 +561,7 @@ impl FnData {
let self_type = if let Some(type_ref) = self_param.ascribed_type() { let self_type = if let Some(type_ref) = self_param.ascribed_type() {
TypeRef::from_ast(type_ref) TypeRef::from_ast(type_ref)
} else { } else {
let self_type = TypeRef::Path(Name::self_type().into()); let self_type = TypeRef::Path(SELF_TYPE.into());
match self_param.kind() { match self_param.kind() {
ast::SelfParamKind::Owned => self_type, ast::SelfParamKind::Owned => self_type,
ast::SelfParamKind::Ref => { ast::SelfParamKind::Ref => {

View file

@ -13,7 +13,7 @@ use ra_syntax::{
}; };
use crate::{ use crate::{
name::AsName, name::{AsName, SELF_PARAM},
type_ref::{Mutability, TypeRef}, type_ref::{Mutability, TypeRef},
DefWithBody, Either, HasSource, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Name, DefWithBody, Either, HasSource, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Name,
Path, Resolver, Path, Resolver,
@ -981,7 +981,7 @@ where
let ptr = AstPtr::new(self_param); let ptr = AstPtr::new(self_param);
let param_pat = self.alloc_pat( let param_pat = self.alloc_pat(
Pat::Bind { Pat::Bind {
name: Name::self_param(), name: SELF_PARAM,
mode: BindingAnnotation::Unannotated, mode: BindingAnnotation::Unannotated,
subpat: None, subpat: None,
}, },

View file

@ -9,6 +9,7 @@ use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, Ty
use crate::{ use crate::{
db::{AstDatabase, DefDatabase, HirDatabase}, db::{AstDatabase, DefDatabase, HirDatabase},
name::SELF_TYPE,
path::Path, path::Path,
type_ref::TypeRef, type_ref::TypeRef,
AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct,
@ -83,7 +84,7 @@ impl GenericParams {
// traits get the Self type as an implicit first type parameter // traits get the Self type as an implicit first type parameter
generics.params.push(GenericParam { generics.params.push(GenericParam {
idx: start, idx: start,
name: Name::self_type(), name: SELF_TYPE,
default: None, default: None,
}); });
generics.fill(&*it.source(db).ast, start + 1); generics.fill(&*it.source(db).ast, start + 1);

View file

@ -49,7 +49,7 @@ mod marks;
use crate::{ use crate::{
db::{AstDatabase, DefDatabase, HirDatabase, InternDatabase}, db::{AstDatabase, DefDatabase, HirDatabase, InternDatabase},
ids::MacroFileKind, ids::MacroFileKind,
name::{AsName, KnownName}, name::AsName,
resolve::Resolver, resolve::Resolver,
source_id::{AstId, FileAstId}, source_id::{AstId, FileAstId},
}; };

View file

@ -26,7 +26,7 @@ impl Name {
/// Note: this is private to make creating name from random string hard. /// Note: this is private to make creating name from random string hard.
/// Hopefully, this should allow us to integrate hygiene cleaner in the /// Hopefully, this should allow us to integrate hygiene cleaner in the
/// future, and to switch to interned representation of names. /// future, and to switch to interned representation of names.
fn new(text: SmolStr) -> Name { const fn new(text: SmolStr) -> Name {
Name { text } Name { text }
} }
@ -34,14 +34,6 @@ impl Name {
Name::new("[missing name]".into()) Name::new("[missing name]".into())
} }
pub(crate) fn self_param() -> Name {
Name::new("self".into())
}
pub(crate) fn self_type() -> Name {
Name::new("Self".into())
}
pub(crate) fn tuple_field_name(idx: usize) -> Name { pub(crate) fn tuple_field_name(idx: usize) -> Name {
Name::new(idx.to_string().into()) Name::new(idx.to_string().into())
} }
@ -63,38 +55,6 @@ impl Name {
pub fn as_smolstr(&self) -> &SmolStr { pub fn as_smolstr(&self) -> &SmolStr {
&self.text &self.text
} }
pub(crate) fn as_known_name(&self) -> Option<KnownName> {
let name = match self.text.as_str() {
"isize" => KnownName::Isize,
"i8" => KnownName::I8,
"i16" => KnownName::I16,
"i32" => KnownName::I32,
"i64" => KnownName::I64,
"i128" => KnownName::I128,
"usize" => KnownName::Usize,
"u8" => KnownName::U8,
"u16" => KnownName::U16,
"u32" => KnownName::U32,
"u64" => KnownName::U64,
"u128" => KnownName::U128,
"f32" => KnownName::F32,
"f64" => KnownName::F64,
"bool" => KnownName::Bool,
"char" => KnownName::Char,
"str" => KnownName::Str,
"Self" => KnownName::SelfType,
"self" => KnownName::SelfParam,
"macro_rules" => KnownName::MacroRules,
"std" => KnownName::Std,
"iter" => KnownName::Iter,
"IntoIterator" => KnownName::IntoIterator,
"Item" => KnownName::Item,
_ => return None,
};
Some(name)
}
} }
pub(crate) trait AsName { pub(crate) trait AsName {
@ -130,76 +90,30 @@ impl AsName for ra_db::Dependency {
} }
} }
// Ideally, should be replaced with pub(crate) const ISIZE: Name = Name::new(SmolStr::new_inline_from_ascii(5, b"isize"));
// ``` pub(crate) const I8: Name = Name::new(SmolStr::new_inline_from_ascii(2, b"i8"));
// const ISIZE: Name = Name::new("isize") pub(crate) const I16: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i16"));
// ``` pub(crate) const I32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i32"));
// but const-fn is not that powerful yet. pub(crate) const I64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i64"));
#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) const I128: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"i128"));
pub(crate) enum KnownName { pub(crate) const USIZE: Name = Name::new(SmolStr::new_inline_from_ascii(5, b"usize"));
Isize, pub(crate) const U8: Name = Name::new(SmolStr::new_inline_from_ascii(2, b"u8"));
I8, pub(crate) const U16: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u16"));
I16, pub(crate) const U32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u32"));
I32, pub(crate) const U64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u64"));
I64, pub(crate) const U128: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"u128"));
I128, pub(crate) const F32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"f32"));
pub(crate) const F64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"f64"));
Usize, pub(crate) const BOOL: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"bool"));
U8, pub(crate) const CHAR: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"char"));
U16, pub(crate) const STR: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"str"));
U32, pub(crate) const SELF_PARAM: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"self"));
U64, pub(crate) const SELF_TYPE: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"Self"));
U128, pub(crate) const MACRO_RULES: Name = Name::new(SmolStr::new_inline_from_ascii(11, b"macro_rules"));
pub(crate) const STD: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"std"));
F32, pub(crate) const ITER: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"iter"));
F64, pub(crate) const INTO_ITERATOR: Name = Name::new(SmolStr::new_inline_from_ascii(12, b"IntoIterator"));
pub(crate) const ITEM: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"Item"));
Bool,
Char,
Str,
SelfType,
SelfParam,
MacroRules,
Std,
Iter,
IntoIterator,
Item,
}
impl AsName for KnownName {
fn as_name(&self) -> Name {
let s = match self {
KnownName::Isize => "isize",
KnownName::I8 => "i8",
KnownName::I16 => "i16",
KnownName::I32 => "i32",
KnownName::I64 => "i64",
KnownName::I128 => "i128",
KnownName::Usize => "usize",
KnownName::U8 => "u8",
KnownName::U16 => "u16",
KnownName::U32 => "u32",
KnownName::U64 => "u64",
KnownName::U128 => "u128",
KnownName::F32 => "f32",
KnownName::F64 => "f64",
KnownName::Bool => "bool",
KnownName::Char => "char",
KnownName::Str => "str",
KnownName::SelfType => "Self",
KnownName::SelfParam => "self",
KnownName::MacroRules => "macro_rules",
KnownName::Std => "std",
KnownName::Iter => "iter",
KnownName::IntoIterator => "IntoIterator",
KnownName::Item => "Item",
};
Name::new(s.into())
}
}
fn resolve_name(text: &SmolStr) -> SmolStr { fn resolve_name(text: &SmolStr) -> SmolStr {
let raw_start = "r#"; let raw_start = "r#";

View file

@ -65,7 +65,7 @@ use test_utils::tested_by;
use crate::{ use crate::{
diagnostics::DiagnosticSink, either::Either, ids::MacroDefId, diagnostics::DiagnosticSink, either::Either, ids::MacroDefId,
nameres::diagnostics::DefDiagnostic, AsName, AstDatabase, AstId, BuiltinType, Crate, nameres::diagnostics::DefDiagnostic, AstDatabase, AstId, BuiltinType, Crate,
DefDatabase, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, DefDatabase, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait,
}; };
@ -138,8 +138,8 @@ pub struct ModuleScope {
static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
BuiltinType::ALL BuiltinType::ALL
.iter() .iter()
.map(|&(known_name, ty)| { .map(|(name, ty)| {
(known_name.as_name(), Resolution { def: PerNs::types(ty.into()), import: None }) (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None })
}) })
.collect() .collect()
}); });

View file

@ -8,11 +8,12 @@ use test_utils::tested_by;
use crate::{ use crate::{
either::Either, either::Either,
ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
name::MACRO_RULES,
nameres::{ nameres::{
diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData,
ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode,
}, },
AstId, Const, DefDatabase, Enum, Function, HirFileId, KnownName, MacroDef, Module, Name, Path, AstId, Const, DefDatabase, Enum, Function, HirFileId, MacroDef, Module, Name, Path,
Static, Struct, Trait, TypeAlias, Union, Static, Struct, Trait, TypeAlias, Union,
}; };
@ -624,7 +625,7 @@ where
} }
fn is_macro_rules(path: &Path) -> bool { fn is_macro_rules(path: &Path) -> bool {
path.as_ident().and_then(Name::as_known_name) == Some(KnownName::MacroRules) path.as_ident() == Some(&MACRO_RULES)
} }
fn resolve_submodule( fn resolve_submodule(

View file

@ -13,7 +13,7 @@ use crate::{
}, },
generics::GenericParams, generics::GenericParams,
impl_block::ImplBlock, impl_block::ImplBlock,
name::{KnownName, Name}, name::{Name, SELF_PARAM, SELF_TYPE},
nameres::{CrateDefMap, CrateModuleId, PerNs}, nameres::{CrateDefMap, CrateModuleId, PerNs},
path::Path, path::Path,
MacroDef, ModuleDef, Trait, MacroDef, ModuleDef, Trait,
@ -151,7 +151,7 @@ impl Resolver {
if let Some(name) = path.as_ident() { if let Some(name) = path.as_ident() {
PathResult::from_resolution(self.resolve_name(db, name)) PathResult::from_resolution(self.resolve_name(db, name))
} else if path.is_self() { } else if path.is_self() {
PathResult::from_resolution(self.resolve_name(db, &Name::self_param())) PathResult::from_resolution(self.resolve_name(db, &SELF_PARAM))
} else { } else {
let (item_map, module) = match self.module() { let (item_map, module) = match self.module() {
Some(it) => it, Some(it) => it,
@ -270,7 +270,7 @@ impl Scope {
fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> { fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
match self { match self {
Scope::ModuleScope(m) => { Scope::ModuleScope(m) => {
if let Some(KnownName::SelfParam) = name.as_known_name() { if name == &SELF_PARAM {
PerNs::types(Resolution::Def(m.crate_def_map.mk_module(m.module_id).into())) PerNs::types(Resolution::Def(m.crate_def_map.mk_module(m.module_id).into()))
} else { } else {
m.crate_def_map m.crate_def_map
@ -283,7 +283,7 @@ impl Scope {
None => PerNs::none(), None => PerNs::none(),
}, },
Scope::ImplBlockScope(i) => { Scope::ImplBlockScope(i) => {
if name.as_known_name() == Some(KnownName::SelfType) { if name == &SELF_TYPE {
PerNs::types(Resolution::SelfType(*i)) PerNs::types(Resolution::SelfType(*i))
} else { } else {
PerNs::none() PerNs::none()
@ -329,7 +329,7 @@ impl Scope {
} }
} }
Scope::ImplBlockScope(i) => { Scope::ImplBlockScope(i) => {
f(Name::self_type(), PerNs::types(Resolution::SelfType(*i))); f(SELF_TYPE, PerNs::types(Resolution::SelfType(*i)));
} }
Scope::ExprScope(e) => { Scope::ExprScope(e) => {
e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {

View file

@ -40,6 +40,7 @@ use crate::{
PatId, Statement, UnaryOp, PatId, Statement, UnaryOp,
}, },
generics::{GenericParams, HasGenericParams}, generics::{GenericParams, HasGenericParams},
name::{SELF_TYPE, INTO_ITERATOR, ITEM, ITER, STD},
nameres::{Namespace, PerNs}, nameres::{Namespace, PerNs},
path::{GenericArg, GenericArgs, PathKind, PathSegment}, path::{GenericArg, GenericArgs, PathKind, PathSegment},
resolve::{ resolve::{
@ -48,7 +49,7 @@ use crate::{
}, },
ty::infer::diagnostics::InferenceDiagnostic, ty::infer::diagnostics::InferenceDiagnostic,
type_ref::{Mutability, TypeRef}, type_ref::{Mutability, TypeRef},
AdtDef, AsName, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, KnownName, AdtDef, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem,
ModuleDef, Name, Path, StructField, ModuleDef, Name, Path, StructField,
}; };
@ -842,7 +843,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
// Parent arguments are unknown, except for the receiver type // Parent arguments are unknown, except for the receiver type
if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) { if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) {
for param in &parent_generics.params { for param in &parent_generics.params {
if param.name.as_known_name() == Some(crate::KnownName::SelfType) { if param.name == SELF_TYPE {
substs.push(receiver_ty.clone()); substs.push(receiver_ty.clone());
} else { } else {
substs.push(Ty::Unknown); substs.push(Ty::Unknown);
@ -1346,15 +1347,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
let into_iter_path = Path { let into_iter_path = Path {
kind: PathKind::Abs, kind: PathKind::Abs,
segments: vec![ segments: vec![
PathSegment { name: KnownName::Std.as_name(), args_and_bindings: None }, PathSegment { name: STD, args_and_bindings: None },
PathSegment { name: KnownName::Iter.as_name(), args_and_bindings: None }, PathSegment { name: ITER, args_and_bindings: None },
PathSegment { name: KnownName::IntoIterator.as_name(), args_and_bindings: None }, PathSegment { name: INTO_ITERATOR, args_and_bindings: None },
], ],
}; };
match self.resolver.resolve_path_segments(self.db, &into_iter_path).into_fully_resolved() { match self.resolver.resolve_path_segments(self.db, &into_iter_path).into_fully_resolved() {
PerNs { types: Some(Def(Trait(trait_))), .. } => { PerNs { types: Some(Def(Trait(trait_))), .. } => {
Some(trait_.associated_type_by_name(self.db, KnownName::Item.as_name())?) Some(trait_.associated_type_by_name(self.db, ITEM)?)
} }
_ => None, _ => None,
} }

View file

@ -17,7 +17,7 @@ rowan = "0.5.0"
# ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here # ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here
# to reduce number of compilations # to reduce number of compilations
text_unit = { version = "0.1.8", features = ["serde"] } text_unit = { version = "0.1.8", features = ["serde"] }
smol_str = { version = "0.1.11", features = ["serde"] } smol_str = { version = "0.1.12", features = ["serde"] }
ra_text_edit = { path = "../ra_text_edit" } ra_text_edit = { path = "../ra_text_edit" }
ra_parser = { path = "../ra_parser" } ra_parser = { path = "../ra_parser" }