Skip to content

Commit f38819c

Browse files
committed
Add some layout tests for pattern type edge cases
1 parent 2c6a12e commit f38819c

File tree

2 files changed

+229
-2
lines changed

2 files changed

+229
-2
lines changed

Diff for: tests/ui/type/pattern_types/range_patterns.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(pattern_types, rustc_attrs)]
1+
#![feature(pattern_types, rustc_attrs, const_trait_impl, pattern_type_range_trait)]
22
#![feature(pattern_type_macro)]
33
#![allow(incomplete_features)]
44

@@ -18,6 +18,25 @@ type A = Option<std::num::NonZeroU32>; //~ ERROR layout_of
1818
#[rustc_layout(debug)]
1919
struct NonZeroU32New(pattern_type!(u32 is 1..)); //~ ERROR layout_of
2020

21+
#[rustc_layout(debug)]
22+
type EMPTY = pattern_type!(u32 is 1..1); //~ ERROR layout_of
23+
24+
#[rustc_layout(debug)]
25+
type WRAP = pattern_type!(u32 is 1..0); //~ ERROR unknown layout
26+
//~^ ERROR: evaluation of constant value failed
27+
28+
#[rustc_layout(debug)]
29+
type WRAP2 = pattern_type!(u32 is 5..2); //~ ERROR layout_of
30+
31+
#[rustc_layout(debug)]
32+
type SIGN = pattern_type!(i8 is -10..=10); //~ ERROR layout_of
33+
34+
#[rustc_layout(debug)]
35+
type MIN = pattern_type!(i8 is -128..=0); //~ ERROR layout_of
36+
37+
#[rustc_layout(debug)]
38+
type SignedWrap = pattern_type!(i8 is 120..=-120); //~ ERROR layout_of
39+
2140
fn main() {
2241
let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(42_u32) };
2342
}

Diff for: tests/ui/type/pattern_types/range_patterns.stderr

