Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #15022 - HKalbasi:nightly-mir-eval-panic, r=HKalbasi
Fix panic in displaying unsized structs
bors 2023-06-10
parent 5f8a6f6 · parent 1dd76e8 · commit 49b4f15
-rw-r--r--crates/hir-ty/src/display.rs15
-rw-r--r--crates/ide/src/hover/tests.rs20
2 files changed, 34 insertions, 1 deletions
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index 2e7558a7b6..c1df24d172 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -2,7 +2,10 @@
//! HIR back into source code, and just displaying them for debugging/testing
//! purposes.
-use std::fmt::{self, Debug};
+use std::{
+ fmt::{self, Debug},
+ mem::size_of,
+};
use base_db::CrateId;
use chalk_ir::{BoundVar, TyKind};
@@ -552,6 +555,16 @@ fn render_const_scalar(
f.write_str("&")?;
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(match b.try_into() {
Ok(b) => b,
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 22bbdf37a8..f75ebfa12e 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -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]