mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Merge #8745
8745: Support goto_type_definition for types r=matklad a=Veykril I'm unsure if the approach of lowering an `ast::Type` to a `hir::Type` is a good idea, it seems fine to me at least. Fixes #2882 Co-authored-by: Lukas Tobias Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
a8da2ca3a1
@ -196,6 +196,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||||||
self.imp.resolve_label(lifetime)
|
self.imp.resolve_label(lifetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolve_type(&self, ty: &ast::Type) -> Option<Type> {
|
||||||
|
self.imp.resolve_type(ty)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
|
pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
|
||||||
self.imp.type_of_expr(expr)
|
self.imp.type_of_expr(expr)
|
||||||
}
|
}
|
||||||
@ -476,6 +480,14 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
ToDef::to_def(self, src)
|
ToDef::to_def(self, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_type(&self, ty: &ast::Type) -> Option<Type> {
|
||||||
|
let scope = self.scope(ty.syntax());
|
||||||
|
let ctx = body::LowerCtx::new(self.db.upcast(), scope.file_id);
|
||||||
|
let ty = hir_ty::TyLoweringContext::new(self.db, &scope.resolver)
|
||||||
|
.lower_ty(&crate::TypeRef::from_ast(&ctx, ty.clone()));
|
||||||
|
Type::new_with_resolver(self.db, &scope.resolver, ty)
|
||||||
|
}
|
||||||
|
|
||||||
fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
|
fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
|
||||||
self.analyze(expr.syntax()).type_of_expr(self.db, expr)
|
self.analyze(expr.syntax()).type_of_expr(self.db, expr)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ pub(crate) fn goto_type_definition(
|
|||||||
ast::Expr(it) => sema.type_of_expr(&it)?,
|
ast::Expr(it) => sema.type_of_expr(&it)?,
|
||||||
ast::Pat(it) => sema.type_of_pat(&it)?,
|
ast::Pat(it) => sema.type_of_pat(&it)?,
|
||||||
ast::SelfParam(it) => sema.type_of_self(&it)?,
|
ast::SelfParam(it) => sema.type_of_self(&it)?,
|
||||||
|
ast::Type(it) => sema.resolve_type(&it)?,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -146,6 +147,17 @@ struct Foo;
|
|||||||
impl Foo {
|
impl Foo {
|
||||||
fn f(&self$0) {}
|
fn f(&self$0) {}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_def_for_type_fallback() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Foo;
|
||||||
|
//^^^
|
||||||
|
impl Foo$0 {}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user