mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge pull request #3686 from Veetaha/feature/hover-actual-type-params
ra_hir: add more privacy for Type
This commit is contained in:
commit
f8fd242199
2 changed files with 17 additions and 15 deletions
|
@ -10,7 +10,7 @@ use hir_def::{
|
|||
docs::Documentation,
|
||||
expr::{BindingAnnotation, Pat, PatId},
|
||||
per_ns::PerNs,
|
||||
resolver::HasResolver,
|
||||
resolver::{HasResolver, Resolver},
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule,
|
||||
ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId,
|
||||
|
@ -912,10 +912,8 @@ impl Local {
|
|||
let def = DefWithBodyId::from(self.parent);
|
||||
let infer = db.infer(def);
|
||||
let ty = infer[self.pat_id].clone();
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let krate = def.module(db.upcast()).krate;
|
||||
let environment = TraitEnvironment::lower(db, &resolver);
|
||||
Type { krate, ty: InEnvironment { value: ty, environment } }
|
||||
Type::new(db, krate, def, ty)
|
||||
}
|
||||
|
||||
pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> {
|
||||
|
@ -1020,11 +1018,21 @@ impl ImplDef {
|
|||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Type {
|
||||
pub(crate) krate: CrateId,
|
||||
pub(crate) ty: InEnvironment<Ty>,
|
||||
krate: CrateId,
|
||||
ty: InEnvironment<Ty>,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
pub(crate) fn new_with_resolver(
|
||||
db: &dyn HirDatabase,
|
||||
resolver: &Resolver,
|
||||
ty: Ty,
|
||||
) -> Option<Type> {
|
||||
let krate = resolver.krate()?;
|
||||
let environment = TraitEnvironment::lower(db, &resolver);
|
||||
Some(Type { krate, ty: InEnvironment { value: ty, environment } })
|
||||
}
|
||||
|
||||
fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {
|
||||
let resolver = lexical_env.resolver(db.upcast());
|
||||
let environment = TraitEnvironment::lower(db, &resolver);
|
||||
|
|
|
@ -17,7 +17,7 @@ use hir_def::{
|
|||
AsMacroCall, DefWithBodyId,
|
||||
};
|
||||
use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
|
||||
use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment};
|
||||
use hir_ty::InferenceResult;
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode},
|
||||
SyntaxNode, SyntaxNodePtr, TextUnit,
|
||||
|
@ -103,10 +103,6 @@ impl SourceAnalyzer {
|
|||
Some(res)
|
||||
}
|
||||
|
||||
fn trait_env(&self, db: &dyn HirDatabase) -> Arc<TraitEnvironment> {
|
||||
TraitEnvironment::lower(db, &self.resolver)
|
||||
}
|
||||
|
||||
pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> {
|
||||
let expr_id = match expr {
|
||||
ast::Expr::MacroCall(call) => {
|
||||
|
@ -117,15 +113,13 @@ impl SourceAnalyzer {
|
|||
}?;
|
||||
|
||||
let ty = self.infer.as_ref()?[expr_id].clone();
|
||||
let environment = self.trait_env(db);
|
||||
Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } })
|
||||
Type::new_with_resolver(db, &self.resolver, ty)
|
||||
}
|
||||
|
||||
pub(crate) fn type_of_pat(&self, db: &dyn HirDatabase, pat: &ast::Pat) -> Option<Type> {
|
||||
let pat_id = self.pat_id(pat)?;
|
||||
let ty = self.infer.as_ref()?[pat_id].clone();
|
||||
let environment = self.trait_env(db);
|
||||
Some(Type { krate: self.resolver.krate()?, ty: InEnvironment { value: ty, environment } })
|
||||
Type::new_with_resolver(db, &self.resolver, ty)
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
|
||||
|
|
Loading…
Reference in a new issue