From f8ddef875af08f6c67fe69f7803f3926bc6f66bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 17:19:30 +0300 Subject: remove forward pointer for name --- crates/ra_hir/src/adt.rs | 3 ++- crates/ra_hir/src/code_model.rs | 18 +++++++++--------- crates/ra_hir/src/expr/lower.rs | 4 ++-- crates/ra_hir/src/from_source.rs | 2 +- crates/ra_hir/src/generics.rs | 14 +++++++++----- crates/ra_hir/src/lib.rs | 6 +++--- crates/ra_hir/src/name.rs | 1 - crates/ra_hir/src/nameres/collector.rs | 5 ++--- crates/ra_hir/src/resolve.rs | 20 +++++++++++--------- crates/ra_hir/src/source_binder.rs | 5 +++-- crates/ra_hir/src/traits.rs | 4 ++-- crates/ra_hir/src/ty/autoderef.rs | 3 ++- crates/ra_hir/src/ty/infer.rs | 2 +- crates/ra_hir/src/ty/infer/expr.rs | 3 ++- crates/ra_hir/src/ty/traits/chalk.rs | 3 ++- crates/ra_hir/src/type_alias.rs | 2 +- 16 files changed, 52 insertions(+), 43 deletions(-) delete mode 100644 crates/ra_hir/src/name.rs (limited to 'crates') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 3e9cd3c63..ce64980bb 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -3,13 +3,14 @@ use std::sync::Arc; +use hir_def::name::AsName; use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, type_ref::TypeRef, - AsName, Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, + Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, }; impl Struct { diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index de1377aa4..7848d0a3f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -5,7 +5,13 @@ pub(crate) mod docs; use std::sync::Arc; -use hir_def::{CrateModuleId, ModuleId}; +use hir_def::{ + name::{ + self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, + U16, U32, U64, U8, USIZE, + }, + CrateModuleId, ModuleId, +}; use ra_db::{CrateId, Edition}; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; @@ -20,10 +26,6 @@ use crate::{ TypeAliasId, }, impl_block::ImplBlock, - name::{ - BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64, - U8, USIZE, - }, nameres::{ImportId, ModuleScope, Namespace}, resolve::{Resolver, Scope, TypeNs}, traits::TraitData, @@ -33,7 +35,7 @@ use crate::{ }, type_ref::Mutability, type_ref::TypeRef, - AsName, Either, HasSource, Name, Ty, + Either, HasSource, Name, Ty, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -898,9 +900,7 @@ impl Trait { .where_predicates .iter() .filter_map(|pred| match &pred.type_ref { - TypeRef::Path(p) if p.as_ident() == Some(&crate::name::SELF_TYPE) => { - pred.bound.as_path() - } + TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(), _ => None, }) .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index b3a9a2e6b..cf8a41b1e 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -1,5 +1,6 @@ //! FIXME: write short doc here +use hir_def::name::{self, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -12,7 +13,6 @@ use test_utils::tested_by; use crate::{ db::HirDatabase, - name::{AsName, Name, SELF_PARAM}, path::GenericArgs, ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, type_ref::TypeRef, @@ -78,7 +78,7 @@ where let ptr = AstPtr::new(&self_param); let param_pat = self.alloc_pat( Pat::Bind { - name: SELF_PARAM, + name: name::SELF_PARAM, mode: BindingAnnotation::Unannotated, subpat: None, }, diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 697c8dc84..b9fbaa367 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -1,11 +1,11 @@ //! FIXME: write short doc here +use hir_def::name::AsName; use ra_syntax::ast::{self, AstNode, NameOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, ids::{AstItemDef, LocationCtx}, - name::AsName, AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, }; diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 4ce7551c3..61786a614 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -5,15 +5,15 @@ use std::sync::Arc; +use hir_def::name::{self, AsName}; use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - name::SELF_TYPE, path::Path, type_ref::{TypeBound, TypeRef}, - Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, - Trait, TypeAlias, Union, + Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, + TypeAlias, Union, }; /// Data about a generic parameter (to a function, struct, impl, ...). @@ -94,11 +94,15 @@ impl GenericParams { GenericDef::Adt(Adt::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: name::SELF_TYPE, + default: None, + }); generics.fill(&it.source(db).ast, start + 1); // add super traits as bounds on Self // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar - let self_param = TypeRef::Path(SELF_TYPE.into()); + let self_param = TypeRef::Path(name::SELF_TYPE.into()); generics.fill_bounds(&it.source(db).ast, self_param); } GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index b49f615bf..620911459 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -36,7 +36,6 @@ mod path; pub mod source_binder; mod ids; -mod name; mod nameres; mod adt; mod traits; @@ -61,7 +60,7 @@ mod marks; use hir_expand::AstId; -use crate::{ids::MacroFileKind, name::AsName, resolve::Resolver}; +use crate::{ids::MacroFileKind, resolve::Resolver}; pub use crate::{ adt::VariantDef, @@ -71,7 +70,6 @@ pub use crate::{ generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, impl_block::ImplBlock, - name::Name, nameres::{ImportId, Namespace, PerNs}, path::{Path, PathKind}, resolve::ScopeDef, @@ -89,3 +87,5 @@ pub use self::code_model::{ Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; + +pub use hir_def::name::Name; diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs deleted file mode 100644 index cf66f88ad..000000000 --- a/crates/ra_hir/src/name.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hir_def::name::*; diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 2dd0a5877..1f3849dc7 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir_def::nameres::raw; +use hir_def::{name, nameres::raw}; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -11,7 +11,6 @@ use crate::{ attr::Attr, db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, - name::MACRO_RULES, nameres::{ diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, @@ -726,7 +725,7 @@ where } fn is_macro_rules(path: &Path) -> bool { - path.as_ident() == Some(&MACRO_RULES) + path.as_ident() == Some(&name::MACRO_RULES) } #[cfg(test)] diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 8b6269407..b9459552b 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -1,7 +1,10 @@ //! Name resolution. use std::sync::Arc; -use hir_def::CrateModuleId; +use hir_def::{ + name::{self, Name}, + CrateModuleId, +}; use rustc_hash::FxHashSet; use crate::{ @@ -13,7 +16,6 @@ use crate::{ }, generics::GenericParams, impl_block::ImplBlock, - name::{Name, SELF_PARAM, SELF_TYPE}, nameres::{CrateDefMap, PerNs}, path::{Path, PathKind}, Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, @@ -150,13 +152,13 @@ impl Resolver { } } Scope::ImplBlockScope(impl_) => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let idx = if path.segments.len() == 1 { None } else { Some(1) }; return Some((TypeNs::SelfType(*impl_), idx)); } } Scope::AdtScope(adt) => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let idx = if path.segments.len() == 1 { None } else { Some(1) }; return Some((TypeNs::AdtSelfType(*adt), idx)); } @@ -205,7 +207,7 @@ impl Resolver { return None; } let n_segments = path.segments.len(); - let tmp = SELF_PARAM; + let tmp = name::SELF_PARAM; let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); for scope in self.scopes.iter().rev() { @@ -241,13 +243,13 @@ impl Resolver { Scope::GenericParams(_) => continue, Scope::ImplBlockScope(impl_) if n_segments > 1 => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let ty = TypeNs::SelfType(*impl_); return Some(ResolveValueResult::Partial(ty, 1)); } } Scope::AdtScope(adt) if n_segments > 1 => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let ty = TypeNs::AdtSelfType(*adt); return Some(ResolveValueResult::Partial(ty, 1)); } @@ -459,10 +461,10 @@ impl Scope { } } Scope::ImplBlockScope(i) => { - f(SELF_TYPE, ScopeDef::ImplSelfType(*i)); + f(name::SELF_TYPE, ScopeDef::ImplSelfType(*i)); } Scope::AdtScope(i) => { - f(SELF_TYPE, ScopeDef::AdtSelfType(*i)); + f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); } Scope::ExprScope(e) => { e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 730c33226..8a1fa29a4 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -7,6 +7,7 @@ //! purely for "IDE needs". use std::sync::Arc; +use hir_def::name::AsName; use ra_db::FileId; use ra_syntax::{ ast::{self, AstNode}, @@ -27,8 +28,8 @@ use crate::{ path::known, resolve::{ScopeDef, TypeNs, ValueNs}, ty::method_resolution::implements_trait, - AsName, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, - Module, Name, Path, Resolver, Static, Struct, Ty, + Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module, + Name, Path, Resolver, Static, Struct, Ty, }; fn try_get_resolver_for_node( diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 22f188049..514c813ab 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs @@ -1,14 +1,14 @@ //! HIR for trait definitions. -use rustc_hash::FxHashMap; use std::sync::Arc; +use hir_def::name::AsName; use ra_syntax::ast::{self, NameOwner}; +use rustc_hash::FxHashMap; use crate::{ db::{AstDatabase, DefDatabase}, ids::LocationCtx, - name::AsName, AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias, }; diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 02492ca14..03c45546d 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -5,10 +5,11 @@ use std::iter::successors; +use hir_def::name; use log::{info, warn}; use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; -use crate::{db::HirDatabase, name, HasGenericParams, Resolver}; +use crate::{db::HirDatabase, HasGenericParams, Resolver}; const AUTODEREF_RECURSION_LIMIT: usize = 10; diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index ebaff998e..92b8e718e 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -21,6 +21,7 @@ use std::sync::Arc; use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; +use hir_def::name; use ra_arena::map::ArenaMap; use ra_prof::profile; use test_utils::tested_by; @@ -37,7 +38,6 @@ use crate::{ db::HirDatabase, diagnostics::DiagnosticSink, expr::{BindingAnnotation, Body, ExprId, PatId}, - name, path::known, resolve::{Resolver, TypeNs}, ty::infer::diagnostics::InferenceDiagnostic, diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index f8807c742..7ef87bfe2 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs @@ -3,12 +3,13 @@ use std::iter::{repeat, repeat_with}; use std::sync::Arc; +use hir_def::name; + use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; use crate::{ db::HirDatabase, expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, generics::{GenericParams, HasGenericParams}, - name, nameres::Namespace, path::{GenericArg, GenericArgs}, ty::{ diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index ab66515be..2dd4c2fae 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -9,6 +9,7 @@ use chalk_ir::{ }; use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; +use hir_def::name; use ra_db::salsa::{InternId, InternKey}; use super::{Canonical, ChalkContext, Impl, Obligation}; @@ -734,7 +735,7 @@ fn closure_fn_trait_impl_datum( substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), }; - let output_ty_id = fn_once_trait.associated_type_by_name(db, &crate::name::OUTPUT_TYPE)?; + let output_ty_id = fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?; let output_ty_value = chalk_rust_ir::AssociatedTyValue { associated_ty_id: output_ty_id.to_chalk(db), diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 674a46102..18c01e1b9 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs @@ -2,11 +2,11 @@ use std::sync::Arc; +use hir_def::name::{AsName, Name}; use ra_syntax::ast::NameOwner; use crate::{ db::{AstDatabase, DefDatabase}, - name::{AsName, Name}, type_ref::TypeRef, HasSource, TypeAlias, }; -- cgit v1.2.3