aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/code_model.rs47
-rw-r--r--crates/hir/src/lib.rs10
2 files changed, 45 insertions, 12 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 5721a66c4..031c91ccf 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -2,8 +2,9 @@
2use std::{iter, sync::Arc}; 2use std::{iter, sync::Arc};
3 3
4use arrayvec::ArrayVec; 4use arrayvec::ArrayVec;
5use base_db::{CrateId, Edition, FileId}; 5use base_db::{CrateId, CrateName, Edition, FileId};
6use either::Either; 6use either::Either;
7use hir_def::find_path::PrefixKind;
7use hir_def::{ 8use hir_def::{
8 adt::ReprKind, 9 adt::ReprKind,
9 adt::StructKind, 10 adt::StructKind,
@@ -29,8 +30,12 @@ use hir_expand::{
29use hir_ty::{ 30use hir_ty::{
30 autoderef, 31 autoderef,
31 display::{HirDisplayError, HirFormatter}, 32 display::{HirDisplayError, HirFormatter},
32 method_resolution, ApplicationTy, CallableDefId, Canonical, FnSig, GenericPredicate, 33 method_resolution,
33 InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, 34 traits::Solution,
35 traits::SolutionVariables,
36 ApplicationTy, BoundVar, CallableDefId, Canonical, DebruijnIndex, FnSig, GenericPredicate,
37 InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, Ty,
38 TyDefId, TyKind, TypeCtor,
34}; 39};
35use rustc_hash::FxHashSet; 40use rustc_hash::FxHashSet;
36use stdx::impl_from; 41use stdx::impl_from;
@@ -98,8 +103,8 @@ impl Crate {
98 db.crate_graph()[self.id].edition 103 db.crate_graph()[self.id].edition
99 } 104 }
100 105
101 pub fn display_name(self, db: &dyn HirDatabase) -> Option<String> { 106 pub fn declaration_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
102 db.crate_graph()[self.id].display_name.clone() 107 db.crate_graph()[self.id].declaration_name.clone()
103 } 108 }
104 109
105 pub fn query_external_importables( 110 pub fn query_external_importables(
@@ -390,8 +395,9 @@ impl Module {
390 self, 395 self,
391 db: &dyn DefDatabase, 396 db: &dyn DefDatabase,
392 item: impl Into<ItemInNs>, 397 item: impl Into<ItemInNs>,
398 prefix_kind: PrefixKind,
393 ) -> Option<ModPath> { 399 ) -> Option<ModPath> {
394 hir_def::find_path::find_path_prefixed(db, item.into(), self.into()) 400 hir_def::find_path::find_path_prefixed(db, item.into(), self.into(), prefix_kind)
395 } 401 }
396} 402}
397 403
@@ -1360,6 +1366,35 @@ impl Type {
1360 db.trait_solve(self.krate, goal).is_some() 1366 db.trait_solve(self.krate, goal).is_some()
1361 } 1367 }
1362 1368
1369 pub fn normalize_trait_assoc_type(
1370 &self,
1371 db: &dyn HirDatabase,
1372 r#trait: Trait,
1373 args: &[Type],
1374 alias: TypeAlias,
1375 ) -> Option<Ty> {
1376 let subst = Substs::build_for_def(db, r#trait.id)
1377 .push(self.ty.value.clone())
1378 .fill(args.iter().map(|t| t.ty.value.clone()))
1379 .build();
1380 let predicate = ProjectionPredicate {
1381 projection_ty: ProjectionTy { associated_ty: alias.id, parameters: subst },
1382 ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)),
1383 };
1384 let goal = Canonical {
1385 value: InEnvironment::new(
1386 self.ty.environment.clone(),
1387 Obligation::Projection(predicate),
1388 ),
1389 kinds: Arc::new([TyKind::General]),
1390 };
1391
1392 match db.trait_solve(self.krate, goal)? {
1393 Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(),
1394 Solution::Ambig(_) => None,
1395 }
1396 }
1397
1363 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { 1398 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {
1364 let lang_item = db.lang_item(self.krate, SmolStr::new("copy")); 1399 let lang_item = db.lang_item(self.krate, SmolStr::new("copy"));
1365 let copy_trait = match lang_item { 1400 let copy_trait = match lang_item {
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index b9d9c7e25..4094a76cb 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -48,13 +48,14 @@ pub use hir_def::{
48 body::scope::ExprScopes, 48 body::scope::ExprScopes,
49 builtin_type::BuiltinType, 49 builtin_type::BuiltinType,
50 docs::Documentation, 50 docs::Documentation,
51 find_path::PrefixKind,
51 item_scope::ItemInNs, 52 item_scope::ItemInNs,
52 nameres::ModuleSource, 53 nameres::ModuleSource,
53 path::ModPath, 54 path::{ModPath, PathKind},
54 type_ref::{Mutability, TypeRef}, 55 type_ref::{Mutability, TypeRef},
55}; 56};
56pub use hir_expand::{ 57pub use hir_expand::{
57 name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, 58 name::known, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc,
58 /* FIXME */ MacroDefId, MacroFile, Origin, 59 /* FIXME */ MacroDefId, MacroFile, Origin,
59}; 60};
60pub use hir_ty::display::HirDisplay; 61pub use hir_ty::display::HirDisplay;
@@ -62,7 +63,4 @@ pub use hir_ty::display::HirDisplay;
62// These are negative re-exports: pub using these names is forbidden, they 63// These are negative re-exports: pub using these names is forbidden, they
63// should remain private to hir internals. 64// should remain private to hir internals.
64#[allow(unused)] 65#[allow(unused)]
65use { 66use {hir_def::path::Path, hir_expand::hygiene::Hygiene};
66 hir_def::path::{Path, PathKind},
67 hir_expand::hygiene::Hygiene,
68};