@@ -171,9 +171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171
171
PatKind :: TupleStruct ( ref qpath, subpats, ddpos) => {
172
172
self . check_pat_tuple_struct ( pat, qpath, subpats, ddpos, expected, def_bm, ti)
173
173
}
174
- PatKind :: Path ( ref qpath) => {
175
- self . check_pat_path ( pat, path_res. unwrap ( ) , qpath, expected, ti)
176
- }
174
+ PatKind :: Path ( _) => self . check_pat_path ( pat, path_res. unwrap ( ) , expected, ti) ,
177
175
PatKind :: Struct ( ref qpath, fields, etc) => {
178
176
self . check_pat_struct ( pat, qpath, fields, etc, expected, def_bm, ti)
179
177
}
@@ -694,7 +692,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
694
692
& self ,
695
693
pat : & Pat < ' _ > ,
696
694
path_resolution : ( Res , Option < Ty < ' tcx > > , & ' b [ hir:: PathSegment < ' b > ] ) ,
697
- qpath : & hir:: QPath < ' _ > ,
698
695
expected : Ty < ' tcx > ,
699
696
ti : TopInfo < ' tcx > ,
700
697
) -> Ty < ' tcx > {
@@ -707,17 +704,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
707
704
self . set_tainted_by_errors ( ) ;
708
705
return tcx. types . err ;
709
706
}
710
- Res :: Def ( DefKind :: AssocFn , _)
711
- | Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fictive ) , _)
712
- | Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , _) => {
713
- report_unexpected_variant_res ( tcx, res, pat. span , qpath) ;
707
+ Res :: Def ( DefKind :: AssocFn | DefKind :: Ctor ( _, CtorKind :: Fictive | CtorKind :: Fn ) , _) => {
708
+ report_unexpected_variant_res ( tcx, res, pat. span ) ;
714
709
return tcx. types . err ;
715
710
}
716
- Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Const ) , _)
717
- | Res :: SelfCtor ( ..)
718
- | Res :: Def ( DefKind :: Const , _)
719
- | Res :: Def ( DefKind :: AssocConst , _)
720
- | Res :: Def ( DefKind :: ConstParam , _) => { } // OK
711
+ Res :: SelfCtor ( ..)
712
+ | Res :: Def (
713
+ DefKind :: Ctor ( _, CtorKind :: Const )
714
+ | DefKind :: Const
715
+ | DefKind :: AssocConst
716
+ | DefKind :: ConstParam ,
717
+ _,
718
+ ) => { } // OK
721
719
_ => bug ! ( "unexpected pattern resolution: {:?}" , res) ,
722
720
}
723
721
@@ -791,14 +789,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
791
789
}
792
790
} ;
793
791
let report_unexpected_res = |res : Res | {
792
+ let sm = tcx. sess . source_map ( ) ;
793
+ let path_str = sm
794
+ . span_to_snippet ( sm. span_until_char ( pat. span , '(' ) )
795
+ . map_or ( String :: new ( ) , |s| format ! ( " `{}`" , s. trim_end( ) ) ) ;
794
796
let msg = format ! (
795
- "expected tuple struct or tuple variant, found {} `{}` " ,
797
+ "expected tuple struct or tuple variant, found {}{} " ,
796
798
res. descr( ) ,
797
- rustc_hir_pretty :: to_string ( & tcx . hir ( ) , |s| s . print_qpath ( qpath , false ) ) ,
799
+ path_str
798
800
) ;
801
+
799
802
let mut err = struct_span_err ! ( tcx. sess, pat. span, E0164 , "{}" , msg) ;
800
- match ( res, & pat . kind ) {
801
- ( Res :: Def ( DefKind :: Fn , _ ) , _ ) | ( Res :: Def ( DefKind :: AssocFn , _ ) , _) => {
803
+ match res {
804
+ Res :: Def ( DefKind :: Fn | DefKind :: AssocFn , _) => {
802
805
err. span_label ( pat. span , "`fn` calls are not allowed in patterns" ) ;
803
806
err. help (
804
807
"for more information, visit \
0 commit comments