@@ -317,20 +317,30 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
317
317
. starts_with ( "std::convert::From<std::option::NoneError" ) ;
318
318
let should_convert_result_to_option = format ! ( "{}" , trait_ref)
319
319
. starts_with ( "<std::option::NoneError as std::convert::From<" ) ;
320
- if is_try && is_from && should_convert_option_to_result {
321
- err. span_suggestion_verbose (
322
- span. shrink_to_lo ( ) ,
323
- "consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else`" ,
324
- ".ok_or_else(|| /* error value */)" . to_string ( ) ,
325
- Applicability :: HasPlaceholders ,
326
- ) ;
327
- } else if is_try && is_from && should_convert_result_to_option {
328
- err. span_suggestion_verbose (
329
- span. shrink_to_lo ( ) ,
330
- "consider converting the `Result<T, _>` into an `Option<T>` using `Result::ok`" ,
331
- ".ok()" . to_string ( ) ,
332
- Applicability :: MachineApplicable ,
333
- ) ;
320
+ if is_try && is_from {
321
+ if should_convert_option_to_result {
322
+ err. span_suggestion_verbose (
323
+ span. shrink_to_lo ( ) ,
324
+ "consider converting the `Option<T>` into a `Result<T, _>` \
325
+ using `Option::ok_or` or `Option::ok_or_else`",
326
+ ".ok_or_else(|| /* error value */)" . to_string ( ) ,
327
+ Applicability :: HasPlaceholders ,
328
+ ) ;
329
+ } else if should_convert_result_to_option {
330
+ err. span_suggestion_verbose (
331
+ span. shrink_to_lo ( ) ,
332
+ "consider converting the `Result<T, _>` into an `Option<T>` \
333
+ using `Result::ok`",
334
+ ".ok()" . to_string ( ) ,
335
+ Applicability :: MachineApplicable ,
336
+ ) ;
337
+ }
338
+ if let Some ( ret_span) = self . return_type_span ( obligation) {
339
+ err. span_label (
340
+ ret_span,
341
+ & format ! ( "expected `{}` because of this" , trait_ref. self_ty( ) ) ,
342
+ ) ;
343
+ }
334
344
}
335
345
336
346
let explanation =
0 commit comments