From b5ce84b17023d27f4e96ec7911aca712db0e000b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 13:15:00 +0200 Subject: Align CallableDefId naming with other ids --- crates/ra_hir/src/code_model.rs | 4 ++-- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir_ty/src/db.rs | 6 ++--- crates/ra_hir_ty/src/diagnostics/unsafe_check.rs | 4 ++-- crates/ra_hir_ty/src/display.rs | 10 ++++---- crates/ra_hir_ty/src/infer/expr.rs | 6 ++--- crates/ra_hir_ty/src/lib.rs | 6 ++--- crates/ra_hir_ty/src/lower.rs | 30 ++++++++++++------------ crates/ra_hir_ty/src/traits/chalk.rs | 4 ++-- crates/ra_hir_ty/src/traits/chalk/mapping.rs | 6 ++--- crates/ra_hir_ty/src/traits/chalk/tls.rs | 24 +++++++++---------- crates/ra_ide/src/call_hierarchy.rs | 2 +- crates/ra_ide/src/call_info.rs | 6 ++--- crates/ra_ide/src/inlay_hints.rs | 6 ++--- 14 files changed, 59 insertions(+), 57 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 42c9ca189..9891b0785 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -40,7 +40,7 @@ use stdx::impl_from; use crate::{ db::{DefDatabase, HirDatabase}, has_source::HasSource, - CallableDef, HirDisplay, InFile, Name, + CallableDefId, HirDisplay, InFile, Name, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -1226,7 +1226,7 @@ impl Type { } // FIXME: this method is broken, as it doesn't take closures into account. - pub fn as_callable(&self) -> Option { + pub fn as_callable(&self) -> Option { Some(self.ty.value.as_callable()?.0) } diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 7d9b174b4..cf7134923 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -55,4 +55,4 @@ pub use hir_expand::{ hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin, }; -pub use hir_ty::{display::HirDisplay, CallableDef}; +pub use hir_ty::{display::HirDisplay, CallableDefId}; diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index cad3856c9..c773adc67 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -13,7 +13,7 @@ use ra_prof::profile; use crate::{ method_resolution::{InherentImpls, TraitImpls}, traits::chalk, - Binders, CallableDef, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, + Binders, CallableDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, }; use hir_expand::name::Name; @@ -45,7 +45,7 @@ pub trait HirDatabase: DefDatabase + Upcast { fn field_types(&self, var: VariantId) -> Arc>>; #[salsa::invoke(crate::callable_item_sig)] - fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig; + fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig; #[salsa::invoke(crate::lower::return_type_impl_traits)] fn return_type_impl_traits( @@ -77,7 +77,7 @@ pub trait HirDatabase: DefDatabase + Upcast { // Interned IDs for Chalk integration #[salsa::interned] - fn intern_callable_def(&self, callable_def: CallableDef) -> InternedCallableDefId; + fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId; #[salsa::interned] fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId; #[salsa::interned] diff --git a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs index 9e4ed9a8b..5cc76bdce 100644 --- a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs @@ -11,7 +11,7 @@ use hir_def::{ use hir_expand::diagnostics::DiagnosticSink; use crate::{ - db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDef, ApplicationTy, + db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDefId, ApplicationTy, InferenceResult, Ty, TypeCtor, }; @@ -88,7 +88,7 @@ fn walk_unsafe( Expr::Call { callee, .. } => { let ty = &infer[*callee]; if let &Ty::Apply(ApplicationTy { - ctor: TypeCtor::FnDef(CallableDef::FunctionId(func)), + ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)), .. }) = ty { diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index c860c254c..758d5f5ac 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs @@ -3,7 +3,7 @@ use std::fmt; use crate::{ - db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate, + db::HirDatabase, utils::generics, ApplicationTy, CallableDefId, FnSig, GenericPredicate, Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, }; use hir_def::{ @@ -263,9 +263,11 @@ impl HirDisplay for ApplicationTy { TypeCtor::FnDef(def) => { let sig = f.db.callable_item_signature(def).subst(&self.parameters); match def { - CallableDef::FunctionId(ff) => write!(f, "fn {}", f.db.function_data(ff).name)?, - CallableDef::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?, - CallableDef::EnumVariantId(e) => { + CallableDefId::FunctionId(ff) => { + write!(f, "fn {}", f.db.function_data(ff).name)? + } + CallableDefId::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?, + CallableDefId::EnumVariantId(e) => { write!(f, "{}", f.db.enum_data(e.parent).variants[e.local_id].name)? } }; diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index ab586b018..731b062c2 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -17,7 +17,7 @@ use crate::{ autoderef, method_resolution, op, traits::{FnTrait, InEnvironment}, utils::{generics, variant_data, Generics}, - ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, + ApplicationTy, Binders, CallableDefId, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, TraitRef, Ty, TypeCtor, }; @@ -854,7 +854,7 @@ impl<'a> InferenceContext<'a> { } // add obligation for trait implementation, if this is a trait method match def { - CallableDef::FunctionId(f) => { + CallableDefId::FunctionId(f) => { if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container { @@ -865,7 +865,7 @@ impl<'a> InferenceContext<'a> { self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } } - CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} + CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {} } } } diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 72b089604..0ef5ca78f 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -44,7 +44,7 @@ use crate::{ pub use autoderef::autoderef; pub use infer::{InferTy, InferenceResult}; -pub use lower::CallableDef; +pub use lower::CallableDefId; pub use lower::{ associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, TyLoweringContext, ValueTyDefId, @@ -102,7 +102,7 @@ pub enum TypeCtor { /// fn foo() -> i32 { 1 } /// let bar = foo; // bar: fn() -> i32 {foo} /// ``` - FnDef(CallableDef), + FnDef(CallableDefId), /// A pointer to a function. Written as `fn() -> i32`. /// @@ -767,7 +767,7 @@ impl Ty { } } - pub fn as_callable(&self) -> Option<(CallableDef, &Substs)> { + pub fn as_callable(&self) -> Option<(CallableDefId, &Substs)> { match self { Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(callable_def), parameters }) => { Some((*callable_def, parameters)) diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 6f4398e84..f274579ea 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -768,11 +768,11 @@ fn count_impl_traits(type_ref: &TypeRef) -> usize { } /// Build the signature of a callable item (function, struct or enum variant). -pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig { +pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDefId) -> PolyFnSig { match def { - CallableDef::FunctionId(f) => fn_sig_for_fn(db, f), - CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s), - CallableDef::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e), + CallableDefId::FunctionId(f) => fn_sig_for_fn(db, f), + CallableDefId::StructId(s) => fn_sig_for_struct_constructor(db, s), + CallableDefId::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e), } } @@ -1107,31 +1107,31 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders { } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum CallableDef { +pub enum CallableDefId { FunctionId(FunctionId), StructId(StructId), EnumVariantId(EnumVariantId), } -impl_from!(FunctionId, StructId, EnumVariantId for CallableDef); +impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId); -impl CallableDef { +impl CallableDefId { pub fn krate(self, db: &dyn HirDatabase) -> CrateId { let db = db.upcast(); match self { - CallableDef::FunctionId(f) => f.lookup(db).module(db), - CallableDef::StructId(s) => s.lookup(db).container.module(db), - CallableDef::EnumVariantId(e) => e.parent.lookup(db).container.module(db), + CallableDefId::FunctionId(f) => f.lookup(db).module(db), + CallableDefId::StructId(s) => s.lookup(db).container.module(db), + CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db), } .krate } } -impl From for GenericDefId { - fn from(def: CallableDef) -> GenericDefId { +impl From for GenericDefId { + fn from(def: CallableDefId) -> GenericDefId { match def { - CallableDef::FunctionId(f) => f.into(), - CallableDef::StructId(s) => s.into(), - CallableDef::EnumVariantId(e) => e.into(), + CallableDefId::FunctionId(f) => f.into(), + CallableDefId::StructId(s) => s.into(), + CallableDefId::EnumVariantId(e) => e.into(), } } } diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index e0a6cfe88..78d0bc43b 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -18,7 +18,7 @@ use crate::{ display::HirDisplay, method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, utils::generics, - CallableDef, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor, + CallableDefId, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor, }; use mapping::{ convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, @@ -525,7 +525,7 @@ pub(crate) fn fn_def_datum_query( _krate: CrateId, fn_def_id: FnDefId, ) -> Arc { - let callable_def: CallableDef = from_chalk(db, fn_def_id); + let callable_def: CallableDefId = from_chalk(db, fn_def_id); let generic_params = generics(db.upcast(), callable_def.into()); let sig = db.callable_item_signature(callable_def); let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index a852ce2ac..09d8347ca 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs @@ -16,7 +16,7 @@ use crate::{ db::HirDatabase, primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, traits::{Canonical, Obligation}, - ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, + ApplicationTy, CallableDefId, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor, }; @@ -454,14 +454,14 @@ impl ToChalk for hir_def::ImplId { } } -impl ToChalk for CallableDef { +impl ToChalk for CallableDefId { type Chalk = FnDefId; fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId { db.intern_callable_def(self).into() } - fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDef { + fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDefId { db.lookup_intern_callable_def(fn_def_id.into()) } } diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index 1e226baea..db915625c 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -5,7 +5,7 @@ use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplicat use itertools::Itertools; use super::{from_chalk, Interner}; -use crate::{db::HirDatabase, CallableDef, TypeCtor}; +use crate::{db::HirDatabase, CallableDefId, TypeCtor}; use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; pub use unsafe_tls::{set_current_program, with_current_program}; @@ -38,16 +38,16 @@ impl DebugContext<'_> { } TypeCtor::FnDef(def) => { let name = match def { - CallableDef::FunctionId(ff) => self.0.function_data(ff).name.clone(), - CallableDef::StructId(s) => self.0.struct_data(s).name.clone(), - CallableDef::EnumVariantId(e) => { + CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(), + CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(), + CallableDefId::EnumVariantId(e) => { let enum_data = self.0.enum_data(e.parent); enum_data.variants[e.local_id].name.clone() } }; match def { - CallableDef::FunctionId(_) => write!(f, "{{fn {}}}", name)?, - CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => { + CallableDefId::FunctionId(_) => write!(f, "{{fn {}}}", name)?, + CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => { write!(f, "{{ctor {}}}", name)? } } @@ -255,18 +255,18 @@ impl DebugContext<'_> { fn_def_id: chalk_ir::FnDefId, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let def: CallableDef = from_chalk(self.0, fn_def_id); + let def: CallableDefId = from_chalk(self.0, fn_def_id); let name = match def { - CallableDef::FunctionId(ff) => self.0.function_data(ff).name.clone(), - CallableDef::StructId(s) => self.0.struct_data(s).name.clone(), - CallableDef::EnumVariantId(e) => { + CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(), + CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(), + CallableDefId::EnumVariantId(e) => { let enum_data = self.0.enum_data(e.parent); enum_data.variants[e.local_id].name.clone() } }; match def { - CallableDef::FunctionId(_) => write!(fmt, "{{fn {}}}", name), - CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => { + CallableDefId::FunctionId(_) => write!(fmt, "{{fn {}}}", name), + CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => { write!(fmt, "{{ctor {}}}", name) } } diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index 884353808..cb7e62cd6 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -97,7 +97,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio //FIXME: Type::as_callable is broken let callable_def = sema.type_of_expr(&expr.expr()?)?.as_callable()?; match callable_def { - hir::CallableDef::FunctionId(it) => { + hir::CallableDefId::FunctionId(it) => { let fn_def: hir::Function = it.into(); let nav = fn_def.to_nav(db); Some(nav) diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 0ef92ed4b..1fe1c21de 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -53,14 +53,14 @@ fn call_info_for_token(sema: &Semantics, token: SyntaxToken) -> Op //FIXME: Type::as_callable is broken let callable_def = sema.type_of_expr(&call.expr()?)?.as_callable()?; match callable_def { - hir::CallableDef::FunctionId(it) => { + hir::CallableDefId::FunctionId(it) => { let fn_def = it.into(); FunctionSignature::from_hir(sema.db, fn_def) } - hir::CallableDef::StructId(it) => { + hir::CallableDefId::StructId(it) => { FunctionSignature::from_struct(sema.db, it.into())? } - hir::CallableDef::EnumVariantId(it) => { + hir::CallableDefId::EnumVariantId(it) => { FunctionSignature::from_enum_variant(sema.db, it.into())? } } diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 35ab741d8..3cbae8a45 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -324,13 +324,13 @@ fn get_fn_signature(sema: &Semantics, expr: &ast::Expr) -> Option< // FIXME: Type::as_callable is broken for closures let callable_def = sema.type_of_expr(&expr.expr()?)?.as_callable()?; match callable_def { - hir::CallableDef::FunctionId(it) => { + hir::CallableDefId::FunctionId(it) => { Some(FunctionSignature::from_hir(sema.db, it.into())) } - hir::CallableDef::StructId(it) => { + hir::CallableDefId::StructId(it) => { FunctionSignature::from_struct(sema.db, it.into()) } - hir::CallableDef::EnumVariantId(it) => { + hir::CallableDefId::EnumVariantId(it) => { FunctionSignature::from_enum_variant(sema.db, it.into()) } } -- cgit v1.2.3