File tree Expand file tree Collapse file tree 4 files changed +84
-3
lines changed
tests/ui/type/pattern_types Expand file tree Collapse file tree 4 files changed +84
-3
lines changed Original file line number Diff line number Diff line change @@ -822,11 +822,21 @@ where
822
822
| ty:: FnDef ( ..)
823
823
| ty:: CoroutineWitness ( ..)
824
824
| ty:: Foreign ( ..)
825
- | ty:: Pat ( _, _)
826
825
| ty:: Dynamic ( _, _, ty:: Dyn ) => {
827
826
bug ! ( "TyAndLayout::field({:?}): not applicable" , this)
828
827
}
829
828
829
+ // May contain wide pointers
830
+ ty:: Pat ( base, pat) => match * pat {
831
+ ty:: PatternKind :: NotNull => {
832
+ assert_eq ! ( i, 0 ) ;
833
+ TyMaybeWithLayout :: Ty ( base)
834
+ }
835
+ ty:: PatternKind :: Range { .. } | ty:: PatternKind :: Or ( _) => {
836
+ bug ! ( "TyAndLayout::field({this:?}): only applicable to !null patterns" )
837
+ }
838
+ } ,
839
+
830
840
ty:: UnsafeBinder ( bound_ty) => {
831
841
let ty = tcx. instantiate_bound_regions_with_erased ( bound_ty. into ( ) ) ;
832
842
field_ty_or_layout ( TyAndLayout { ty, ..this } , cx, i)
Original file line number Diff line number Diff line change @@ -273,6 +273,12 @@ fn layout_of_uncached<'tcx>(
273
273
} ;
274
274
275
275
layout. largest_niche = Some ( niche) ;
276
+ // Make wide pointer pattern types contain only a single field
277
+ // of the wide pointer type itself.
278
+ layout. fields = FieldsShape :: Arbitrary {
279
+ offsets : [ Size :: ZERO ] . into_iter ( ) . collect ( ) ,
280
+ memory_index : [ 0 ] . into_iter ( ) . collect ( ) ,
281
+ }
276
282
} else {
277
283
bug ! (
278
284
"pattern type with `!null` pattern but not scalar/pair layout: {ty:?}, {layout:?}"
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
12
12
#[ rustc_layout( debug) ]
13
13
type Test = Option < NonNull < ( ) > > ; //~ ERROR layout_of
14
14
15
+ #[ rustc_layout( debug) ]
16
+ type Wide = pattern_type ! ( * const [ u8 ] is !null) ; //~ ERROR layout_of
17
+
15
18
const _: ( ) = assert ! ( size_of:: <NonNull <( ) >>( ) == size_of:: <Option <NonNull <( ) >>>( ) ) ;
16
19
17
20
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -13,7 +13,14 @@ error: layout_of((*const T) is !null) = Layout {
13
13
valid_range: 1..=18446744073709551615,
14
14
},
15
15
),
16
- fields: Primitive,
16
+ fields: Arbitrary {
17
+ offsets: [
18
+ Size(0 bytes),
19
+ ],
20
+ memory_index: [
21
+ 0,
22
+ ],
23
+ },
17
24
largest_niche: Some(
18
25
Niche {
19
26
offset: Size(0 bytes),
@@ -153,5 +160,60 @@ error: layout_of(Option<(*const ()) is !null>) = Layout {
153
160
LL | type Test = Option<NonNull<()>>;
154
161
| ^^^^^^^^^
155
162
156
- error: aborting due to 2 previous errors
163
+ error: layout_of((*const [u8]) is !null) = Layout {
164
+ size: Size(16 bytes),
165
+ align: AbiAndPrefAlign {
166
+ abi: Align(8 bytes),
167
+ pref: Align(8 bytes),
168
+ },
169
+ backend_repr: ScalarPair(
170
+ Initialized {
171
+ value: Pointer(
172
+ AddressSpace(
173
+ 0,
174
+ ),
175
+ ),
176
+ valid_range: 1..=18446744073709551615,
177
+ },
178
+ Initialized {
179
+ value: Int(
180
+ I64,
181
+ false,
182
+ ),
183
+ valid_range: 0..=18446744073709551615,
184
+ },
185
+ ),
186
+ fields: Arbitrary {
187
+ offsets: [
188
+ Size(0 bytes),
189
+ ],
190
+ memory_index: [
191
+ 0,
192
+ ],
193
+ },
194
+ largest_niche: Some(
195
+ Niche {
196
+ offset: Size(0 bytes),
197
+ value: Pointer(
198
+ AddressSpace(
199
+ 0,
200
+ ),
201
+ ),
202
+ valid_range: 1..=18446744073709551615,
203
+ },
204
+ ),
205
+ uninhabited: false,
206
+ variants: Single {
207
+ index: 0,
208
+ },
209
+ max_repr_align: None,
210
+ unadjusted_abi_align: Align(8 bytes),
211
+ randomization_seed: $SEED,
212
+ }
213
+ --> $DIR/non_null.rs:16:1
214
+ |
215
+ LL | type Wide = pattern_type!(*const [u8] is !null);
216
+ | ^^^^^^^^^
217
+
218
+ error: aborting due to 3 previous errors
157
219
You can’t perform that action at this time.
0 commit comments