Skip to content

Commit cae54d8

Browse files
bors[bot]Veykril
andauthored
Merge #9761
9761: feat: Show coerced types on type hover r=Veykril a=Veykril This applies to both the ranged hover request as well as the normal hover type fallback. ![image](https://user-images.githubusercontent.com/3757771/127883884-2935b624-a3e5-4f35-861a-7d6d3266d187.png) ![image](https://user-images.githubusercontent.com/3757771/127883951-4ff96b6b-7576-4886-887b-1198c1121841.png) We unfortunately have to leave out syntax highlighting here as otherwise the `Type` and `Coerced` words in the hover will get colored. Note that this does not show all the coercions yet(and almost no pattern coercions) as not all coercion adjustments are implemented yet. Closes #2677 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 138849a + f2d2ce0 commit cae54d8

File tree

3 files changed

+157
-79
lines changed

3 files changed

+157
-79
lines changed

crates/hir/src/semantics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
225225
self.imp.type_of_pat(pat)
226226
}
227227

228-
pub fn type_of_pat_with_coercion(&self, expr: &ast::Pat) -> Option<Type> {
228+
pub fn type_of_pat_with_coercion(&self, expr: &ast::Pat) -> Option<(Type, bool)> {
229229
self.imp.type_of_pat_with_coercion(expr)
230230
}
231231

@@ -577,7 +577,7 @@ impl<'db> SemanticsImpl<'db> {
577577
self.analyze(pat.syntax()).type_of_pat(self.db, pat)
578578
}
579579

580-
fn type_of_pat_with_coercion(&self, pat: &ast::Pat) -> Option<Type> {
580+
fn type_of_pat_with_coercion(&self, pat: &ast::Pat) -> Option<(Type, bool)> {
581581
self.analyze(pat.syntax()).type_of_pat_with_coercion(self.db, pat)
582582
}
583583

crates/hir/src/source_analyzer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ impl SourceAnalyzer {
147147
&self,
148148
db: &dyn HirDatabase,
149149
pat: &ast::Pat,
150-
) -> Option<Type> {
150+
) -> Option<(Type, bool)> {
151151
let pat_id = self.pat_id(pat)?;
152152
let infer = self.infer.as_ref()?;
153-
let ty = infer
153+
let (ty, coerced) = infer
154154
.pat_adjustments
155155
.get(&pat_id)
156-
.and_then(|adjusts| adjusts.last().map(|adjust| &adjust.target))
157-
.unwrap_or_else(|| &infer[pat_id]);
158-
Type::new_with_resolver(db, &self.resolver, ty.clone())
156+
.and_then(|adjusts| adjusts.last().map(|adjust| (&adjust.target, true)))
157+
.unwrap_or_else(|| (&infer[pat_id], false));
158+
Type::new_with_resolver(db, &self.resolver, ty.clone()).zip(Some(coerced))
159159
}
160160

161161
pub(crate) fn type_of_self(

0 commit comments

Comments
 (0)