@@ -171,9 +171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171171 PatKind :: TupleStruct ( ref qpath, subpats, ddpos) => {
172172 self . check_pat_tuple_struct ( pat, qpath, subpats, ddpos, expected, def_bm, ti)
173173 }
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) ,
177175 PatKind :: Struct ( ref qpath, fields, etc) => {
178176 self . check_pat_struct ( pat, qpath, fields, etc, expected, def_bm, ti)
179177 }
@@ -694,7 +692,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
694692 & self ,
695693 pat : & Pat < ' _ > ,
696694 path_resolution : ( Res , Option < Ty < ' tcx > > , & ' b [ hir:: PathSegment < ' b > ] ) ,
697- qpath : & hir:: QPath < ' _ > ,
698695 expected : Ty < ' tcx > ,
699696 ti : TopInfo < ' tcx > ,
700697 ) -> Ty < ' tcx > {
@@ -707,17 +704,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
707704 self . set_tainted_by_errors ( ) ;
708705 return tcx. types . err ;
709706 }
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 ) ;
714709 return tcx. types . err ;
715710 }
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
721719 _ => bug ! ( "unexpected pattern resolution: {:?}" , res) ,
722720 }
723721
@@ -791,14 +789,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
791789 }
792790 } ;
793791 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( ) ) ) ;
794796 let msg = format ! (
795- "expected tuple struct or tuple variant, found {} `{}` " ,
797+ "expected tuple struct or tuple variant, found {}{} " ,
796798 res. descr( ) ,
797- rustc_hir_pretty :: to_string ( & tcx . hir ( ) , |s| s . print_qpath ( qpath , false ) ) ,
799+ path_str
798800 ) ;
801+
799802 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 , _) => {
802805 err. span_label ( pat. span , "`fn` calls are not allowed in patterns" ) ;
803806 err. help (
804807 "for more information, visit \
0 commit comments