1 // Copyright (C) 2024 Free Software Foundation, Inc.
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #![allow(unused_variables)]
18 #![allow(unused_assignments)]
20 fn ignore<T>(x: T) { }
22 // A generic struct that is unsized if T is unsized.
23 pub struct MaybeUnsizedStruct<T: ?Sized> {
28 // Same but without an ordinary part.
29 pub struct MaybeUnsizedStruct2<T: ?Sized> {
34 // This struct is still sized because T is a fixed-length array
35 let sized_struct = &MaybeUnsizedStruct {
40 // This struct is still sized because T is sized
41 let nested_sized_struct = &MaybeUnsizedStruct {
43 rest: MaybeUnsizedStruct {
49 // This will be a fat pointer, containing the length of the final
51 let unsized_struct: &MaybeUnsizedStruct<[u32]> = sized_struct;
53 // This will also be a fat pointer, containing the length of the
55 let nested_unsized_struct:
56 &MaybeUnsizedStruct<MaybeUnsizedStruct<[u32]>> = nested_sized_struct;
58 let alpha: MaybeUnsizedStruct2<[u8; 4]> = MaybeUnsizedStruct2 { value: *b"abc\0" };
59 let beta: &MaybeUnsizedStruct2<[u8]> = α
61 let reference = &unsized_struct;
63 ignore(sized_struct); // set breakpoint here
64 ignore(nested_sized_struct);
65 ignore(unsized_struct);
66 ignore(nested_unsized_struct);