aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/type_ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/type_ref.rs')
-rw-r--r--crates/hir_def/src/type_ref.rs38
1 files changed, 3 insertions, 35 deletions
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs
index e18712d24..ea29da5da 100644
--- a/crates/hir_def/src/type_ref.rs
+++ b/crates/hir_def/src/type_ref.rs
@@ -1,15 +1,10 @@
1//! HIR for references to types. Paths in these are not yet resolved. They can 1//! HIR for references to types. Paths in these are not yet resolved. They can
2//! be directly created from an ast::TypeRef, without further queries. 2//! be directly created from an ast::TypeRef, without further queries.
3 3
4use hir_expand::{name::Name, AstId, ExpandResult, InFile}; 4use hir_expand::{name::Name, AstId, InFile};
5use syntax::ast; 5use syntax::ast;
6 6
7use crate::{ 7use crate::{body::LowerCtx, path::Path};
8 body::{Expander, LowerCtx},
9 db::DefDatabase,
10 path::Path,
11 ModuleId,
12};
13 8
14#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] 9#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
15pub enum Mutability { 10pub enum Mutability {
@@ -124,7 +119,7 @@ pub enum TypeBound {
124 119
125impl TypeRef { 120impl TypeRef {
126 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 121 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
127 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { 122 pub fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
128 match node { 123 match node {
129 ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), 124 ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
130 ast::Type::TupleType(inner) => { 125 ast::Type::TupleType(inner) => {
@@ -303,30 +298,3 @@ impl TypeBound {
303 } 298 }
304 } 299 }
305} 300}
306
307pub fn expand_macro_type(
308 db: &dyn DefDatabase,
309 module_id: ModuleId,
310 macro_type: &TypeRef,
311) -> Option<TypeRef> {
312 let macro_call = match macro_type {
313 TypeRef::Macro(macro_call) => macro_call,
314 _ => panic!("expected TypeRef::Macro"),
315 };
316
317 let file_id = macro_call.file_id;
318 let macro_call = macro_call.to_node(db.upcast());
319
320 let mut expander = Expander::new(db, file_id, module_id);
321 let (file_id, expanded) = match expander.enter_expand::<ast::Type>(db, macro_call.clone()) {
322 Ok(ExpandResult { value: Some((mark, expanded)), .. }) => {
323 let file_id = expander.current_file_id();
324 expander.exit(db, mark);
325 (file_id, expanded)
326 }
327 _ => return None,
328 };
329
330 let ctx = LowerCtx::new(db, file_id);
331 return Some(TypeRef::from_ast(&ctx, expanded));
332}