Skip to content

Commit a10fd83

Browse files
committed
Auto merge of #14748 - lumenian:type-alias-layout, r=HKalbasi
Show type alias layout This PR expands on #13490 to allow displaying layout data on hover for type aliases.
2 parents bb66f6f + ecc081d commit a10fd83

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/ide/src/hover/render.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,10 @@ pub(super) fn definition(
473473
}),
474474
Definition::Trait(it) => label_and_docs(db, it),
475475
Definition::TraitAlias(it) => label_and_docs(db, it),
476-
Definition::TypeAlias(it) => label_and_docs(db, it),
476+
Definition::TypeAlias(it) => label_and_layout_info_and_docs(db, it, |&it| {
477+
let layout = it.ty(db).layout(db).ok()?;
478+
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
479+
}),
477480
Definition::BuiltinType(it) => {
478481
return famous_defs
479482
.and_then(|fd| builtin(fd, it))

crates/ide/src/hover/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ fn test_hover_function_pointer_show_identifiers() {
14051405
```
14061406
14071407
```rust
1408-
type foo = fn(a: i32, b: i32) -> i32
1408+
type foo = fn(a: i32, b: i32) -> i32 // size = 8, align = 8
14091409
```
14101410
"#]],
14111411
);
@@ -1423,7 +1423,7 @@ fn test_hover_function_pointer_no_identifier() {
14231423
```
14241424
14251425
```rust
1426-
type foo = fn(i32, i32) -> i32
1426+
type foo = fn(i32, i32) -> i32 // size = 8, align = 8
14271427
```
14281428
"#]],
14291429
);
@@ -3555,7 +3555,7 @@ type Fo$0o2 = Foo<2>;
35553555
```
35563556
35573557
```rust
3558-
type Foo2 = Foo<2>
3558+
type Foo2 = Foo<2> // size = 0, align = 1
35593559
```
35603560
"#]],
35613561
);

0 commit comments

Comments
 (0)