mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
Fix panic in displaying unsized structs
This commit is contained in:
parent
6fbf6ef514
commit
1dd76e8a9d
2 changed files with 34 additions and 1 deletions
|
@ -2,7 +2,10 @@
|
||||||
//! HIR back into source code, and just displaying them for debugging/testing
|
//! HIR back into source code, and just displaying them for debugging/testing
|
||||||
//! purposes.
|
//! purposes.
|
||||||
|
|
||||||
use std::fmt::{self, Debug};
|
use std::{
|
||||||
|
fmt::{self, Debug},
|
||||||
|
mem::size_of,
|
||||||
|
};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use chalk_ir::{BoundVar, TyKind};
|
use chalk_ir::{BoundVar, TyKind};
|
||||||
|
@ -552,6 +555,16 @@ fn render_const_scalar(
|
||||||
f.write_str("&")?;
|
f.write_str("&")?;
|
||||||
render_const_scalar(f, bytes, memory_map, t)
|
render_const_scalar(f, bytes, memory_map, t)
|
||||||
}
|
}
|
||||||
|
TyKind::Adt(adt, _) if b.len() == 2 * size_of::<usize>() => match adt.0 {
|
||||||
|
hir_def::AdtId::StructId(s) => {
|
||||||
|
let data = f.db.struct_data(s);
|
||||||
|
write!(f, "&{}", data.name.display(f.db.upcast()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return f.write_str("<unsized-enum-or-union>");
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let addr = usize::from_le_bytes(b.try_into().unwrap());
|
let addr = usize::from_le_bytes(b.try_into().unwrap());
|
||||||
let Ok(layout) = f.db.layout_of_ty(t.clone(), krate) else {
|
let Ok(layout) = f.db.layout_of_ty(t.clone(), krate) else {
|
||||||
|
|
|
@ -4525,6 +4525,26 @@ const FOO$0: Tree = {
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
// FIXME: Show the data of unsized structs
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- minicore: slice, index, coerce_unsized, transmute
|
||||||
|
#[repr(transparent)]
|
||||||
|
struct S<T: ?Sized>(T);
|
||||||
|
const FOO$0: &S<[u8]> = core::mem::transmute::<&[u8], _>(&[1, 2, 3]);
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*FOO*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const FOO: &S<[u8]> = &S
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue