@@ -9,7 +9,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
99use rustc_hir:: { HirId , Pat , PatKind } ;
1010use rustc_infer:: infer;
1111use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
12- use rustc_infer:: traits:: Pattern ;
12+ use rustc_infer:: traits:: { ObligationCause , Pattern } ;
1313use rustc_span:: hygiene:: DesugaringKind ;
1414use rustc_span:: source_map:: { Span , Spanned } ;
1515use syntax:: ast;
@@ -66,16 +66,19 @@ struct TopInfo<'tcx> {
6666}
6767
6868impl < ' tcx > FnCtxt < ' _ , ' tcx > {
69+ fn pattern_cause ( & self , ti : TopInfo < ' tcx > , cause_span : Span ) -> ObligationCause < ' tcx > {
70+ let code = Pattern { span : ti. span , root_ty : ti. expected , origin_expr : ti. origin_expr } ;
71+ self . cause ( cause_span, code)
72+ }
73+
6974 fn demand_eqtype_pat_diag (
7075 & self ,
7176 cause_span : Span ,
7277 expected : Ty < ' tcx > ,
7378 actual : Ty < ' tcx > ,
7479 ti : TopInfo < ' tcx > ,
7580 ) -> Option < DiagnosticBuilder < ' tcx > > {
76- let code = Pattern { span : ti. span , root_ty : ti. expected , origin_expr : ti. origin_expr } ;
77- let cause = self . cause ( cause_span, code) ;
78- self . demand_eqtype_with_origin ( & cause, expected, actual)
81+ self . demand_eqtype_with_origin ( & self . pattern_cause ( ti, cause_span) , expected, actual)
7982 }
8083
8184 fn demand_eqtype_pat (
@@ -379,7 +382,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
379382 // &'static str <: expected
380383 //
381384 // then that's equivalent to there existing a LUB.
382- if let Some ( mut err) = self . demand_suptype_diag ( span, expected, pat_ty) {
385+ let cause = self . pattern_cause ( ti, span) ;
386+ if let Some ( mut err) = self . demand_suptype_with_origin ( & cause, expected, pat_ty) {
383387 err. emit_unless (
384388 ti. span
385389 . filter ( |& s| {
0 commit comments