Skip to content

Commit 8e1ba7f

Browse files
committed
Fix memory layout config not working for closures
1 parent 98a4c50 commit 8e1ba7f

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

crates/ide/src/hover.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn hover_simple(
227227
return None;
228228
}
229229
let c = token.parent().and_then(|x| x.parent()).and_then(ast::ClosureExpr::cast)?;
230-
render::closure_expr(sema, c)
230+
render::closure_expr(sema, config, c)
231231
})
232232
});
233233

crates/ide/src/hover/render.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ pub(super) fn type_info_of(
4343

4444
pub(super) fn closure_expr(
4545
sema: &Semantics<'_, RootDatabase>,
46+
config: &HoverConfig,
4647
c: ast::ClosureExpr,
4748
) -> Option<HoverResult> {
4849
let ty = &sema.type_of_expr(&c.into())?.original;
49-
let layout = ty
50-
.layout(sema.db)
51-
.map(|x| format!(" // size = {}, align = {}", x.size.bytes(), x.align.abi.bytes()))
52-
.unwrap_or_default();
50+
let layout = if config.memory_layout {
51+
ty.layout(sema.db)
52+
.map(|x| format!(" // size = {}, align = {}", x.size.bytes(), x.align.abi.bytes()))
53+
.unwrap_or_default()
54+
} else {
55+
String::default()
56+
};
5357
let c = ty.as_closure()?;
5458
let mut captures = c
5559
.captured_items(sema.db)

crates/ide/src/hover/tests.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -1766,9 +1766,7 @@ pub fn fo$0o() {}
17661766
#[test]
17671767
fn test_hover_no_memory_layout() {
17681768
check_hover_no_memory_layout(
1769-
r#"
1770-
struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
1771-
"#,
1769+
r#"struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }"#,
17721770
expect![[r#"
17731771
*field_a*
17741772
@@ -1781,6 +1779,26 @@ struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
17811779
```
17821780
"#]],
17831781
);
1782+
1783+
check_hover_no_memory_layout(
1784+
r#"
1785+
//- minicore: copy
1786+
fn main() {
1787+
let x = 2;
1788+
let y = $0|z| x + z;
1789+
}
1790+
"#,
1791+
expect![[r#"
1792+
*|*
1793+
```rust
1794+
{closure#0}
1795+
impl Fn(i32) -> i32
1796+
```
1797+
1798+
## Captures
1799+
* `x` by immutable borrow
1800+
"#]],
1801+
);
17841802
}
17851803

17861804
#[test]

0 commit comments

Comments
 (0)