@@ -1034,31 +1034,35 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10341034 // For each method in the chain, see if this is `Result::map_err` or
10351035 // `Option::ok_or_else` and if it is, see if the closure passed to it has an incorrect
10361036 // trailing `;`.
1037- // Ideally we would instead use `FnCtxt::lookup_method_for_diagnostic` for 100%
1038- // accurate check, but we are in the wrong stage to do that and looking for
1039- // `Result::map_err` by checking the Self type and the path segment is enough.
1040- // sym::ok_or_else
10411037 if let Some ( ty) = get_e_type ( prev_ty)
10421038 && let Some ( found_ty) = found_ty
1039+ // Ideally we would instead use `FnCtxt::lookup_method_for_diagnostic` for 100%
1040+ // accurate check, but we are in the wrong stage to do that and looking for
1041+ // `Result::map_err` by checking the Self type and the path segment is enough.
1042+ // sym::ok_or_else
10431043 && (
1044- (
1044+ ( // Result::map_err
10451045 path_segment. ident . name == sym:: map_err
10461046 && is_diagnostic_item ( sym:: Result , next_ty)
1047- ) || (
1047+ ) || ( // Option::ok_or_else
10481048 path_segment. ident . name == sym:: ok_or_else
10491049 && is_diagnostic_item ( sym:: Option , next_ty)
10501050 )
10511051 )
1052- && [ sym :: map_err , sym :: ok_or_else ] . contains ( & path_segment . ident . name )
1052+ // Found `Result<_, ()>?`
10531053 && let ty:: Tuple ( tys) = found_ty. kind ( )
10541054 && tys. is_empty ( )
1055+ // The current method call returns `Result<_, ()>`
10551056 && self . can_eq ( obligation. param_env , ty, found_ty)
1057+ // There's a single argument in the method call and it is a closure
10561058 && args. len ( ) == 1
10571059 && let Some ( arg) = args. get ( 0 )
10581060 && let hir:: ExprKind :: Closure ( closure) = arg. kind
1061+ // The closure has a block for its body with no tail expression
10591062 && let body = self . tcx . hir ( ) . body ( closure. body )
10601063 && let hir:: ExprKind :: Block ( block, _) = body. value . kind
10611064 && let None = block. expr
1065+ // The last statement is of a type that can be converted to the return error type
10621066 && let [ .., stmt] = block. stmts
10631067 && let hir:: StmtKind :: Semi ( expr) = stmt. kind
10641068 && let expr_ty = self . resolve_vars_if_possible (
0 commit comments