+209-1
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,213 @@ error: layout_of(NonZeroU32New) = Layout {
357357
LL | struct NonZeroU32New(pattern_type!(u32 is 1..));
358358
| ^^^^^^^^^^^^^^^^^^^^
359359

360-
error: aborting due to 5 previous errors
360+
error: layout_of((u32) is 1..=0) = Layout {
361+
size: Size(4 bytes),
362+
align: AbiAndPrefAlign {
363+
abi: Align(4 bytes),
364+
pref: $SOME_ALIGN,
365+
},
366+
backend_repr: Scalar(
367+
Initialized {
368+
value: Int(
369+
I32,
370+
false,
371+
),
372+
valid_range: (..=0) | (1..),
373+
},
374+
),
375+
fields: Primitive,
376+
largest_niche: Some(
377+
Niche {
378+
offset: Size(0 bytes),
379+
value: Int(
380+
I32,
381+
false,
382+
),
383+
valid_range: (..=0) | (1..),
384+
},
385+
),
386+
uninhabited: false,
387+
variants: Single {
388+
index: 0,
389+
},
390+
max_repr_align: None,
391+
unadjusted_abi_align: Align(4 bytes),
392+
randomization_seed: $SEED,
393+
}
394+
--> $DIR/range_patterns.rs:22:1
395+
|
396+
LL | type EMPTY = pattern_type!(u32 is 1..1);
397+
| ^^^^^^^^^^
398+
399+
error[E0080]: evaluation of constant value failed
400+
--> $DIR/range_patterns.rs:25:37
401+
|
402+
LL | type WRAP = pattern_type!(u32 is 1..0);
403+
| ^ evaluation panicked: exclusive range end at minimum value of type
404+
405+
error: the type has an unknown layout
406+
--> $DIR/range_patterns.rs:25:1
407+
|
408+
LL | type WRAP = pattern_type!(u32 is 1..0);
409+
| ^^^^^^^^^
410+
411+
error: layout_of((u32) is 5..=1) = Layout {
412+
size: Size(4 bytes),
413+
align: AbiAndPrefAlign {
414+
abi: Align(4 bytes),
415+
pref: $SOME_ALIGN,
416+
},
417+
backend_repr: Scalar(
418+
Initialized {
419+
value: Int(
420+
I32,
421+
false,
422+
),
423+
valid_range: (..=1) | (5..),
424+
},
425+
),
426+
fields: Primitive,
427+
largest_niche: Some(
428+
Niche {
429+
offset: Size(0 bytes),
430+
value: Int(
431+
I32,
432+
false,
433+
),
434+
valid_range: (..=1) | (5..),
435+
},
436+
),
437+
uninhabited: false,
438+
variants: Single {
439+
index: 0,
440+
},
441+
max_repr_align: None,
442+
unadjusted_abi_align: Align(4 bytes),
443+
randomization_seed: $SEED,
444+
}
445+
--> $DIR/range_patterns.rs:29:1
446+
|
447+
LL | type WRAP2 = pattern_type!(u32 is 5..2);
448+
| ^^^^^^^^^^
449+
450+
error: layout_of((i8) is -10..=10) = Layout {
451+
size: Size(1 bytes),
452+
align: AbiAndPrefAlign {
453+
abi: Align(1 bytes),
454+
pref: $SOME_ALIGN,
455+
},
456+
backend_repr: Scalar(
457+
Initialized {
458+
value: Int(
459+
I8,
460+
true,
461+
),
462+
valid_range: (..=10) | (246..),
463+
},
464+
),
465+
fields: Primitive,
466+
largest_niche: Some(
467+
Niche {
468+
offset: Size(0 bytes),
469+
value: Int(
470+
I8,
471+
true,
472+
),
473+
valid_range: (..=10) | (246..),
474+
},
475+
),
476+
uninhabited: false,
477+
variants: Single {
478+
index: 0,
479+
},
480+
max_repr_align: None,
481+
unadjusted_abi_align: Align(1 bytes),
482+
randomization_seed: $SEED,
483+
}
484+
--> $DIR/range_patterns.rs:32:1
485+
|
486+
LL | type SIGN = pattern_type!(i8 is -10..=10);
487+
| ^^^^^^^^^
488+
489+
error: layout_of((i8) is i8::MIN..=0) = Layout {
490+
size: Size(1 bytes),
491+
align: AbiAndPrefAlign {
492+
abi: Align(1 bytes),
493+
pref: $SOME_ALIGN,
494+
},
495+
backend_repr: Scalar(
496+
Initialized {
497+
value: Int(
498+
I8,
499+
true,
500+
),
501+
valid_range: (..=0) | (128..),
502+
},
503+
),
504+
fields: Primitive,
505+
largest_niche: Some(
506+
Niche {
507+
offset: Size(0 bytes),
508+
value: Int(
509+
I8,
510+
true,
511+
),
512+
valid_range: (..=0) | (128..),
513+
},
514+
),
515+
uninhabited: false,
516+
variants: Single {
517+
index: 0,
518+
},
519+
max_repr_align: None,
520+
unadjusted_abi_align: Align(1 bytes),
521+
randomization_seed: $SEED,
522+
}
523+
--> $DIR/range_patterns.rs:35:1
524+
|
525+
LL | type MIN = pattern_type!(i8 is -128..=0);
526+
| ^^^^^^^^
527+
528+
error: layout_of((i8) is 120..=-120) = Layout {
529+
size: Size(1 bytes),
530+
align: AbiAndPrefAlign {
531+
abi: Align(1 bytes),
532+
pref: $SOME_ALIGN,
533+
},
534+
backend_repr: Scalar(
535+
Initialized {
536+
value: Int(
537+
I8,
538+
true,
539+
),
540+
valid_range: 120..=136,
541+
},
542+
),
543+
fields: Primitive,
544+
largest_niche: Some(
545+
Niche {
546+
offset: Size(0 bytes),
547+
value: Int(
548+
I8,
549+
true,
550+
),
551+
valid_range: 120..=136,
552+
},
553+
),
554+
uninhabited: false,
555+
variants: Single {
556+
index: 0,
557+
},
558+
max_repr_align: None,
559+
unadjusted_abi_align: Align(1 bytes),
560+
randomization_seed: $SEED,
561+
}
562+
--> $DIR/range_patterns.rs:38:1
563+
|
564+
LL | type SignedWrap = pattern_type!(i8 is 120..=-120);
565+
| ^^^^^^^^^^^^^^^
566+
567+
error: aborting due to 12 previous errors
361568

569+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)