Fix memory layout config not working for closures
This commit is contained in:
parent
98a4c5049f
commit
8e1ba7fdab
@ -227,7 +227,7 @@ fn hover_simple(
|
||||
return None;
|
||||
}
|
||||
let c = token.parent().and_then(|x| x.parent()).and_then(ast::ClosureExpr::cast)?;
|
||||
render::closure_expr(sema, c)
|
||||
render::closure_expr(sema, config, c)
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -43,13 +43,17 @@ pub(super) fn type_info_of(
|
||||
|
||||
pub(super) fn closure_expr(
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
config: &HoverConfig,
|
||||
c: ast::ClosureExpr,
|
||||
) -> Option<HoverResult> {
|
||||
let ty = &sema.type_of_expr(&c.into())?.original;
|
||||
let layout = ty
|
||||
.layout(sema.db)
|
||||
.map(|x| format!(" // size = {}, align = {}", x.size.bytes(), x.align.abi.bytes()))
|
||||
.unwrap_or_default();
|
||||
let layout = if config.memory_layout {
|
||||
ty.layout(sema.db)
|
||||
.map(|x| format!(" // size = {}, align = {}", x.size.bytes(), x.align.abi.bytes()))
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
String::default()
|
||||
};
|
||||
let c = ty.as_closure()?;
|
||||
let mut captures = c
|
||||
.captured_items(sema.db)
|
||||
|
@ -1766,9 +1766,7 @@ pub fn foo()
|
||||
#[test]
|
||||
fn test_hover_no_memory_layout() {
|
||||
check_hover_no_memory_layout(
|
||||
r#"
|
||||
struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
|
||||
"#,
|
||||
r#"struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }"#,
|
||||
expect![[r#"
|
||||
*field_a*
|
||||
|
||||
@ -1781,6 +1779,26 @@ struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
|
||||
check_hover_no_memory_layout(
|
||||
r#"
|
||||
//- minicore: copy
|
||||
fn main() {
|
||||
let x = 2;
|
||||
let y = $0|z| x + z;
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*|*
|
||||
```rust
|
||||
{closure#0}
|
||||
impl Fn(i32) -> i32
|
||||
```
|
||||
|
||||
## Captures
|
||||
* `x` by immutable borrow
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user