aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/attrs.rs2
-rw-r--r--crates/hir/src/display.rs32
-rw-r--r--crates/hir/src/lib.rs28
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/hir/src/source_analyzer.rs6
5 files changed, 48 insertions, 22 deletions
diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs
index 505fc05e7..dab8da7bb 100644
--- a/crates/hir/src/attrs.rs
+++ b/crates/hir/src/attrs.rs
@@ -125,5 +125,5 @@ fn resolve_doc_path(
125 Some(Namespace::Macros) => return None, 125 Some(Namespace::Macros) => return None,
126 None => resolved.iter_items().find_map(|it| it.as_module_def_id())?, 126 None => resolved.iter_items().find_map(|it| it.as_module_def_id())?,
127 }; 127 };
128 Some(def.into()) 128 Some(def)
129} 129}
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index 44cdcc296..9f6d7be48 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -12,8 +12,8 @@ use hir_ty::display::{
12use syntax::ast::{self, NameOwner}; 12use syntax::ast::{self, NameOwner};
13 13
14use crate::{ 14use crate::{
15 Const, ConstParam, Enum, Field, Function, HasVisibility, Module, Static, Struct, Substs, Trait, 15 Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam,
16 Type, TypeAlias, TypeParam, Union, Variant, 16 Module, Static, Struct, Substitution, Trait, Type, TypeAlias, TypeParam, Union, Variant,
17}; 17};
18 18
19impl HirDisplay for Function { 19impl HirDisplay for Function {
@@ -120,6 +120,16 @@ impl HirDisplay for Function {
120 } 120 }
121} 121}
122 122
123impl HirDisplay for Adt {
124 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
125 match self {
126 Adt::Struct(it) => it.hir_fmt(f),
127 Adt::Union(it) => it.hir_fmt(f),
128 Adt::Enum(it) => it.hir_fmt(f),
129 }
130 }
131}
132
123impl HirDisplay for Struct { 133impl HirDisplay for Struct {
124 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 134 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
125 write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; 135 write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
@@ -211,11 +221,21 @@ impl HirDisplay for Type {
211 } 221 }
212} 222}
213 223
224impl HirDisplay for GenericParam {
225 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
226 match self {
227 GenericParam::TypeParam(it) => it.hir_fmt(f),
228 GenericParam::LifetimeParam(it) => it.hir_fmt(f),
229 GenericParam::ConstParam(it) => it.hir_fmt(f),
230 }
231 }
232}
233
214impl HirDisplay for TypeParam { 234impl HirDisplay for TypeParam {
215 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 235 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
216 write!(f, "{}", self.name(f.db))?; 236 write!(f, "{}", self.name(f.db))?;
217 let bounds = f.db.generic_predicates_for_param(self.id); 237 let bounds = f.db.generic_predicates_for_param(self.id);
218 let substs = Substs::type_params(f.db, self.id.parent); 238 let substs = Substitution::type_params(f.db, self.id.parent);
219 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); 239 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
220 if !(predicates.is_empty() || f.omit_verbose_types()) { 240 if !(predicates.is_empty() || f.omit_verbose_types()) {
221 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; 241 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
@@ -224,6 +244,12 @@ impl HirDisplay for TypeParam {
224 } 244 }
225} 245}
226 246
247impl HirDisplay for LifetimeParam {
248 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
249 write!(f, "{}", self.name(f.db))
250 }
251}
252
227impl HirDisplay for ConstParam { 253impl HirDisplay for ConstParam {
228 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 254 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
229 write!(f, "const {}: ", self.name(f.db))?; 255 write!(f, "const {}: ", self.name(f.db))?;
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 265a084f3..b41a36a78 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -57,8 +57,8 @@ use hir_ty::{
57 to_assoc_type_id, 57 to_assoc_type_id,
58 traits::{FnTrait, Solution, SolutionVariables}, 58 traits::{FnTrait, Solution, SolutionVariables},
59 AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate, 59 AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate,
60 InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty, 60 InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substitution,
61 TyDefId, TyKind, TyVariableKind, 61 Ty, TyDefId, TyKind, TyVariableKind,
62}; 62};
63use itertools::Itertools; 63use itertools::Itertools;
64use rustc_hash::FxHashSet; 64use rustc_hash::FxHashSet;
@@ -518,7 +518,7 @@ impl Field {
518 VariantDef::Union(it) => it.id.into(), 518 VariantDef::Union(it) => it.id.into(),
519 VariantDef::Variant(it) => it.parent.id.into(), 519 VariantDef::Variant(it) => it.parent.id.into(),
520 }; 520 };
521 let substs = Substs::type_params(db, generic_def_id); 521 let substs = Substitution::type_params(db, generic_def_id);
522 let ty = db.field_types(var_id)[self.id].clone().subst(&substs); 522 let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
523 Type::new(db, self.parent.module(db).id.krate(), var_id, ty) 523 Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
524 } 524 }
@@ -1335,7 +1335,7 @@ impl Local {
1335 1335
1336 // FIXME: why is this an option? It shouldn't be? 1336 // FIXME: why is this an option? It shouldn't be?
1337 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { 1337 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
1338 let body = db.body(self.parent.into()); 1338 let body = db.body(self.parent);
1339 match &body[self.pat_id] { 1339 match &body[self.pat_id] {
1340 Pat::Bind { name, .. } => Some(name.clone()), 1340 Pat::Bind { name, .. } => Some(name.clone()),
1341 _ => None, 1341 _ => None,
@@ -1347,7 +1347,7 @@ impl Local {
1347 } 1347 }
1348 1348
1349 pub fn is_mut(self, db: &dyn HirDatabase) -> bool { 1349 pub fn is_mut(self, db: &dyn HirDatabase) -> bool {
1350 let body = db.body(self.parent.into()); 1350 let body = db.body(self.parent);
1351 matches!(&body[self.pat_id], Pat::Bind { mode: BindingAnnotation::Mutable, .. }) 1351 matches!(&body[self.pat_id], Pat::Bind { mode: BindingAnnotation::Mutable, .. })
1352 } 1352 }
1353 1353
@@ -1360,7 +1360,7 @@ impl Local {
1360 } 1360 }
1361 1361
1362 pub fn ty(self, db: &dyn HirDatabase) -> Type { 1362 pub fn ty(self, db: &dyn HirDatabase) -> Type {
1363 let def = DefWithBodyId::from(self.parent); 1363 let def = self.parent;
1364 let infer = db.infer(def); 1364 let infer = db.infer(def);
1365 let ty = infer[self.pat_id].clone(); 1365 let ty = infer[self.pat_id].clone();
1366 let krate = def.module(db.upcast()).krate(); 1366 let krate = def.module(db.upcast()).krate();
@@ -1368,7 +1368,7 @@ impl Local {
1368 } 1368 }
1369 1369
1370 pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::IdentPat, ast::SelfParam>> { 1370 pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::IdentPat, ast::SelfParam>> {
1371 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 1371 let (_body, source_map) = db.body_with_source_map(self.parent);
1372 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... 1372 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
1373 let root = src.file_syntax(db.upcast()); 1373 let root = src.file_syntax(db.upcast());
1374 src.map(|ast| { 1374 src.map(|ast| {
@@ -1393,12 +1393,12 @@ impl Label {
1393 } 1393 }
1394 1394
1395 pub fn name(self, db: &dyn HirDatabase) -> Name { 1395 pub fn name(self, db: &dyn HirDatabase) -> Name {
1396 let body = db.body(self.parent.into()); 1396 let body = db.body(self.parent);
1397 body[self.label_id].name.clone() 1397 body[self.label_id].name.clone()
1398 } 1398 }
1399 1399
1400 pub fn source(self, db: &dyn HirDatabase) -> InFile<ast::Label> { 1400 pub fn source(self, db: &dyn HirDatabase) -> InFile<ast::Label> {
1401 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 1401 let (_body, source_map) = db.body_with_source_map(self.parent);
1402 let src = source_map.label_syntax(self.label_id); 1402 let src = source_map.label_syntax(self.label_id);
1403 let root = src.file_syntax(db.upcast()); 1403 let root = src.file_syntax(db.upcast());
1404 src.map(|ast| ast.to_node(&root)) 1404 src.map(|ast| ast.to_node(&root))
@@ -1471,7 +1471,7 @@ impl TypeParam {
1471 let resolver = self.id.parent.resolver(db.upcast()); 1471 let resolver = self.id.parent.resolver(db.upcast());
1472 let krate = self.id.parent.module(db.upcast()).krate(); 1472 let krate = self.id.parent.module(db.upcast()).krate();
1473 let ty = params.get(local_idx)?.clone(); 1473 let ty = params.get(local_idx)?.clone();
1474 let subst = Substs::type_params(db, self.id.parent); 1474 let subst = Substitution::type_params(db, self.id.parent);
1475 let ty = ty.subst(&subst.prefix(local_idx)); 1475 let ty = ty.subst(&subst.prefix(local_idx));
1476 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) 1476 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
1477 } 1477 }
@@ -1674,7 +1674,7 @@ impl Type {
1674 krate: CrateId, 1674 krate: CrateId,
1675 def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>, 1675 def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>,
1676 ) -> Type { 1676 ) -> Type {
1677 let substs = Substs::build_for_def(db, def).fill_with_unknown().build(); 1677 let substs = Substitution::build_for_def(db, def).fill_with_unknown().build();
1678 let ty = db.ty(def.into()).subst(&substs); 1678 let ty = db.ty(def.into()).subst(&substs);
1679 Type::new(db, krate, def, ty) 1679 Type::new(db, krate, def, ty)
1680 } 1680 }
@@ -1754,7 +1754,7 @@ impl Type {
1754 pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool { 1754 pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool {
1755 let trait_ref = hir_ty::TraitRef { 1755 let trait_ref = hir_ty::TraitRef {
1756 trait_: trait_.id, 1756 trait_: trait_.id,
1757 substs: Substs::build_for_def(db, trait_.id) 1757 substs: Substitution::build_for_def(db, trait_.id)
1758 .push(self.ty.value.clone()) 1758 .push(self.ty.value.clone())
1759 .fill(args.iter().map(|t| t.ty.value.clone())) 1759 .fill(args.iter().map(|t| t.ty.value.clone()))
1760 .build(), 1760 .build(),
@@ -1778,7 +1778,7 @@ impl Type {
1778 args: &[Type], 1778 args: &[Type],
1779 alias: TypeAlias, 1779 alias: TypeAlias,
1780 ) -> Option<Type> { 1780 ) -> Option<Type> {
1781 let subst = Substs::build_for_def(db, trait_.id) 1781 let subst = Substitution::build_for_def(db, trait_.id)
1782 .push(self.ty.value.clone()) 1782 .push(self.ty.value.clone())
1783 .fill(args.iter().map(|t| t.ty.value.clone())) 1783 .fill(args.iter().map(|t| t.ty.value.clone()))
1784 .build(); 1784 .build();
@@ -2045,7 +2045,7 @@ impl Type {
2045 fn walk_substs( 2045 fn walk_substs(
2046 db: &dyn HirDatabase, 2046 db: &dyn HirDatabase,
2047 type_: &Type, 2047 type_: &Type,
2048 substs: &Substs, 2048 substs: &Substitution,
2049 cb: &mut impl FnMut(Type), 2049 cb: &mut impl FnMut(Type),
2050 ) { 2050 ) {
2051 for ty in substs.iter() { 2051 for ty in substs.iter() {
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index c7e0d0be3..e0eb2a66d 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -836,7 +836,7 @@ impl<'a> SemanticsScope<'a> {
836 resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), 836 resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()),
837 resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(id.into()), 837 resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(id.into()),
838 resolver::ScopeDef::Local(pat_id) => { 838 resolver::ScopeDef::Local(pat_id) => {
839 let parent = resolver.body_owner().unwrap().into(); 839 let parent = resolver.body_owner().unwrap();
840 ScopeDef::Local(Local { parent, pat_id }) 840 ScopeDef::Local(Local { parent, pat_id })
841 } 841 }
842 }; 842 };
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 4d59293e9..37d162b32 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -20,7 +20,7 @@ use hir_def::{
20use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; 20use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
21use hir_ty::{ 21use hir_ty::{
22 diagnostics::{record_literal_missing_fields, record_pattern_missing_fields}, 22 diagnostics::{record_literal_missing_fields, record_pattern_missing_fields},
23 InferenceResult, Substs, 23 InferenceResult, Substitution,
24}; 24};
25use syntax::{ 25use syntax::{
26 ast::{self, AstNode}, 26 ast::{self, AstNode},
@@ -329,7 +329,7 @@ impl SourceAnalyzer {
329 &self, 329 &self,
330 db: &dyn HirDatabase, 330 db: &dyn HirDatabase,
331 krate: CrateId, 331 krate: CrateId,
332 substs: &Substs, 332 substs: &Substitution,
333 variant: VariantId, 333 variant: VariantId,
334 missing_fields: Vec<LocalFieldId>, 334 missing_fields: Vec<LocalFieldId>,
335 ) -> Vec<(Field, Type)> { 335 ) -> Vec<(Field, Type)> {
@@ -484,7 +484,7 @@ fn resolve_hir_path_(
484 resolver.resolve_path_in_value_ns_fully(db.upcast(), path.mod_path()).and_then(|val| { 484 resolver.resolve_path_in_value_ns_fully(db.upcast(), path.mod_path()).and_then(|val| {
485 let res = match val { 485 let res = match val {
486 ValueNs::LocalBinding(pat_id) => { 486 ValueNs::LocalBinding(pat_id) => {
487 let var = Local { parent: body_owner?.into(), pat_id }; 487 let var = Local { parent: body_owner?, pat_id };
488 PathResolution::Local(var) 488 PathResolution::Local(var)
489 } 489 }
490 ValueNs::FunctionId(it) => PathResolution::Def(Function::from(it).into()), 490 ValueNs::FunctionId(it) => PathResolution::Def(Function::from(it).into()),