Skip to content

Commit 2ece970

Browse files
Show inlay hints for type placeholders
Partially fixes #11722 (const parameters TBD) let _: (_, _, [_; _]) = (1_u32, 2_i32, [false]);
1 parent b31416d commit 2ece970

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,25 @@ fn hints(
288288
implied_dyn_trait::hints(hints, famous_defs, config, Either::Right(dyn_));
289289
Some(())
290290
},
291+
ast::Type::InferType(ref infer) => {
292+
(|| {
293+
let module= sema.scope(infer.syntax())?.module();
294+
let ty = sema.resolve_type(&ty)?;
295+
let label = ty.display_source_code(sema.db, module.into(), false).ok()?;
296+
hints.push(InlayHint {
297+
range: infer.syntax().text_range(),
298+
kind: InlayKind::Type,
299+
label: format!("= {label}").into(),
300+
text_edit: None,
301+
position: InlayHintPosition::After,
302+
pad_left: true,
303+
pad_right: false,
304+
resolve_parent: None,
305+
});
306+
Some(())
307+
})();
308+
Some(())
309+
},
291310
_ => Some(()),
292311
},
293312
ast::GenericParamList(it) => bounds::hints(hints, famous_defs, config, it),
@@ -1101,4 +1120,21 @@ where
11011120
"#,
11021121
);
11031122
}
1123+
1124+
#[test]
1125+
fn inferred_types() {
1126+
check(
1127+
r#"
1128+
struct S<T>(T);
1129+
1130+
fn foo() {
1131+
let t: (_, _, [_; _]) = (1_u32, S(2), [false] as _);
1132+
//^ = u32
1133+
//^ = S<i32>
1134+
//^ = bool
1135+
//^ = [bool; 1]
1136+
}
1137+
"#,
1138+
);
1139+
}
11041140
}

crates/ide/src/inlay_hints/adjustment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ fn main() {
366366
//^^^^^^^^^^^^^^^^^^^^^)
367367
//^^^^^^^^^&raw mut *
368368
let _: &mut [_] = &mut [0; 0];
369+
//^ = i32
369370
//^^^^^^^^^^^<unsize>&mut *
370371
371372
Struct.consume();

crates/ide/src/inlay_hints/param_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ fn main() {
568568
let param = 0;
569569
foo(param);
570570
foo(param as _);
571+
//^ = u32
571572
let param_end = 0;
572573
foo(param_end);
573574
let start_param = 0;

0 commit comments

Comments
 (0)