Skip to content

Commit 1bfe5f1

Browse files
committed
Add a non-Copy packed struct to deriving-all-codegen.rs.
Because the generatedd code is different to a `Copy` packed struct.
1 parent 292de22 commit 1bfe5f1

File tree

2 files changed

+124
-22
lines changed

2 files changed

+124
-22
lines changed

src/test/ui/deriving/deriving-all-codegen.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ struct Big {
3838
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
3939
struct Unsized([u32]);
4040

41-
// A packed tuple struct.
41+
// A packed tuple struct that impls `Copy`.
4242
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
4343
#[repr(packed)]
44-
struct Packed(u32);
44+
struct PackedCopy(u32);
45+
46+
// A packed tuple struct that does not impl `Copy`. Note that the alignment of
47+
// the field must be 1 for this code to be valid. Otherwise it triggers an
48+
// error "`#[derive]` can't be used on a `#[repr(packed)]` struct that does not
49+
// derive Copy (error E0133)" at MIR building time. This is a weird case and
50+
// it's possible that this struct is not supposed to work, but for now it does.
51+
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
52+
#[repr(packed)]
53+
struct PackedNonCopy(u8);
4554

4655
// An empty enum.
4756
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]

src/test/ui/deriving/deriving-all-codegen.stdout

Lines changed: 113 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -422,65 +422,67 @@ impl ::core::cmp::Ord for Unsized {
422422
}
423423
}
424424

