From 012fec54dc508896493d5d3073b4786c93d66fe9 Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Mon, 8 Jul 2019 03:29:38 +0600 Subject: [PATCH 1/2] Constify KnownName's --- Cargo.lock | 10 +- crates/ra_hir/src/code_model.rs | 41 ++++---- crates/ra_hir/src/expr.rs | 4 +- crates/ra_hir/src/generics.rs | 3 +- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/name.rs | 136 +++++-------------------- crates/ra_hir/src/nameres.rs | 6 +- crates/ra_hir/src/nameres/collector.rs | 5 +- crates/ra_hir/src/resolve.rs | 10 +- crates/ra_hir/src/ty/infer.rs | 13 +-- crates/ra_syntax/Cargo.toml | 2 +- 11 files changed, 75 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0599edb33..85dbd2a373 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1278,7 +1278,7 @@ dependencies = [ "ra_parser 0.1.0", "ra_text_edit 0.1.0", "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", "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)", @@ -1308,7 +1308,7 @@ dependencies = [ name = "ra_tt" version = "0.1.0" 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]] @@ -1563,7 +1563,7 @@ dependencies = [ "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)", "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)", ] @@ -1722,7 +1722,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smol_str" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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 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 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 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" diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6cf2c620d6..8922163adf 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -19,6 +19,7 @@ use crate::{ TypeAliasId, }, 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}, resolve::Resolver, traits::{TraitData, TraitItem}, @@ -28,7 +29,7 @@ use crate::{ }, type_ref::Mutability, 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 @@ -96,27 +97,27 @@ pub enum BuiltinType { impl BuiltinType { #[rustfmt::skip] - pub(crate) const ALL: &'static [(KnownName, BuiltinType)] = &[ - (KnownName::Char, BuiltinType::Char), - (KnownName::Bool, BuiltinType::Bool), - (KnownName::Str, BuiltinType::Str), + pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[ + (CHAR, BuiltinType::Char), + (BOOL, BuiltinType::Bool), + (STR, BuiltinType::Str), - (KnownName::Isize, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), - (KnownName::I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })), - (KnownName::I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })), - (KnownName::I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })), - (KnownName::I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })), - (KnownName::I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })), + (ISIZE, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), + (I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })), + (I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })), + (I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })), + (I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })), + (I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })), - (KnownName::Usize, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), - (KnownName::U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), - (KnownName::U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), - (KnownName::U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), - (KnownName::U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), - (KnownName::U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), + (USIZE, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), + (U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), + (U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), + (U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), + (U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), + (U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), - (KnownName::F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), - (KnownName::F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })), + (F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), + (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() { TypeRef::from_ast(type_ref) } else { - let self_type = TypeRef::Path(Name::self_type().into()); + let self_type = TypeRef::Path(SELF_TYPE.into()); match self_param.kind() { ast::SelfParamKind::Owned => self_type, ast::SelfParamKind::Ref => { diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 3e763fef0a..3a97d97ce1 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -13,7 +13,7 @@ use ra_syntax::{ }; use crate::{ - name::AsName, + name::{AsName, SELF_PARAM}, type_ref::{Mutability, TypeRef}, DefWithBody, Either, HasSource, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Name, Path, Resolver, @@ -981,7 +981,7 @@ where let ptr = AstPtr::new(self_param); let param_pat = self.alloc_pat( Pat::Bind { - name: Name::self_param(), + name: SELF_PARAM, mode: BindingAnnotation::Unannotated, subpat: None, }, diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 521e47090d..3ad2c551a0 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -9,6 +9,7 @@ use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, Ty use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, + name::SELF_TYPE, path::Path, type_ref::TypeRef, 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 generics.params.push(GenericParam { idx: start, - name: Name::self_type(), + name: SELF_TYPE, default: None, }); generics.fill(&*it.source(db).ast, start + 1); diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index ec0676783f..56831ba05b 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -49,7 +49,7 @@ mod marks; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase, InternDatabase}, ids::MacroFileKind, - name::{AsName, KnownName}, + name::AsName, resolve::Resolver, source_id::{AstId, FileAstId}, }; diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index b71590560e..7187953140 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs @@ -26,7 +26,7 @@ impl Name { /// Note: this is private to make creating name from random string hard. /// Hopefully, this should allow us to integrate hygiene cleaner in the /// future, and to switch to interned representation of names. - fn new(text: SmolStr) -> Name { + const fn new(text: SmolStr) -> Name { Name { text } } @@ -34,14 +34,6 @@ impl Name { 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 { Name::new(idx.to_string().into()) } @@ -63,38 +55,6 @@ impl Name { pub fn as_smolstr(&self) -> &SmolStr { &self.text } - - pub(crate) fn as_known_name(&self) -> Option { - 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 { @@ -130,76 +90,30 @@ impl AsName for ra_db::Dependency { } } -// Ideally, should be replaced with -// ``` -// const ISIZE: Name = Name::new("isize") -// ``` -// but const-fn is not that powerful yet. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) enum KnownName { - Isize, - I8, - I16, - I32, - I64, - I128, - - Usize, - U8, - U16, - U32, - U64, - U128, - - F32, - F64, - - 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()) - } -} +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")); +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")); +pub(crate) const I64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"i64")); +pub(crate) const I128: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"i128")); +pub(crate) const USIZE: Name = Name::new(SmolStr::new_inline_from_ascii(5, b"usize")); +pub(crate) const U8: Name = Name::new(SmolStr::new_inline_from_ascii(2, b"u8")); +pub(crate) const U16: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u16")); +pub(crate) const U32: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u32")); +pub(crate) const U64: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"u64")); +pub(crate) const U128: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"u128")); +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")); +pub(crate) const BOOL: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"bool")); +pub(crate) const CHAR: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"char")); +pub(crate) const STR: Name = Name::new(SmolStr::new_inline_from_ascii(3, b"str")); +pub(crate) const SELF_PARAM: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"self")); +pub(crate) const SELF_TYPE: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"Self")); +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")); +pub(crate) const ITER: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"iter")); +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")); fn resolve_name(text: &SmolStr) -> SmolStr { let raw_start = "r#"; diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index c84d2eada8..4c5623063a 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -65,7 +65,7 @@ use test_utils::tested_by; use crate::{ 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, }; @@ -138,8 +138,8 @@ pub struct ModuleScope { static BUILTIN_SCOPE: Lazy> = Lazy::new(|| { BuiltinType::ALL .iter() - .map(|&(known_name, ty)| { - (known_name.as_name(), Resolution { def: PerNs::types(ty.into()), import: None }) + .map(|(name, ty)| { + (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None }) }) .collect() }); diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 9f197bb58f..1c3b453bd0 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -8,11 +8,12 @@ use test_utils::tested_by; use crate::{ either::Either, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, + name::MACRO_RULES, nameres::{ diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, 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, }; @@ -624,7 +625,7 @@ where } 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( diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index e2a7639b02..ef75308f62 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -13,7 +13,7 @@ use crate::{ }, generics::GenericParams, impl_block::ImplBlock, - name::{KnownName, Name}, + name::{Name, SELF_PARAM, SELF_TYPE}, nameres::{CrateDefMap, CrateModuleId, PerNs}, path::Path, MacroDef, ModuleDef, Trait, @@ -151,7 +151,7 @@ impl Resolver { if let Some(name) = path.as_ident() { PathResult::from_resolution(self.resolve_name(db, name)) } 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 { let (item_map, module) = match self.module() { Some(it) => it, @@ -270,7 +270,7 @@ impl Scope { fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs { match self { 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())) } else { m.crate_def_map @@ -283,7 +283,7 @@ impl Scope { None => PerNs::none(), }, Scope::ImplBlockScope(i) => { - if name.as_known_name() == Some(KnownName::SelfType) { + if name == &SELF_TYPE { PerNs::types(Resolution::SelfType(*i)) } else { PerNs::none() @@ -329,7 +329,7 @@ impl Scope { } } Scope::ImplBlockScope(i) => { - f(Name::self_type(), PerNs::types(Resolution::SelfType(*i))); + f(SELF_TYPE, PerNs::types(Resolution::SelfType(*i))); } Scope::ExprScope(e) => { e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 973de70dfb..41980a3253 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -40,6 +40,7 @@ use crate::{ PatId, Statement, UnaryOp, }, generics::{GenericParams, HasGenericParams}, + name::{SELF_TYPE, INTO_ITERATOR, ITEM, ITER, STD}, nameres::{Namespace, PerNs}, path::{GenericArg, GenericArgs, PathKind, PathSegment}, resolve::{ @@ -48,7 +49,7 @@ use crate::{ }, ty::infer::diagnostics::InferenceDiagnostic, type_ref::{Mutability, TypeRef}, - AdtDef, AsName, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, KnownName, + AdtDef, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, ModuleDef, Name, Path, StructField, }; @@ -842,7 +843,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Parent arguments are unknown, except for the receiver type if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) { 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()); } else { substs.push(Ty::Unknown); @@ -1346,15 +1347,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let into_iter_path = Path { kind: PathKind::Abs, segments: vec![ - PathSegment { name: KnownName::Std.as_name(), args_and_bindings: None }, - PathSegment { name: KnownName::Iter.as_name(), args_and_bindings: None }, - PathSegment { name: KnownName::IntoIterator.as_name(), args_and_bindings: None }, + PathSegment { name: STD, args_and_bindings: None }, + PathSegment { name: ITER, 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() { 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, } diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 95ff6b1d85..156991358e 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -17,7 +17,7 @@ rowan = "0.5.0" # ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here # to reduce number of compilations 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_parser = { path = "../ra_parser" } From 09b72489dd085dadce94b454408d18a36abb1681 Mon Sep 17 00:00:00 2001 From: Muhammad Mominul Huque Date: Mon, 8 Jul 2019 04:09:35 +0600 Subject: [PATCH 2/2] cargo format --- crates/ra_hir/src/code_model.rs | 5 ++++- crates/ra_hir/src/generics.rs | 6 +----- crates/ra_hir/src/name.rs | 3 ++- crates/ra_hir/src/nameres.rs | 4 ++-- crates/ra_hir/src/nameres/collector.rs | 4 ++-- crates/ra_hir/src/ty/infer.rs | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 8922163adf..8053576623 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -19,7 +19,10 @@ use crate::{ TypeAliasId, }, impl_block::ImplBlock, - name::{BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, STR, U128, U16, U32, U64, U8, USIZE, SELF_TYPE}, + name::{ + BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64, + U8, USIZE, + }, nameres::{CrateModuleId, ImportId, ModuleScope, Namespace}, resolve::Resolver, traits::{TraitData, TraitItem}, diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 3ad2c551a0..07a59193f0 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -82,11 +82,7 @@ impl GenericParams { GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), GenericDef::Trait(it) => { // traits get the Self type as an implicit first type parameter - generics.params.push(GenericParam { - idx: start, - name: SELF_TYPE, - default: None, - }); + generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); generics.fill(&*it.source(db).ast, start + 1); } GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start), diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index 7187953140..5f64b7759e 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs @@ -112,7 +112,8 @@ pub(crate) const SELF_TYPE: Name = Name::new(SmolStr::new_inline_from_ascii(4, b 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")); pub(crate) const ITER: Name = Name::new(SmolStr::new_inline_from_ascii(4, b"iter")); -pub(crate) const INTO_ITERATOR: Name = Name::new(SmolStr::new_inline_from_ascii(12, b"IntoIterator")); +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")); fn resolve_name(text: &SmolStr) -> SmolStr { diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 4c5623063a..bbdc606cd9 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -65,8 +65,8 @@ use test_utils::tested_by; use crate::{ diagnostics::DiagnosticSink, either::Either, ids::MacroDefId, - nameres::diagnostics::DefDiagnostic, AstDatabase, AstId, BuiltinType, Crate, - DefDatabase, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, + nameres::diagnostics::DefDiagnostic, AstDatabase, AstId, BuiltinType, Crate, DefDatabase, + HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, }; pub(crate) use self::raw::{ImportSourceMap, RawItems}; diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 1c3b453bd0..552a1b6d9e 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -13,8 +13,8 @@ use crate::{ diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, }, - AstId, Const, DefDatabase, Enum, Function, HirFileId, MacroDef, Module, Name, Path, - Static, Struct, Trait, TypeAlias, Union, + AstId, Const, DefDatabase, Enum, Function, HirFileId, MacroDef, Module, Name, Path, Static, + Struct, Trait, TypeAlias, Union, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 41980a3253..52a49070a1 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -40,7 +40,7 @@ use crate::{ PatId, Statement, UnaryOp, }, generics::{GenericParams, HasGenericParams}, - name::{SELF_TYPE, INTO_ITERATOR, ITEM, ITER, STD}, + name::{INTO_ITERATOR, ITEM, ITER, SELF_TYPE, STD}, nameres::{Namespace, PerNs}, path::{GenericArg, GenericArgs, PathKind, PathSegment}, resolve::{ @@ -49,8 +49,8 @@ use crate::{ }, ty::infer::diagnostics::InferenceDiagnostic, type_ref::{Mutability, TypeRef}, - AdtDef, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, - ModuleDef, Name, Path, StructField, + AdtDef, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, ModuleDef, Name, Path, + StructField, }; mod unify;