Skip to content

Commit

Permalink
Auto merge of #14748 - lumenian:type-alias-layout, r=HKalbasi
Browse files Browse the repository at this point in the history
Show type alias layout

This PR expands on #13490 to allow displaying layout data on hover for type aliases.
  • Loading branch information
bors committed May 6, 2023
2 parents bb66f6f + ecc081d commit a10fd83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/ide/src/hover/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,10 @@ pub(super) fn definition(
}),
Definition::Trait(it) => label_and_docs(db, it),
Definition::TraitAlias(it) => label_and_docs(db, it),
Definition::TypeAlias(it) => label_and_docs(db, it),
Definition::TypeAlias(it) => label_and_layout_info_and_docs(db, it, |&it| {
let layout = it.ty(db).layout(db).ok()?;
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
}),
Definition::BuiltinType(it) => {
return famous_defs
.and_then(|fd| builtin(fd, it))
Expand Down
6 changes: 3 additions & 3 deletions crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ fn test_hover_function_pointer_show_identifiers() {
```
```rust
type foo = fn(a: i32, b: i32) -> i32
type foo = fn(a: i32, b: i32) -> i32 // size = 8, align = 8
```
"#]],
);
Expand All @@ -1423,7 +1423,7 @@ fn test_hover_function_pointer_no_identifier() {
```
```rust
type foo = fn(i32, i32) -> i32
type foo = fn(i32, i32) -> i32 // size = 8, align = 8
```
"#]],
);
Expand Down Expand Up @@ -3555,7 +3555,7 @@ type Fo$0o2 = Foo<2>;
```
```rust
type Foo2 = Foo<2>
type Foo2 = Foo<2> // size = 0, align = 1
```
"#]],
);
Expand Down

0 comments on commit a10fd83

Please sign in to comment.