aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/Cargo.toml1
-rw-r--r--crates/hir/src/attrs.rs2
-rw-r--r--crates/hir/src/lib.rs15
-rw-r--r--crates/hir/src/semantics.rs12
-rw-r--r--crates/hir/src/source_analyzer.rs2
5 files changed, 29 insertions, 3 deletions
diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml
index 9e329656f..560b15238 100644
--- a/crates/hir/Cargo.toml
+++ b/crates/hir/Cargo.toml
@@ -25,3 +25,4 @@ hir_expand = { path = "../hir_expand", version = "0.0.0" }
25hir_def = { path = "../hir_def", version = "0.0.0" } 25hir_def = { path = "../hir_def", version = "0.0.0" }
26hir_ty = { path = "../hir_ty", version = "0.0.0" } 26hir_ty = { path = "../hir_ty", version = "0.0.0" }
27tt = { path = "../tt", version = "0.0.0" } 27tt = { path = "../tt", version = "0.0.0" }
28cfg = { path = "../cfg", version = "0.0.0" }
diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs
index 4a11622fc..e8fa3c56e 100644
--- a/crates/hir/src/attrs.rs
+++ b/crates/hir/src/attrs.rs
@@ -112,7 +112,7 @@ fn resolve_doc_path(
112 AttrDefId::MacroDefId(_) => return None, 112 AttrDefId::MacroDefId(_) => return None,
113 }; 113 };
114 let path = ast::Path::parse(link).ok()?; 114 let path = ast::Path::parse(link).ok()?;
115 let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); 115 let modpath = ModPath::from_src(db.upcast(), path, &Hygiene::new_unhygienic()).unwrap();
116 let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); 116 let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath);
117 if resolved == PerNs::none() { 117 if resolved == PerNs::none() {
118 if let Some(trait_id) = resolver.resolve_module_path_in_trait_items(db.upcast(), &modpath) { 118 if let Some(trait_id) = resolver.resolve_module_path_in_trait_items(db.upcast(), &modpath) {
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index d8ccfde0c..c9ef4b420 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -89,6 +89,7 @@ pub use crate::{
89// Generally, a refactoring which *removes* a name from this list is a good 89// Generally, a refactoring which *removes* a name from this list is a good
90// idea! 90// idea!
91pub use { 91pub use {
92 cfg::{CfgAtom, CfgExpr, CfgOptions},
92 hir_def::{ 93 hir_def::{
93 adt::StructKind, 94 adt::StructKind,
94 attr::{Attr, Attrs, AttrsWithOwner, Documentation}, 95 attr::{Attr, Attrs, AttrsWithOwner, Documentation},
@@ -215,6 +216,10 @@ impl Crate {
215 216
216 doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/") 217 doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
217 } 218 }
219
220 pub fn cfg(&self, db: &dyn HirDatabase) -> CfgOptions {
221 db.crate_graph()[self.id].cfg_options.clone()
222 }
218} 223}
219 224
220#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 225#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -1666,7 +1671,7 @@ impl Impl {
1666 .value 1671 .value
1667 .attrs() 1672 .attrs()
1668 .filter_map(|it| { 1673 .filter_map(|it| {
1669 let path = ModPath::from_src(it.path()?, &hygenic)?; 1674 let path = ModPath::from_src(db.upcast(), it.path()?, &hygenic)?;
1670 if path.as_ident()?.to_string() == "derive" { 1675 if path.as_ident()?.to_string() == "derive" {
1671 Some(it) 1676 Some(it)
1672 } else { 1677 } else {
@@ -1744,6 +1749,10 @@ impl Type {
1744 } 1749 }
1745 } 1750 }
1746 1751
1752 pub fn strip_references(&self) -> Type {
1753 self.derived(self.ty.strip_references().clone())
1754 }
1755
1747 pub fn is_unknown(&self) -> bool { 1756 pub fn is_unknown(&self) -> bool {
1748 self.ty.is_unknown() 1757 self.ty.is_unknown()
1749 } 1758 }
@@ -2062,6 +2071,10 @@ impl Type {
2062 Some(adt.into()) 2071 Some(adt.into())
2063 } 2072 }
2064 2073
2074 pub fn as_builtin(&self) -> Option<BuiltinType> {
2075 self.ty.as_builtin().map(|inner| BuiltinType { inner })
2076 }
2077
2065 pub fn as_dyn_trait(&self) -> Option<Trait> { 2078 pub fn as_dyn_trait(&self) -> Option<Trait> {
2066 self.ty.dyn_trait().map(Into::into) 2079 self.ty.dyn_trait().map(Into::into)
2067 } 2080 }
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 62500602a..38bd376bc 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -196,6 +196,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
196 self.imp.resolve_label(lifetime) 196 self.imp.resolve_label(lifetime)
197 } 197 }
198 198
199 pub fn resolve_type(&self, ty: &ast::Type) -> Option<Type> {
200 self.imp.resolve_type(ty)
201 }
202
199 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { 203 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
200 self.imp.type_of_expr(expr) 204 self.imp.type_of_expr(expr)
201 } 205 }
@@ -476,6 +480,14 @@ impl<'db> SemanticsImpl<'db> {
476 ToDef::to_def(self, src) 480 ToDef::to_def(self, src)
477 } 481 }
478 482
483 fn resolve_type(&self, ty: &ast::Type) -> Option<Type> {
484 let scope = self.scope(ty.syntax());
485 let ctx = body::LowerCtx::new(self.db.upcast(), scope.file_id);
486 let ty = hir_ty::TyLoweringContext::new(self.db, &scope.resolver)
487 .lower_ty(&crate::TypeRef::from_ast(&ctx, ty.clone()));
488 Type::new_with_resolver(self.db, &scope.resolver, ty)
489 }
490
479 fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { 491 fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
480 self.analyze(expr.syntax()).type_of_expr(self.db, expr) 492 self.analyze(expr.syntax()).type_of_expr(self.db, expr)
481 } 493 }
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 0895bd6f1..b5c65808e 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -283,7 +283,7 @@ impl SourceAnalyzer {
283 283
284 // This must be a normal source file rather than macro file. 284 // This must be a normal source file rather than macro file.
285 let hygiene = Hygiene::new(db.upcast(), self.file_id); 285 let hygiene = Hygiene::new(db.upcast(), self.file_id);
286 let ctx = body::LowerCtx::with_hygiene(&hygiene); 286 let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
287 let hir_path = Path::from_src(path.clone(), &ctx)?; 287 let hir_path = Path::from_src(path.clone(), &ctx)?;
288 288
289 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we 289 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we