File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 2
2
//! HIR back into source code, and just displaying them for debugging/testing
3
3
//! purposes.
4
4
5
- use std:: fmt:: { self , Debug } ;
5
+ use std:: {
6
+ fmt:: { self , Debug } ,
7
+ mem:: size_of,
8
+ } ;
6
9
7
10
use base_db:: CrateId ;
8
11
use chalk_ir:: { BoundVar , TyKind } ;
@@ -552,6 +555,16 @@ fn render_const_scalar(
552
555
f. write_str ( "&" ) ?;
553
556
render_const_scalar ( f, bytes, memory_map, t)
554
557
}
558
+ TyKind :: Adt ( adt, _) if b. len ( ) == 2 * size_of :: < usize > ( ) => match adt. 0 {
559
+ hir_def:: AdtId :: StructId ( s) => {
560
+ let data = f. db . struct_data ( s) ;
561
+ write ! ( f, "&{}" , data. name. display( f. db. upcast( ) ) ) ?;
562
+ Ok ( ( ) )
563
+ }
564
+ _ => {
565
+ return f. write_str ( "<unsized-enum-or-union>" ) ;
566
+ }
567
+ } ,
555
568
_ => {
556
569
let addr = usize:: from_le_bytes ( match b. try_into ( ) {
557
570
Ok ( b) => b,
Original file line number Diff line number Diff line change @@ -4525,6 +4525,26 @@ const FOO$0: Tree = {
4525
4525
```
4526
4526
"# ] ] ,
4527
4527
) ;
4528
+ // FIXME: Show the data of unsized structs
4529
+ check (
4530
+ r#"
4531
+ //- minicore: slice, index, coerce_unsized, transmute
4532
+ #[repr(transparent)]
4533
+ struct S<T: ?Sized>(T);
4534
+ const FOO$0: &S<[u8]> = core::mem::transmute::<&[u8], _>(&[1, 2, 3]);
4535
+ "# ,
4536
+ expect ! [ [ r#"
4537
+ *FOO*
4538
+
4539
+ ```rust
4540
+ test
4541
+ ```
4542
+
4543
+ ```rust
4544
+ const FOO: &S<[u8]> = &S
4545
+ ```
4546
+ "# ] ] ,
4547
+ ) ;
4528
4548
}
4529
4549
4530
4550
#[ test]
You can’t perform that action at this time.
0 commit comments