2
2
3
3
use expect_test:: expect;
4
4
5
- use crate :: macro_expansion_tests:: check;
5
+ use crate :: macro_expansion_tests:: { check, check_errors } ;
6
6
7
7
#[ test]
8
8
fn test_copy_expand_simple ( ) {
@@ -16,7 +16,7 @@ struct Foo;
16
16
#[derive(Copy)]
17
17
struct Foo;
18
18
19
- impl < > $crate::marker::Copy for Foo< > where {}"# ] ] ,
19
+ impl <> $crate::marker::Copy for Foo< > where {}"# ] ] ,
20
20
) ;
21
21
}
22
22
@@ -40,7 +40,7 @@ macro Copy {}
40
40
#[derive(Copy)]
41
41
struct Foo;
42
42
43
- impl < > $crate::marker::Copy for Foo< > where {}"# ] ] ,
43
+ impl <> $crate::marker::Copy for Foo< > where {}"# ] ] ,
44
44
) ;
45
45
}
46
46
@@ -225,14 +225,14 @@ enum Bar {
225
225
Bar,
226
226
}
227
227
228
- impl < > $crate::default::Default for Foo< > where {
228
+ impl <> $crate::default::Default for Foo< > where {
229
229
fn default() -> Self {
230
230
Foo {
231
231
field1: $crate::default::Default::default(), field2: $crate::default::Default::default(),
232
232
}
233
233
}
234
234
}
235
- impl < > $crate::default::Default for Bar< > where {
235
+ impl <> $crate::default::Default for Bar< > where {
236
236
fn default() -> Self {
237
237
Bar::Bar
238
238
}
@@ -260,7 +260,7 @@ enum Command {
260
260
Jump,
261
261
}
262
262
263
- impl < > $crate::cmp::PartialEq for Command< > where {
263
+ impl <> $crate::cmp::PartialEq for Command< > where {
264
264
fn eq(&self , other: &Self ) -> bool {
265
265
match (self , other) {
266
266
(Command::Move {
@@ -273,7 +273,7 @@ impl < > $crate::cmp::PartialEq for Command< > where {
273
273
}
274
274
}
275
275
}
276
- impl < > $crate::cmp::Eq for Command< > where {}"# ] ] ,
276
+ impl <> $crate::cmp::Eq for Command< > where {}"# ] ] ,
277
277
) ;
278
278
}
279
279
@@ -298,7 +298,7 @@ enum Command {
298
298
Jump,
299
299
}
300
300
301
- impl < > $crate::cmp::PartialEq for Command< > where {
301
+ impl <> $crate::cmp::PartialEq for Command< > where {
302
302
fn eq(&self , other: &Self ) -> bool {
303
303
match (self , other) {
304
304
(Command::Move {
@@ -311,7 +311,7 @@ impl < > $crate::cmp::PartialEq for Command< > where {
311
311
}
312
312
}
313
313
}
314
- impl < > $crate::cmp::Eq for Command< > where {}"# ] ] ,
314
+ impl <> $crate::cmp::Eq for Command< > where {}"# ] ] ,
315
315
) ;
316
316
}
317
317
@@ -335,7 +335,7 @@ enum Command {
335
335
Jump,
336
336
}
337
337
338
- impl < > $crate::cmp::PartialOrd for Command< > where {
338
+ impl <> $crate::cmp::PartialOrd for Command< > where {
339
339
fn partial_cmp(&self , other: &Self ) -> $crate::option::Option::Option<$crate::cmp::Ordering> {
340
340
match $crate::intrinsics::discriminant_value(self ).partial_cmp(&$crate::intrinsics::discriminant_value(other)) {
341
341
$crate::option::Option::Some($crate::cmp::Ordering::Equal)=> {
@@ -370,7 +370,7 @@ impl < > $crate::cmp::PartialOrd for Command< > where {
370
370
}
371
371
}
372
372
}
373
- impl < > $crate::cmp::Ord for Command< > where {
373
+ impl <> $crate::cmp::Ord for Command< > where {
374
374
fn cmp(&self , other: &Self ) -> $crate::cmp::Ordering {
375
375
match $crate::intrinsics::discriminant_value(self ).cmp(&$crate::intrinsics::discriminant_value(other)) {
376
376
$crate::cmp::Ordering::Equal=> {
@@ -432,7 +432,7 @@ struct Foo {
432
432
z: (i32, u64),
433
433
}
434
434
435
- impl < > $crate::hash::Hash for Foo< > where {
435
+ impl <> $crate::hash::Hash for Foo< > where {
436
436
fn hash<H: $crate::hash::Hasher>(&self , ra_expand_state: &mut H) {
437
437
match self {
438
438
Foo {
@@ -470,7 +470,7 @@ enum Command {
470
470
Jump,
471
471
}
472
472
473
- impl < > $crate::hash::Hash for Command< > where {
473
+ impl <> $crate::hash::Hash for Command< > where {
474
474
fn hash<H: $crate::hash::Hasher>(&self , ra_expand_state: &mut H) {
475
475
$crate::mem::discriminant(self ).hash(ra_expand_state);
476
476
match self {
@@ -516,7 +516,7 @@ enum Command {
516
516
Jump,
517
517
}
518
518
519
- impl < > $crate::fmt::Debug for Command< > where {
519
+ impl <> $crate::fmt::Debug for Command< > where {
520
520
fn fmt(&self , f: &mut $crate::fmt::Formatter) -> $crate::fmt::Result {
521
521
match self {
522
522
Command::Move {
@@ -578,7 +578,7 @@ enum HideAndShowEnum {
578
578
}
579
579
}
580
580
581
- impl < > $crate::fmt::Debug for HideAndShow< > where {
581
+ impl <> $crate::fmt::Debug for HideAndShow< > where {
582
582
fn fmt(&self , f: &mut $crate::fmt::Formatter) -> $crate::fmt::Result {
583
583
match self {
584
584
HideAndShow {
@@ -588,7 +588,7 @@ impl < > $crate::fmt::Debug for HideAndShow< > where {
588
588
}
589
589
}
590
590
}
591
- impl < > $crate::fmt::Debug for HideAndShowEnum< > where {
591
+ impl <> $crate::fmt::Debug for HideAndShowEnum< > where {
592
592
fn fmt(&self , f: &mut $crate::fmt::Formatter) -> $crate::fmt::Result {
593
593
match self {
594
594
HideAndShowEnum::AlwaysShow {
@@ -640,17 +640,109 @@ enum Bar {
640
640
Bar,
641
641
}
642
642
643
- impl < > $crate::default::Default for Foo< > where {
643
+ impl <> $crate::default::Default for Foo< > where {
644
644
fn default() -> Self {
645
645
Foo {
646
646
field1: $crate::default::Default::default(), field4: $crate::default::Default::default(),
647
647
}
648
648
}
649
649
}
650
- impl < > $crate::default::Default for Bar< > where {
650
+ impl <> $crate::default::Default for Bar< > where {
651
651
fn default() -> Self {
652
652
Bar::Bar
653
653
}
654
654
}"## ] ] ,
655
655
) ;
656
656
}
657
+
658
+ #[ test]
659
+ fn coerce_pointee_expansion ( ) {
660
+ check (
661
+ r#"
662
+ //- minicore: coerce_pointee
663
+
664
+ use core::marker::CoercePointee;
665
+
666
+ pub trait Trait<T: ?Sized> {}
667
+
668
+ #[derive(CoercePointee)]
669
+ #[repr(transparent)]
670
+ pub struct Foo<'a, T: ?Sized + Trait<U>, #[pointee] U: ?Sized, const N: u32>(T)
671
+ where
672
+ U: Trait<U> + ToString;"# ,
673
+ expect ! [ [ r#"
674
+
675
+ use core::marker::CoercePointee;
676
+
677
+ pub trait Trait<T: ?Sized> {}
678
+
679
+ #[derive(CoercePointee)]
680
+ #[repr(transparent)]
681
+ pub struct Foo<'a, T: ?Sized + Trait<U>, #[pointee] U: ?Sized, const N: u32>(T)
682
+ where
683
+ U: Trait<U> + ToString;
684
+ impl <T, U, const N: u32, __S> $crate::ops::DispatchFromDyn<Foo<'a, T, __S, N>> for Foo<T, U, N, > where U: Trait<U> +ToString, T: Trait<__S>, __S: ?Sized, __S: Trait<__S> +ToString, U: ::core::marker::Unsize<__S>, T:?Sized+Trait<U>, U:?Sized, {}
685
+ impl <T, U, const N: u32, __S> $crate::ops::CoerceUnsized<Foo<'a, T, __S, N>> for Foo<T, U, N, > where U: Trait<U> +ToString, T: Trait<__S>, __S: ?Sized, __S: Trait<__S> +ToString, U: ::core::marker::Unsize<__S>, T:?Sized+Trait<U>, U:?Sized, {}"# ] ] ,
686
+ ) ;
687
+ }
688
+
689
+ #[ test]
690
+ fn coerce_pointee_errors ( ) {
691
+ check_errors (
692
+ r#"
693
+ //- minicore: coerce_pointee
694
+
695
+ use core::marker::CoercePointee;
696
+
697
+ #[derive(CoercePointee)]
698
+ enum Enum {}
699
+
700
+ #[derive(CoercePointee)]
701
+ struct Struct1;
702
+
703
+ #[derive(CoercePointee)]
704
+ struct Struct2();
705
+
706
+ #[derive(CoercePointee)]
707
+ struct Struct3 {}
708
+
709
+ #[derive(CoercePointee)]
710
+ struct Struct4<T: ?Sized>(T);
711
+
712
+ #[derive(CoercePointee)]
713
+ #[repr(transparent)]
714
+ struct Struct5(i32);
715
+
716
+ #[derive(CoercePointee)]
717
+ #[repr(transparent)]
718
+ struct Struct6<#[pointee] T: ?Sized, #[pointee] U: ?Sized>(T, U);
719
+
720
+ #[derive(CoercePointee)]
721
+ #[repr(transparent)]
722
+ struct Struct7<T: ?Sized, U: ?Sized>(T, U);
723
+
724
+ #[derive(CoercePointee)]
725
+ #[repr(transparent)]
726
+ struct Struct8<#[pointee] T, U: ?Sized>(T);
727
+
728
+ #[derive(CoercePointee)]
729
+ #[repr(transparent)]
730
+ struct Struct9<T>(T);
731
+
732
+ #[derive(CoercePointee)]
733
+ #[repr(transparent)]
734
+ struct Struct9<#[pointee] T, U>(T) where T: ?Sized;
735
+ "# ,
736
+ expect ! [ [ r#"
737
+ 35..72: `CoercePointee` can only be derived on `struct`s
738
+ 74..114: `CoercePointee` can only be derived on `struct`s with at least one field
739
+ 116..158: `CoercePointee` can only be derived on `struct`s with at least one field
740
+ 160..202: `CoercePointee` can only be derived on `struct`s with at least one field
741
+ 204..258: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`
742
+ 260..326: `CoercePointee` can only be derived on `struct`s that are generic over at least one type
743
+ 328..439: only one type parameter can be marked as `#[pointee]` when deriving `CoercePointee` traits
744
+ 441..530: exactly one generic type parameter must be marked as `#[pointee]` to derive `CoercePointee` traits
745
+ 532..621: `derive(CoercePointee)` requires `T` to be marked `?Sized`
746
+ 623..690: `derive(CoercePointee)` requires `T` to be marked `?Sized`"# ] ] ,
747
+ ) ;
748
+ }
0 commit comments