mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 07:37:30 +00:00
Show inlay hints for type placeholders
Partially fixes #11722 (const parameters TBD) let _: (_, _, [_; _]) = (1_u32, 2_i32, [false]);
This commit is contained in:
parent
b31416da52
commit
2ece970132
3 changed files with 38 additions and 0 deletions
|
@ -288,6 +288,25 @@ fn hints(
|
|||
implied_dyn_trait::hints(hints, famous_defs, config, Either::Right(dyn_));
|
||||
Some(())
|
||||
},
|
||||
ast::Type::InferType(ref infer) => {
|
||||
(|| {
|
||||
let module= sema.scope(infer.syntax())?.module();
|
||||
let ty = sema.resolve_type(&ty)?;
|
||||
let label = ty.display_source_code(sema.db, module.into(), false).ok()?;
|
||||
hints.push(InlayHint {
|
||||
range: infer.syntax().text_range(),
|
||||
kind: InlayKind::Type,
|
||||
label: format!("= {label}").into(),
|
||||
text_edit: None,
|
||||
position: InlayHintPosition::After,
|
||||
pad_left: true,
|
||||
pad_right: false,
|
||||
resolve_parent: None,
|
||||
});
|
||||
Some(())
|
||||
})();
|
||||
Some(())
|
||||
},
|
||||
_ => Some(()),
|
||||
},
|
||||
ast::GenericParamList(it) => bounds::hints(hints, famous_defs, config, it),
|
||||
|
@ -1101,4 +1120,21 @@ where
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inferred_types() {
|
||||
check(
|
||||
r#"
|
||||
struct S<T>(T);
|
||||
|
||||
fn foo() {
|
||||
let t: (_, _, [_; _]) = (1_u32, S(2), [false] as _);
|
||||
//^ = u32
|
||||
//^ = S<i32>
|
||||
//^ = bool
|
||||
//^ = [bool; 1]
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -366,6 +366,7 @@ fn main() {
|
|||
//^^^^^^^^^^^^^^^^^^^^^)
|
||||
//^^^^^^^^^&raw mut *
|
||||
let _: &mut [_] = &mut [0; 0];
|
||||
//^ = i32
|
||||
//^^^^^^^^^^^<unsize>&mut *
|
||||
|
||||
Struct.consume();
|
||||
|
|
|
@ -568,6 +568,7 @@ fn main() {
|
|||
let param = 0;
|
||||
foo(param);
|
||||
foo(param as _);
|
||||
//^ = u32
|
||||
let param_end = 0;
|
||||
foo(param_end);
|
||||
let start_param = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue