File tree Expand file tree Collapse file tree 3 files changed +71
-2
lines changed
compiler/rustc_middle/src/ty
tests/ui/type/pattern_types Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -822,11 +822,20 @@ where
822822 | ty:: FnDef ( ..)
823823 | ty:: CoroutineWitness ( ..)
824824 | ty:: Foreign ( ..)
825- | ty:: Pat ( _, _)
826825 | ty:: Dynamic ( _, _, ty:: Dyn ) => {
827826 bug ! ( "TyAndLayout::field({:?}): not applicable" , this)
828827 }
829828
829+ // May contain wide pointers
830+ ty:: Pat ( base, pat) => match * pat {
831+ ty:: PatternKind :: NotNull => {
832+ field_ty_or_layout ( TyAndLayout { ty : base, ..this } , cx, i)
833+ }
834+ ty:: PatternKind :: Range { .. } | ty:: PatternKind :: Or ( _) => {
835+ bug ! ( "TyAndLayout::field({this:?}): only applicable to !null patterns" )
836+ }
837+ } ,
838+
830839 ty:: UnsafeBinder ( bound_ty) => {
831840 let ty = tcx. instantiate_bound_regions_with_erased ( bound_ty. into ( ) ) ;
832841 field_ty_or_layout ( TyAndLayout { ty, ..this } , cx, i)
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ type NonNull<T> = pattern_type!(*const T is !null); //~ ERROR layout_of
1212#[ rustc_layout( debug) ]
1313type Test = Option < NonNull < ( ) > > ; //~ ERROR layout_of
1414
15+ #[ rustc_layout( debug) ]
16+ type Wide = pattern_type ! ( * const [ u8 ] is !null) ; //~ ERROR layout_of
17+
1518const _: ( ) = assert ! ( size_of:: <NonNull <( ) >>( ) == size_of:: <Option <NonNull <( ) >>>( ) ) ;
1619
1720fn main ( ) { }
Original file line number Diff line number Diff line change @@ -157,5 +157,62 @@ error: layout_of(Option<(*const ()) is !null>) = Layout {
157157LL | type Test = Option<NonNull<()>>;
158158 | ^^^^^^^^^
159159
160- error: aborting due to 2 previous errors
160+ error: layout_of((*const [u8]) is !null) = Layout {
161+ size: Size(16 bytes),
162+ align: AbiAndPrefAlign {
163+ abi: Align(8 bytes),
164+ pref: Align(8 bytes),
165+ },
166+ backend_repr: ScalarPair(
167+ Initialized {
168+ value: Pointer(
169+ AddressSpace(
170+ 0,
171+ ),
172+ ),
173+ valid_range: 1..=18446744073709551615,
174+ },
175+ Initialized {
176+ value: Int(
177+ I64,
178+ false,
179+ ),
180+ valid_range: 0..=18446744073709551615,
181+ },
182+ ),
183+ fields: Arbitrary {
184+ offsets: [
185+ Size(0 bytes),
186+ Size(8 bytes),
187+ ],
188+ memory_index: [
189+ 0,
190+ 1,
191+ ],
192+ },
193+ largest_niche: Some(
194+ Niche {
195+ offset: Size(0 bytes),
196+ value: Pointer(
197+ AddressSpace(
198+ 0,
199+ ),
200+ ),
201+ valid_range: 1..=18446744073709551615,
202+ },
203+ ),
204+ uninhabited: false,
205+ variants: Single {
206+ index: 0,
207+ },
208+ max_repr_align: None,
209+ unadjusted_abi_align: Align(8 bytes),
210+ randomization_seed: 16,
211+ }
212+ --> $DIR/non_null.rs:14:1
213+ |
214+ LL | type Wide = pattern_type!(*const [u8] is !null);
215+ | ^^^^^^^^^
216+
217+ error: aborting due to 3 previous errors
161218
You can’t perform that action at this time.
0 commit comments