diff options
| author | bors <bors@rust-lang.org> | 2023-02-15 13:47:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-15 13:47:29 +0000 |
| commit | dd582dac67e35365dff25c8a299c6e7e0f08dd3e (patch) | |
| tree | 534fec05c7c6b106148fc21ee625bd8f1851f62a | |
| parent | a04054ac3969334d4f907ab751fdd339a1506a2c (diff) | |
| parent | 585919006674d11d3ec38d26ab3ec04506ac1909 (diff) | |
| download | rust-dd582dac67e35365dff25c8a299c6e7e0f08dd3e.tar.gz rust-dd582dac67e35365dff25c8a299c6e7e0f08dd3e.zip | |
Auto merge of #14157 - Veykril:inlay, r=Veykril
Adjust binding mode inlay hints to render better with @ patterns
| -rw-r--r-- | crates/ide/src/inlay_hints/binding_mode.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/crates/ide/src/inlay_hints/binding_mode.rs b/crates/ide/src/inlay_hints/binding_mode.rs index 11b9cd269bf..5d9729263c2 100644 --- a/crates/ide/src/inlay_hints/binding_mode.rs +++ b/crates/ide/src/inlay_hints/binding_mode.rs @@ -29,8 +29,17 @@ pub(super) fn hints( _ => None, }) .last(); - let range = - outer_paren_pat.as_ref().map_or_else(|| pat.syntax(), |it| it.syntax()).text_range(); + let range = outer_paren_pat.as_ref().map_or_else( + || match pat { + // for ident patterns that @ bind a name, render the un-ref patterns in front of the inner pattern + // instead of the name as that makes it more clear and doesn't really change the outcome + ast::Pat::IdentPat(it) => { + it.pat().map_or_else(|| it.syntax().text_range(), |it| it.syntax().text_range()) + } + it => it.syntax().text_range(), + }, + |it| it.syntax().text_range(), + ); let pattern_adjustments = sema.pattern_adjustments(pat); pattern_adjustments.iter().for_each(|ty| { let reference = ty.is_reference(); @@ -123,4 +132,20 @@ fn __( }"#, ); } + + #[test] + fn hints_binding_modes_complex_ident_pat() { + check_with_config( + InlayHintsConfig { binding_mode_hints: true, ..DISABLED_CONFIG }, + r#" +struct Struct { + field: &'static str, +} +fn foo(s @ Struct { field, .. }: &Struct) {} + //^^^^^^^^^^^^^^^^^^^^^^^^ref + //^^^^^^^^^^^^^^^^^^^^& + //^^^^^ref +"#, + ); + } } |
