Skip to content

Commit 42534f5

Browse files
committed
Add some layout tests for pattern type edge cases
1 parent f9a8860 commit 42534f5

File tree

2 files changed

+224
-2
lines changed

2 files changed

+224
-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

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

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

0 commit comments

Comments
 (0)