@@ -3691,3 +3691,268 @@ LL | | bar
3691
3691
let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
3692
3692
assert_data_eq ! ( renderer. render( input) , expected. raw( ) ) ;
3693
3693
}
3694
+
3695
+ #[ test]
3696
+ fn origin_path_repeated ( ) {
3697
+ // tests/ui/pattern/usefulness/match-privately-empty.rs
3698
+ let source = r#"//@ revisions: normal exhaustive_patterns
3699
+ #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))]
3700
+ #![feature(never_type)]
3701
+
3702
+ mod private {
3703
+ pub struct Private {
3704
+ _bot: !,
3705
+ pub misc: bool,
3706
+ }
3707
+ pub const DATA: Option<Private> = None;
3708
+ }
3709
+
3710
+ fn main() {
3711
+ match private::DATA {
3712
+ //~^ ERROR non-exhaustive patterns: `Some(Private { misc: true, .. })` not covered
3713
+ None => {}
3714
+ Some(private::Private { misc: false, .. }) => {}
3715
+ }
3716
+ }
3717
+ "# ;
3718
+ let title_0 = "non-exhaustive patterns: `Some(Private { misc: true, .. })` not covered" ;
3719
+ let title_1 = "`Option<Private>` defined here" ;
3720
+ let title_2 = "ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown" ;
3721
+
3722
+ let input = & [
3723
+ Group :: with_title ( Level :: ERROR . title ( title_0) . id ( "E0004" ) ) . element (
3724
+ Snippet :: source ( source)
3725
+ . path ( "$DIR/match-privately-empty.rs" )
3726
+ . annotation (
3727
+ AnnotationKind :: Primary
3728
+ . span ( 286 ..299 )
3729
+ . label ( "pattern `Some(Private { misc: true, .. })` not covered" ) ,
3730
+ ) ,
3731
+ ) ,
3732
+ Group :: with_title ( Level :: NOTE . title ( title_1) )
3733
+ . element (
3734
+ Origin :: path ( "$SRC_DIR/core/src/option.rs" )
3735
+ . line ( 593 )
3736
+ . char_column ( 0 )
3737
+ . primary ( true ) ,
3738
+ )
3739
+ . element (
3740
+ Origin :: path ( "$SRC_DIR/core/src/option.rs" )
3741
+ . line ( 601 )
3742
+ . char_column ( 4 ) ,
3743
+ )
3744
+ . element ( Padding )
3745
+ . element ( Level :: NOTE . message ( "not covered" ) )
3746
+ . element ( Level :: NOTE . message ( "the matched value is of type `Option<Private>`" ) ) ,
3747
+ Group :: with_title ( Level :: HELP . title ( title_2) ) . element (
3748
+ Snippet :: source ( source)
3749
+ . path ( "$DIR/match-privately-empty.rs" )
3750
+ . line_start ( 17 )
3751
+ . fold ( true )
3752
+ . patch ( Patch :: new (
3753
+ 468 ..468 ,
3754
+ ",
3755
+ Some(Private { misc: true, .. }) => todo!()" ,
3756
+ ) ) ,
3757
+ ) ,
3758
+ ] ;
3759
+ let expected = str![ [ r#"
3760
+ error[E0004]: non-exhaustive patterns: `Some(Private { misc: true, .. })` not covered
3761
+ ╭▸ $DIR/match-privately-empty.rs:14:11
3762
+ │
3763
+ LL │ match private::DATA {
3764
+ │ ━━━━━━━━━━━━━ pattern `Some(Private { misc: true, .. })` not covered
3765
+ ╰╴
3766
+ note: `Option<Private>` defined here
3767
+ ╭▸ $SRC_DIR/core/src/option.rs:593:0
3768
+ ⸬ $SRC_DIR/core/src/option.rs:601:4
3769
+ │
3770
+ ├ note: not covered
3771
+ ╰ note: the matched value is of type `Option<Private>`
3772
+ help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
3773
+ ╭╴
3774
+ LL ± Some(private::Private { misc: false, .. }) => {},
3775
+ LL + Some(Private { misc: true, .. }) => todo!()
3776
+ ╰╴
3777
+ "# ] ] ;
3778
+ let renderer = Renderer :: plain ( )
3779
+ . anonymized_line_numbers ( true )
3780
+ . theme ( OutputTheme :: Unicode ) ;
3781
+ assert_data_eq ! ( renderer. render( input) , expected) ;
3782
+ }
3783
+
3784
+ #[ test]
3785
+ fn origin_path_repeated_element_between ( ) {
3786
+ // tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.rs
3787
+ let source = r#"//@ revisions: old new
3788
+ //@[old] edition:2015
3789
+ //@[new] edition:2021
3790
+ //@[new] run-rustfix
3791
+ #![deny(bare_trait_objects)]
3792
+ fn ord_prefer_dot(s: String) -> Ord {
3793
+ //[new]~^ ERROR expected a type, found a trait
3794
+ //[old]~^^ ERROR the trait `Ord` is not dyn compatible
3795
+ //[old]~| ERROR trait objects without an explicit `dyn` are deprecated
3796
+ //[old]~| WARNING this is accepted in the current edition (Rust 2015)
3797
+ (s.starts_with("."), s)
3798
+ }
3799
+ fn main() {
3800
+ let _ = ord_prefer_dot(String::new());
3801
+ }
3802
+ "# ;
3803
+ let title_0 = "for a trait to be dyn compatible it needs to allow building a vtable
3804
+ for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>" ;
3805
+
3806
+ let input = & [
3807
+ Group :: with_title (
3808
+ Level :: ERROR
3809
+ . title ( "the trait `Ord` is not dyn compatible" )
3810
+ . id ( "E0038" ) ,
3811
+ )
3812
+ . element (
3813
+ Snippet :: source ( source)
3814
+ . path ( "$DIR/bare-trait-dont-suggest-dyn.rs" )
3815
+ . annotation (
3816
+ AnnotationKind :: Primary
3817
+ . span ( 149 ..152 )
3818
+ . label ( "`Ord` is not dyn compatible" ) ,
3819
+ ) ,
3820
+ ) ,
3821
+ Group :: with_title ( Level :: NOTE . title ( title_0) )
3822
+ . element (
3823
+ Origin :: path ( "$SRC_DIR/core/src/cmp.rs" )
3824
+ . line ( 961 )
3825
+ . char_column ( 20 )
3826
+ . primary ( true ) ,
3827
+ )
3828
+ . element ( Padding )
3829
+ . element ( Level :: NOTE . message (
3830
+ "the trait is not dyn compatible because it uses `Self` as a type parameter" ,
3831
+ ) )
3832
+ . element (
3833
+ Origin :: path ( "$SRC_DIR/core/src/cmp.rs" )
3834
+ . line ( 338 )
3835
+ . char_column ( 14 ) ,
3836
+ )
3837
+ . element ( Padding )
3838
+ . element ( Level :: NOTE . message (
3839
+ "the trait is not dyn compatible because it uses `Self` as a type parameter" ,
3840
+ ) ) ,
3841
+ Group :: with_title ( Level :: HELP . title ( "consider using an opaque type instead" ) ) . element (
3842
+ Snippet :: source ( source)
3843
+ . path ( "$DIR/bare-trait-dont-suggest-dyn.rs" )
3844
+ . line_start ( 6 )
3845
+ . fold ( true )
3846
+ . patch ( Patch :: new ( 149 ..149 , "impl " ) ) ,
3847
+ ) ,
3848
+ ] ;
3849
+ let expected = str![ [ r#"
3850
+ error[E0038]: the trait `Ord` is not dyn compatible
3851
+ ╭▸ $DIR/bare-trait-dont-suggest-dyn.rs:6:33
3852
+ │
3853
+ LL │ fn ord_prefer_dot(s: String) -> Ord {
3854
+ │ ━━━ `Ord` is not dyn compatible
3855
+ ╰╴
3856
+ note: for a trait to be dyn compatible it needs to allow building a vtable
3857
+ for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
3858
+ ╭▸ $SRC_DIR/core/src/cmp.rs:961:20
3859
+ │
3860
+ ╰ note: the trait is not dyn compatible because it uses `Self` as a type parameter
3861
+ ⸬ $SRC_DIR/core/src/cmp.rs:338:14
3862
+ │
3863
+ ╰ note: the trait is not dyn compatible because it uses `Self` as a type parameter
3864
+ help: consider using an opaque type instead
3865
+ ╭╴
3866
+ LL │ fn ord_prefer_dot(s: String) -> impl Ord {
3867
+ ╰╴ ++++
3868
+ "# ] ] ;
3869
+ let renderer = Renderer :: plain ( )
3870
+ . anonymized_line_numbers ( true )
3871
+ . theme ( OutputTheme :: Unicode ) ;
3872
+ assert_data_eq ! ( renderer. render( input) , expected) ;
3873
+ }
3874
+
3875
+ #[ test]
3876
+ fn multiple_origin ( ) {
3877
+ // tests/ui/binop/binary-op-not-allowed-issue-125631.rs
3878
+ let source_0 = r#"use std::io::{Error, ErrorKind};
3879
+ use std::thread;
3880
+
3881
+ struct T1;
3882
+ struct T2;
3883
+
3884
+ fn main() {
3885
+ (Error::new(ErrorKind::Other, "1"), T1, 1) == (Error::new(ErrorKind::Other, "1"), T1, 2);
3886
+ //~^ERROR binary operation `==` cannot be applied to type
3887
+ (Error::new(ErrorKind::Other, "2"), thread::current())
3888
+ == (Error::new(ErrorKind::Other, "2"), thread::current());
3889
+ //~^ERROR binary operation `==` cannot be applied to type
3890
+ (Error::new(ErrorKind::Other, "4"), thread::current(), T1, T2)
3891
+ == (Error::new(ErrorKind::Other, "4"), thread::current(), T1, T2);
3892
+ //~^ERROR binary operation `==` cannot be applied to type
3893
+ }
3894
+ "# ;
3895
+ let title_0 =
3896
+ "the foreign item types don't implement required traits for this operation to be valid" ;
3897
+
3898
+ let input = & [
3899
+ Group :: with_title (
3900
+ Level :: ERROR
3901
+ . title ( "binary operation `==` cannot be applied to type `(std::io::Error, Thread)`" )
3902
+ . id ( "E0369" ) ,
3903
+ )
3904
+ . element (
3905
+ Snippet :: source ( source_0)
3906
+ . path ( "$DIR/binary-op-not-allowed-issue-125631.rs" )
3907
+ . annotation (
3908
+ AnnotationKind :: Context
3909
+ . span ( 246 ..300 )
3910
+ . label ( "(std::io::Error, Thread)" ) ,
3911
+ )
3912
+ . annotation (
3913
+ AnnotationKind :: Context
3914
+ . span ( 312 ..366 )
3915
+ . label ( "(std::io::Error, Thread)" ) ,
3916
+ )
3917
+ . annotation ( AnnotationKind :: Primary . span ( 309 ..311 ) ) ,
3918
+ ) ,
3919
+ Group :: with_title ( Level :: NOTE . title ( title_0) )
3920
+ . element (
3921
+ Origin :: path ( "$SRC_DIR/std/src/io/error.rs" )
3922
+ . line ( 65 )
3923
+ . char_column ( 0 )
3924
+ . primary ( true ) ,
3925
+ )
3926
+ . element ( Padding )
3927
+ . element ( Level :: NOTE . message ( "not implement `PartialEq`" ) )
3928
+ . element (
3929
+ Origin :: path ( "$SRC_DIR/std/src/thread/mod.rs" )
3930
+ . line ( 1439 )
3931
+ . char_column ( 0 )
3932
+ . primary ( true ) ,
3933
+ )
3934
+ . element ( Padding )
3935
+ . element ( Level :: NOTE . message ( "not implement `PartialEq`" ) ) ,
3936
+ ] ;
3937
+ let expected = str![ [ r#"
3938
+ error[E0369]: binary operation `==` cannot be applied to type `(std::io::Error, Thread)`
3939
+ ╭▸ $DIR/binary-op-not-allowed-issue-125631.rs:11:9
3940
+ │
3941
+ LL │ (Error::new(ErrorKind::Other, "2"), thread::current())
3942
+ │ ────────────────────────────────────────────────────── (std::io::Error, Thread)
3943
+ LL │ == (Error::new(ErrorKind::Other, "2"), thread::current());
3944
+ │ ━━ ────────────────────────────────────────────────────── (std::io::Error, Thread)
3945
+ ╰╴
3946
+ note: the foreign item types don't implement required traits for this operation to be valid
3947
+ ╭▸ $SRC_DIR/std/src/io/error.rs:65:0
3948
+ │
3949
+ ╰ note: not implement `PartialEq`
3950
+ ╭▸ $SRC_DIR/std/src/thread/mod.rs:1439:0
3951
+ │
3952
+ ╰ note: not implement `PartialEq`
3953
+ "# ] ] ;
3954
+ let renderer = Renderer :: plain ( )
3955
+ . anonymized_line_numbers ( true )
3956
+ . theme ( OutputTheme :: Unicode ) ;
3957
+ assert_data_eq ! ( renderer. render( input) , expected) ;
3958
+ }
0 commit comments