@@ -46,7 +46,7 @@ struct TopInfo<'tcx> {
4646 /// Was the origin of the `span` from a scrutinee expression?
4747 ///
4848 /// Otherwise there is no scrutinee and it could be e.g. from the type of a formal parameter.
49- origin_expr : bool ,
49+ origin_expr : Option < & ' tcx hir :: Expr < ' tcx > > ,
5050 /// The span giving rise to the `expected` type, if one could be provided.
5151 ///
5252 /// If `origin_expr` is `true`, then this is the span of the scrutinee as in:
@@ -74,7 +74,8 @@ struct TopInfo<'tcx> {
7474
7575impl < ' tcx > FnCtxt < ' _ , ' tcx > {
7676 fn pattern_cause ( & self , ti : TopInfo < ' tcx > , cause_span : Span ) -> ObligationCause < ' tcx > {
77- let code = Pattern { span : ti. span , root_ty : ti. expected , origin_expr : ti. origin_expr } ;
77+ let code =
78+ Pattern { span : ti. span , root_ty : ti. expected , origin_expr : ti. origin_expr . is_some ( ) } ;
7879 self . cause ( cause_span, code)
7980 }
8081
@@ -85,7 +86,14 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
8586 actual : Ty < ' tcx > ,
8687 ti : TopInfo < ' tcx > ,
8788 ) -> Option < DiagnosticBuilder < ' tcx , ErrorGuaranteed > > {
88- self . demand_eqtype_with_origin ( & self . pattern_cause ( ti, cause_span) , expected, actual)
89+ let mut diag =
90+ self . demand_eqtype_with_origin ( & self . pattern_cause ( ti, cause_span) , expected, actual) ?;
91+ if let Some ( expr) = ti. origin_expr {
92+ self . suggest_fn_call ( & mut diag, expr, expected, |output| {
93+ self . can_eq ( self . param_env , output, actual) . is_ok ( )
94+ } ) ;
95+ }
96+ Some ( diag)
8997 }
9098
9199 fn demand_eqtype_pat (
@@ -127,7 +135,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
127135 pat : & ' tcx Pat < ' tcx > ,
128136 expected : Ty < ' tcx > ,
129137 span : Option < Span > ,
130- origin_expr : bool ,
138+ origin_expr : Option < & ' tcx hir :: Expr < ' tcx > > ,
131139 ) {
132140 let info = TopInfo { expected, origin_expr, span } ;
133141 self . check_pat ( pat, expected, INITIAL_BM , info) ;
@@ -2146,7 +2154,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21462154 err. help ( "the semantics of slice patterns changed recently; see issue #62254" ) ;
21472155 } else if self . autoderef ( span, expected_ty)
21482156 . any ( |( ty, _) | matches ! ( ty. kind( ) , ty:: Slice ( ..) | ty:: Array ( ..) ) )
2149- && let ( Some ( span) , true ) = ( ti. span , ti. origin_expr )
2157+ && let Some ( span) = ti. span
2158+ && let Some ( _) = ti. origin_expr
21502159 && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
21512160 {
21522161 let ty = self . resolve_vars_if_possible ( ti. expected ) ;
0 commit comments