File tree 3 files changed +71
-2
lines changed
compiler/rustc_middle/src/ty
tests/ui/type/pattern_types
3 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -822,11 +822,20 @@ 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
+ 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
+
830
839
ty:: UnsafeBinder ( bound_ty) => {
831
840
let ty = tcx. instantiate_bound_regions_with_erased ( bound_ty. into ( ) ) ;
832
841
field_ty_or_layout ( TyAndLayout { ty, ..this } , cx, i)
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ type NonNull<T> = pattern_type!(*const T is !null); //~ ERROR layout_of
10
10
#[ rustc_layout( debug) ]
11
11
type Test = Option < NonNull < ( ) > > ; //~ ERROR layout_of
12
12
13
+ #[ rustc_layout( debug) ]
14
+ type Wide = pattern_type ! ( * const [ u8 ] is !null) ; //~ ERROR layout_of
15
+
13
16
const _: ( ) = assert ! ( size_of:: <NonNull <( ) >>( ) == size_of:: <Option <NonNull <( ) >>>( ) ) ;
14
17
15
18
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -157,5 +157,62 @@ error: layout_of(Option<(*const ()) is !null>) = Layout {
157
157
LL | type Test = Option<NonNull<()>>;
158
158
| ^^^^^^^^^
159
159
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
161
218
You can’t perform that action at this time.
0 commit comments