File tree Expand file tree Collapse file tree 4 files changed +82
-3
lines changed
tests/ui/type/pattern_types Expand file tree Collapse file tree 4 files changed +82
-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,10 @@ fn layout_of_uncached<'tcx>(
273
273
} ;
274
274
275
275
layout. largest_niche = Some ( niche) ;
276
+ layout. fields = FieldsShape :: Arbitrary {
277
+ offsets : [ Size :: ZERO ] . into_iter ( ) . collect ( ) ,
278
+ memory_index : [ 0 ] . into_iter ( ) . collect ( ) ,
279
+ }
276
280
} else {
277
281
bug ! (
278
282
"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 @@ -14,7 +14,14 @@ error: layout_of((*const T) is !null) = Layout {
14
14
valid_range: 1..=18446744073709551615,
15
15
},
16
16
),
17
- fields: Primitive,
17
+ fields: Arbitrary {
18
+ offsets: [
19
+ Size(0 bytes),
20
+ ],
21
+ memory_index: [
22
+ 0,
23
+ ],
24
+ },
18
25
largest_niche: Some(
19
26
Niche {
20
27
offset: Size(0 bytes),
@@ -157,5 +164,60 @@ error: layout_of(Option<(*const ()) is !null>) = Layout {
157
164
LL | type Test = Option<NonNull<()>>;
158
165
| ^^^^^^^^^
159
166
160
- error: aborting due to 2 previous errors
167
+ error: layout_of((*const [u8]) is !null) = Layout {
168
+ size: Size(16 bytes),
169
+ align: AbiAndPrefAlign {
170
+ abi: Align(8 bytes),
171
+ pref: Align(8 bytes),
172
+ },
173
+ backend_repr: ScalarPair(
174
+ Initialized {
175
+ value: Pointer(
176
+ AddressSpace(
177
+ 0,
178
+ ),
179
+ ),
180
+ valid_range: 1..=18446744073709551615,
181
+ },
182
+ Initialized {
183
+ value: Int(
184
+ I64,
185
+ false,
186
+ ),
187
+ valid_range: 0..=18446744073709551615,
188
+ },
189
+ ),
190
+ fields: Arbitrary {
191
+ offsets: [
192
+ Size(0 bytes),
193
+ ],
194
+ memory_index: [
195
+ 0,
196
+ ],
197
+ },
198
+ largest_niche: Some(
199
+ Niche {
200
+ offset: Size(0 bytes),
201
+ value: Pointer(
202
+ AddressSpace(
203
+ 0,
204
+ ),
205
+ ),
206
+ valid_range: 1..=18446744073709551615,
207
+ },
208
+ ),
209
+ uninhabited: false,
210
+ variants: Single {
211
+ index: 0,
212
+ },
213
+ max_repr_align: None,
214
+ unadjusted_abi_align: Align(8 bytes),
215
+ randomization_seed: $SEED,
216
+ }
217
+ --> $DIR/non_null.rs:16:1
218
+ |
219
+ LL | type Wide = pattern_type!(*const [u8] is !null);
220
+ | ^^^^^^^^^
221
+
222
+ error: aborting due to 3 previous errors
161
223
You can’t perform that action at this time.
0 commit comments