Skip to content

Commit 157bd41

Browse files
committed
fix: Fix hover for infer type not working
1 parent a03dfd4 commit 157bd41

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

crates/ide/src/hover/render.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,37 +228,14 @@ pub(super) fn underscore(
228228
return None;
229229
}
230230
let parent = token.parent()?;
231-
let _it = match_ast! {
231+
match_ast! {
232232
match parent {
233-
ast::InferType(it) => it,
234-
ast::UnderscoreExpr(it) => return type_info_of(sema, config, &Either::Left(ast::Expr::UnderscoreExpr(it)),edition, display_target),
235-
ast::WildcardPat(it) => return type_info_of(sema, config, &Either::Right(ast::Pat::WildcardPat(it)),edition, display_target),
236-
_ => return None,
233+
ast::InferType(it) => type_info(sema, config, TypeInfo { original: sema.resolve_type(&ast::Type::InferType(it))?, adjusted: None}, edition, display_target),
234+
ast::UnderscoreExpr(it) => type_info(sema, config, sema.type_of_expr(&ast::Expr::UnderscoreExpr(it))?, edition, display_target),
235+
ast::WildcardPat(it) => type_info(sema, config, sema.type_of_pat(&ast::Pat::WildcardPat(it))?, edition, display_target),
236+
_ => None,
237237
}
238-
};
239-
// let it = infer_type.syntax().parent()?;
240-
// match_ast! {
241-
// match it {
242-
// ast::LetStmt(_it) => (),
243-
// ast::Param(_it) => (),
244-
// ast::RetType(_it) => (),
245-
// ast::TypeArg(_it) => (),
246-
247-
// ast::CastExpr(_it) => (),
248-
// ast::ParenType(_it) => (),
249-
// ast::TupleType(_it) => (),
250-
// ast::PtrType(_it) => (),
251-
// ast::RefType(_it) => (),
252-
// ast::ArrayType(_it) => (),
253-
// ast::SliceType(_it) => (),
254-
// ast::ForType(_it) => (),
255-
// _ => return None,
256-
// }
257-
// }
258-
259-
// FIXME: https://github.com/rust-lang/rust-analyzer/issues/11762, this currently always returns Unknown
260-
// type_info(sema, config, sema.resolve_type(&ast::Type::InferType(it))?, None)
261-
None
238+
}
262239
}
263240

264241
pub(super) fn keyword(

crates/ide/src/hover/tests.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8199,19 +8199,31 @@ fn main() {
81998199

82008200
#[test]
82018201
fn hover_underscore_type() {
8202-
check_hover_no_result(
8202+
check(
82038203
r#"
82048204
fn main() {
82058205
let x: _$0 = 0;
82068206
}
82078207
"#,
8208+
expect![[r#"
8209+
*_*
8210+
```rust
8211+
i32
8212+
```
8213+
"#]],
82088214
);
8209-
check_hover_no_result(
8215+
check(
82108216
r#"
82118217
fn main() {
82128218
let x: (_$0,) = (0,);
82138219
}
82148220
"#,
8221+
expect![[r#"
8222+
*_*
8223+
```rust
8224+
i32
8225+
```
8226+
"#]],
82158227
);
82168228
}
82178229

0 commit comments

Comments
 (0)