425-
// A packed tuple struct.
425+
// A packed tuple struct that impls `Copy`.
426426
#[repr(packed)]
427-
struct Packed(u32);
427+
struct PackedCopy(u32);
428428
#[automatically_derived]
429429
#[allow(unused_qualifications)]
430-
impl ::core::clone::Clone for Packed {
430+
impl ::core::clone::Clone for PackedCopy {
431431
#[inline]
432-
fn clone(&self) -> Packed {
432+
fn clone(&self) -> PackedCopy {
433433
let _: ::core::clone::AssertParamIsClone<u32>;
434434
*self
435435
}
436436
}
437437
#[automatically_derived]
438438
#[allow(unused_qualifications)]
439-
impl ::core::marker::Copy for Packed { }
439+
impl ::core::marker::Copy for PackedCopy { }
440440
#[automatically_derived]
441441
#[allow(unused_qualifications)]
442-
impl ::core::fmt::Debug for Packed {
442+
impl ::core::fmt::Debug for PackedCopy {
443443
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
444444
let Self(__self_0_0) = *self;
445-
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Packed",
445+
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PackedCopy",
446446
&&__self_0_0)
447447
}
448448
}
449449
#[automatically_derived]
450450
#[allow(unused_qualifications)]
451-
impl ::core::default::Default for Packed {
451+
impl ::core::default::Default for PackedCopy {
452452
#[inline]
453-
fn default() -> Packed { Packed(::core::default::Default::default()) }
453+
fn default() -> PackedCopy {
454+
PackedCopy(::core::default::Default::default())
455+
}
454456
}
455457
#[automatically_derived]
456458
#[allow(unused_qualifications)]
457-
impl ::core::hash::Hash for Packed {
459+
impl ::core::hash::Hash for PackedCopy {
458460
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
459461
let Self(__self_0_0) = *self;
460462
::core::hash::Hash::hash(&__self_0_0, state)
461463
}
462464
}
463-
impl ::core::marker::StructuralPartialEq for Packed {}
465+
impl ::core::marker::StructuralPartialEq for PackedCopy {}
464466
#[automatically_derived]
465467
#[allow(unused_qualifications)]
466-
impl ::core::cmp::PartialEq for Packed {
468+
impl ::core::cmp::PartialEq for PackedCopy {
467469
#[inline]
468-
fn eq(&self, other: &Packed) -> bool {
470+
fn eq(&self, other: &PackedCopy) -> bool {
469471
let Self(__self_0_0) = *self;
470472
let Self(__self_1_0) = *other;
471473
__self_0_0 == __self_1_0
472474
}
473475
#[inline]
474-
fn ne(&self, other: &Packed) -> bool {
476+
fn ne(&self, other: &PackedCopy) -> bool {
475477
let Self(__self_0_0) = *self;
476478
let Self(__self_1_0) = *other;
477479
__self_0_0 != __self_1_0
478480
}
479481
}
480-
impl ::core::marker::StructuralEq for Packed {}
482+
impl ::core::marker::StructuralEq for PackedCopy {}
481483
#[automatically_derived]
482484
#[allow(unused_qualifications)]
483-
impl ::core::cmp::Eq for Packed {
485+
impl ::core::cmp::Eq for PackedCopy {
484486
#[inline]
485487
#[doc(hidden)]
486488
#[no_coverage]
@@ -490,9 +492,9 @@ impl ::core::cmp::Eq for Packed {
490492
}
491493
#[automatically_derived]
492494
#[allow(unused_qualifications)]
493-
impl ::core::cmp::PartialOrd for Packed {
495+
impl ::core::cmp::PartialOrd for PackedCopy {
494496
#[inline]
495-
fn partial_cmp(&self, other: &Packed)
497+
fn partial_cmp(&self, other: &PackedCopy)
496498
-> ::core::option::Option<::core::cmp::Ordering> {
497499
let Self(__self_0_0) = *self;
498500
let Self(__self_1_0) = *other;
@@ -501,15 +503,106 @@ impl ::core::cmp::PartialOrd for Packed {
501503
}
502504
#[automatically_derived]
503505
#[allow(unused_qualifications)]
504-
impl ::core::cmp::Ord for Packed {
506+
impl ::core::cmp::Ord for PackedCopy {
505507
#[inline]
506-
fn cmp(&self, other: &Packed) -> ::core::cmp::Ordering {
508+
fn cmp(&self, other: &PackedCopy) -> ::core::cmp::Ordering {
507509
let Self(__self_0_0) = *self;
508510
let Self(__self_1_0) = *other;
509511
::core::cmp::Ord::cmp(&__self_0_0, &__self_1_0)
510512
}
511513
}
512514

515+
// A packed tuple struct that does not impl `Copy`. Note that the alignment of
516+
// the field must be 1 for this code to be valid. Otherwise it triggers an
517+
// error "`#[derive]` can't be used on a `#[repr(packed)]` struct that does not
518+
// derive Copy (error E0133)" at MIR building time. This is a weird case and
519+
// it's possible that this struct is not supposed to work, but for now it does.
520+
#[repr(packed)]
521+
struct PackedNonCopy(u8);
522+
#[automatically_derived]
523+
#[allow(unused_qualifications)]
524+
impl ::core::clone::Clone for PackedNonCopy {
525+
#[inline]
526+
fn clone(&self) -> PackedNonCopy {
527+
let Self(ref __self_0_0) = *self;
528+
PackedNonCopy(::core::clone::Clone::clone(&*__self_0_0))
529+
}
530+
}
531+
#[automatically_derived]
532+
#[allow(unused_qualifications)]
533+
impl ::core::fmt::Debug for PackedNonCopy {
534+
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
535+
let Self(ref __self_0_0) = *self;
536+
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PackedNonCopy",
537+
&&*__self_0_0)
538+
}
539+
}
540+
#[automatically_derived]
541+
#[allow(unused_qualifications)]
542+
impl ::core::default::Default for PackedNonCopy {
543+
#[inline]
544+
fn default() -> PackedNonCopy {
545+
PackedNonCopy(::core::default::Default::default())
546+
}
547+
}
548+
#[automatically_derived]
549+
#[allow(unused_qualifications)]
550+
impl ::core::hash::Hash for PackedNonCopy {
551+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
552+
let Self(ref __self_0_0) = *self;
553+
::core::hash::Hash::hash(&*__self_0_0, state)
554+
}
555+
}
556+
impl ::core::marker::StructuralPartialEq for PackedNonCopy {}
557+
#[automatically_derived]
558+
#[allow(unused_qualifications)]
559+
impl ::core::cmp::PartialEq for PackedNonCopy {
560+
#[inline]
561+
fn eq(&self, other: &PackedNonCopy) -> bool {
562+
let Self(ref __self_0_0) = *self;
563+
let Self(ref __self_1_0) = *other;
564+
*__self_0_0 == *__self_1_0
565+
}
566+
#[inline]
567+
fn ne(&self, other: &PackedNonCopy) -> bool {
568+
let Self(ref __self_0_0) = *self;
569+
let Self(ref __self_1_0) = *other;
570+
*__self_0_0 != *__self_1_0
571+
}
572+
}
573+
impl ::core::marker::StructuralEq for PackedNonCopy {}
574+
#[automatically_derived]
575+
#[allow(unused_qualifications)]
576+
impl ::core::cmp::Eq for PackedNonCopy {
577+
#[inline]
578+
#[doc(hidden)]
579+
#[no_coverage]
580+
fn assert_receiver_is_total_eq(&self) -> () {
581+
let _: ::core::cmp::AssertParamIsEq<u8>;
582+
}
583+
}
584+
#[automatically_derived]
585+
#[allow(unused_qualifications)]
586+
impl ::core::cmp::PartialOrd for PackedNonCopy {
587+
#[inline]
588+
fn partial_cmp(&self, other: &PackedNonCopy)
589+
-> ::core::option::Option<::core::cmp::Ordering> {
590+
let Self(ref __self_0_0) = *self;
591+
let Self(ref __self_1_0) = *other;
592+
::core::cmp::PartialOrd::partial_cmp(&*__self_0_0, &*__self_1_0)
593+
}
594+
}
595+
#[automatically_derived]
596+
#[allow(unused_qualifications)]
597+
impl ::core::cmp::Ord for PackedNonCopy {
598+
#[inline]
599+
fn cmp(&self, other: &PackedNonCopy) -> ::core::cmp::Ordering {
600+
let Self(ref __self_0_0) = *self;
601+
let Self(ref __self_1_0) = *other;
602+
::core::cmp::Ord::cmp(&*__self_0_0, &*__self_1_0)
603+
}
604+
}
605+
513606
// An empty enum.
514607
enum Enum0 {}
515608
#[automatically_derived]

0 commit comments

Comments
 (0)