File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 22//! HIR back into source code, and just displaying them for debugging/testing
33//! purposes.
44
5- use std:: fmt:: { self , Debug } ;
5+ use std:: {
6+ fmt:: { self , Debug } ,
7+ mem:: size_of,
8+ } ;
69
710use base_db:: CrateId ;
811use chalk_ir:: { BoundVar , TyKind } ;
@@ -552,6 +555,16 @@ fn render_const_scalar(
552555 f. write_str ( "&" ) ?;
553556 render_const_scalar ( f, bytes, memory_map, t)
554557 }
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+ } ,
555568 _ => {
556569 let addr = usize:: from_le_bytes ( b. try_into ( ) . unwrap ( ) ) ;
557570 let Ok ( layout) = f. db . layout_of_ty ( t. clone ( ) , krate) else {
Original file line number Diff line number Diff line change @@ -4525,6 +4525,26 @@ const FOO$0: Tree = {
45254525 ```
45264526 "# ] ] ,
45274527 ) ;
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+ ) ;
45284548}
45294549
45304550#[ test]
You can’t perform that action at this time.
0 commit comments