mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Merge #11771
11771: feat: Visualize compiler inserted reborrows via inlay hints r=Veykril a=Veykril Disabled by default.  Closes https://github.com/rust-analyzer/rust-analyzer/issues/11275 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
966b692422
9 changed files with 127 additions and 17 deletions
|
@ -8,6 +8,7 @@ use base_db::{FileId, FileRange};
|
|||
use hir_def::{
|
||||
body, macro_id_to_def_id,
|
||||
resolver::{self, HasResolver, Resolver, TypeNs},
|
||||
type_ref::Mutability,
|
||||
AsMacroCall, FunctionId, MacroId, TraitId, VariantId,
|
||||
};
|
||||
use hir_expand::{
|
||||
|
@ -313,6 +314,11 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||
self.imp.resolve_type(ty)
|
||||
}
|
||||
|
||||
// FIXME: Figure out a nice interface to inspect adjustments
|
||||
pub fn is_implicit_reborrow(&self, expr: &ast::Expr) -> Option<Mutability> {
|
||||
self.imp.is_implicit_reborrow(expr)
|
||||
}
|
||||
|
||||
pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<TypeInfo> {
|
||||
self.imp.type_of_expr(expr)
|
||||
}
|
||||
|
@ -900,6 +906,10 @@ impl<'db> SemanticsImpl<'db> {
|
|||
Type::new_with_resolver(self.db, &scope.resolver, ty)
|
||||
}
|
||||
|
||||
fn is_implicit_reborrow(&self, expr: &ast::Expr) -> Option<Mutability> {
|
||||
self.analyze(expr.syntax()).is_implicit_reborrow(self.db, expr)
|
||||
}
|
||||
|
||||
fn type_of_expr(&self, expr: &ast::Expr) -> Option<TypeInfo> {
|
||||
self.analyze(expr.syntax())
|
||||
.type_of_expr(self.db, expr)
|
||||
|
|
|
@ -20,12 +20,14 @@ use hir_def::{
|
|||
macro_id_to_def_id,
|
||||
path::{ModPath, Path, PathKind},
|
||||
resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs},
|
||||
type_ref::Mutability,
|
||||
AsMacroCall, DefWithBodyId, FieldId, FunctionId, LocalFieldId, ModuleDefId, VariantId,
|
||||
};
|
||||
use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
|
||||
use hir_ty::{
|
||||
diagnostics::{record_literal_missing_fields, record_pattern_missing_fields},
|
||||
InferenceResult, Interner, Substitution, TyExt, TyLoweringContext,
|
||||
Adjust, Adjustment, AutoBorrow, InferenceResult, Interner, Substitution, TyExt,
|
||||
TyLoweringContext,
|
||||
};
|
||||
use syntax::{
|
||||
ast::{self, AstNode},
|
||||
|
@ -139,6 +141,23 @@ impl SourceAnalyzer {
|
|||
Some(res)
|
||||
}
|
||||
|
||||
pub(crate) fn is_implicit_reborrow(
|
||||
&self,
|
||||
db: &dyn HirDatabase,
|
||||
expr: &ast::Expr,
|
||||
) -> Option<Mutability> {
|
||||
let expr_id = self.expr_id(db, expr)?;
|
||||
let infer = self.infer.as_ref()?;
|
||||
let adjustments = infer.expr_adjustments.get(&expr_id)?;
|
||||
adjustments.windows(2).find_map(|slice| match slice {
|
||||
&[Adjustment {kind: Adjust::Deref(None), ..}, Adjustment {kind: Adjust::Borrow(AutoBorrow::Ref(m)), ..}] => Some(match m {
|
||||
hir_ty::Mutability::Mut => Mutability::Mut,
|
||||
hir_ty::Mutability::Not => Mutability::Shared,
|
||||
}),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn type_of_expr(
|
||||
&self,
|
||||
db: &dyn HirDatabase,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue