Skip to content

Commit a0cc664

Browse files
bors[bot]lnicola
andauthored
Merge #3797
3797: Don't show chaining hints for record literals and unit structs r=matklad a=lnicola Fixes #3796 r? @Veetaha Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 67351a0 + 70960df commit a0cc664

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

crates/ra_ide/src/inlay_hints.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ fn get_chaining_hints(
7575
return None;
7676
}
7777

78-
let ty = sema.type_of_expr(&expr)?;
79-
if ty.is_unknown() {
78+
if matches!(expr, ast::Expr::RecordLit(_)) {
8079
return None;
8180
}
8281

@@ -95,6 +94,17 @@ fn get_chaining_hints(
9594
let next = tokens.next()?.kind();
9695
let next_next = tokens.next()?.kind();
9796
if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT {
97+
let ty = sema.type_of_expr(&expr)?;
98+
if ty.is_unknown() {
99+
return None;
100+
}
101+
if matches!(expr, ast::Expr::PathExpr(_)) {
102+
if let Some(Adt::Struct(st)) = ty.as_adt() {
103+
if st.fields(sema.db).is_empty() {
104+
return None;
105+
}
106+
}
107+
}
98108
let label = ty.display_truncated(sema.db, config.max_length).to_string();
99109
acc.push(InlayHint {
100110
range: expr.syntax().text_range(),
@@ -1154,32 +1164,35 @@ fn main() {
11541164
struct A { pub b: B }
11551165
struct B { pub c: C }
11561166
struct C(pub bool);
1167+
struct D;
1168+
1169+
impl D {
1170+
fn foo(&self) -> i32 { 42 }
1171+
}
11571172
11581173
fn main() {
11591174
let x = A { b: B { c: C(true) } }
11601175
.b
11611176
.c
11621177
.0;
1178+
let x = D
1179+
.foo();
11631180
}"#,
11641181
);
11651182
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
11661183
[
11671184
InlayHint {
1168-
range: [150; 221),
1185+
range: [252; 323),
11691186
kind: ChainingHint,
11701187
label: "C",
11711188
},
11721189
InlayHint {
1173-
range: [150; 198),
1190+
range: [252; 300),
11741191
kind: ChainingHint,
11751192
label: "B",
11761193
},
1177-
InlayHint {
1178-
range: [150; 175),
1179-
kind: ChainingHint,
1180-
label: "A",
1181-
},
1182-
]"###);
1194+
]
1195+
"###);
11831196
}
11841197

11851198
#[test]

0 commit comments

Comments
 (0)