Skip to content

Commit 7c9a85b

Browse files
committed
fix: Don't show duplicated adjustment hints for blocks, ifs and matches
1 parent 34e654c commit 7c9a85b

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,12 @@ fn adjustment_hints(
638638
return None;
639639
}
640640

641-
if let ast::Expr::ParenExpr(_) = expr {
642-
// These inherit from the inner expression which would result in duplicate hints
641+
// These inherit from the inner expression which would result in duplicate hints
642+
if let ast::Expr::ParenExpr(_)
643+
| ast::Expr::IfExpr(_)
644+
| ast::Expr::BlockExpr(_)
645+
| ast::Expr::MatchExpr(_) = expr
646+
{
643647
return None;
644648
}
645649

@@ -3083,6 +3087,33 @@ fn main() {
30833087
//^^^^^^^^^^^&
30843088
//^^^^^^^^^^^*
30853089
(&mut Struct).by_ref_mut();
3090+
3091+
// Check that block-like expressions don't duplicate hints
3092+
let _: &mut [u32] = (&mut []);
3093+
//^^^^^^^<unsize>
3094+
//^^^^^^^&mut $
3095+
//^^^^^^^*
3096+
let _: &mut [u32] = { &mut [] };
3097+
//^^^^^^^<unsize>
3098+
//^^^^^^^&mut $
3099+
//^^^^^^^*
3100+
let _: &mut [u32] = unsafe { &mut [] };
3101+
//^^^^^^^<unsize>
3102+
//^^^^^^^&mut $
3103+
//^^^^^^^*
3104+
let _: &mut [u32] = if true {
3105+
&mut []
3106+
//^^^^^^^<unsize>
3107+
//^^^^^^^&mut $
3108+
//^^^^^^^*
3109+
} else {
3110+
loop {}
3111+
//^^^^^^^<never-to-any>
3112+
};
3113+
let _: &mut [u32] = match () { () => &mut [] }
3114+
//^^^^^^^<unsize>
3115+
//^^^^^^^&mut $
3116+
//^^^^^^^*
30863117
}
30873118
30883119
#[derive(Copy, Clone)]
@@ -3092,6 +3123,8 @@ impl Struct {
30923123
fn by_ref(&self) {}
30933124
fn by_ref_mut(&mut self) {}
30943125
}
3126+
trait Trait {}
3127+
impl Trait for Struct {}
30953128
"#,
30963129
)
30973130
}

0 commit comments

Comments
 (0)