@@ -155,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
155155 self . check_pat_tuple_struct ( pat, qpath, subpats, ddpos, expected, def_bm, ti)
156156 }
157157 PatKind :: Path ( ref qpath) => {
158- self . check_pat_path ( pat, path_res. unwrap ( ) , qpath, expected)
158+ self . check_pat_path ( pat, path_res. unwrap ( ) , qpath, expected, ti )
159159 }
160160 PatKind :: Struct ( ref qpath, fields, etc) => {
161161 self . check_pat_struct ( pat, qpath, fields, etc, expected, def_bm, ti)
@@ -671,6 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
671671 path_resolution : ( Res , Option < Ty < ' tcx > > , & ' b [ hir:: PathSegment < ' b > ] ) ,
672672 qpath : & hir:: QPath < ' _ > ,
673673 expected : Ty < ' tcx > ,
674+ ti : TopInfo < ' tcx > ,
674675 ) -> Ty < ' tcx > {
675676 let tcx = self . tcx ;
676677
@@ -696,7 +697,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
696697
697698 // Type-check the path.
698699 let pat_ty = self . instantiate_value_path ( segments, opt_ty, res, pat. span , pat. hir_id ) . 0 ;
699- self . demand_suptype ( pat. span , expected, pat_ty) ;
700+ if let Some ( mut err) =
701+ self . demand_suptype_with_origin ( & self . pattern_cause ( ti, pat. span ) , expected, pat_ty)
702+ {
703+ err. emit ( ) ;
704+ }
700705 pat_ty
701706 }
702707
0 commit comments