@@ -891,23 +891,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
891
891
}
892
892
if let Some ( typeck_results) =
893
893
self . in_progress_typeck_results . map ( |t| t. borrow ( ) )
894
+ && let ty = typeck_results. expr_ty_adjusted ( base)
895
+ && let ty:: FnDef ( def_id, _substs) = ty. kind ( )
896
+ && let Some ( hir:: Node :: Item ( hir:: Item { span, ident, .. } ) ) =
897
+ hir. get_if_local ( * def_id)
894
898
{
895
- let ty = typeck_results. expr_ty_adjusted ( base) ;
896
- if let ty:: FnDef ( def_id, _substs) = ty. kind ( ) {
897
- if let Some ( hir:: Node :: Item ( hir:: Item { span, ident, .. } ) ) =
898
- hir. get_if_local ( * def_id)
899
- {
900
- err. span_suggestion_verbose (
901
- span. shrink_to_lo ( ) ,
902
- & format ! (
903
- "alternatively, consider making `fn {}` asynchronous" ,
904
- ident
905
- ) ,
906
- "async " . to_string ( ) ,
907
- Applicability :: MaybeIncorrect ,
908
- ) ;
909
- }
910
- }
899
+ err. span_suggestion_verbose (
900
+ span. shrink_to_lo ( ) ,
901
+ & format ! (
902
+ "alternatively, consider making `fn {}` asynchronous" ,
903
+ ident
904
+ ) ,
905
+ "async " . to_string ( ) ,
906
+ Applicability :: MaybeIncorrect ,
907
+ ) ;
911
908
}
912
909
}
913
910
}
@@ -1000,34 +997,24 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1000
997
span : Span ,
1001
998
trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
1002
999
) {
1003
- let is_empty_tuple =
1004
- |ty : ty:: Binder < ' tcx , Ty < ' _ > > | * ty. skip_binder ( ) . kind ( ) == ty:: Tuple ( ty:: List :: empty ( ) ) ;
1005
-
1006
1000
let hir = self . tcx . hir ( ) ;
1007
1001
let parent_node = hir. get_parent_node ( obligation. cause . body_id ) ;
1008
1002
let node = hir. find ( parent_node) ;
1009
- if let Some ( hir:: Node :: Item ( hir:: Item {
1010
- kind : hir:: ItemKind :: Fn ( sig, _, body_id) , ..
1011
- } ) ) = node
1003
+ if let Some ( hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Fn ( sig, _, body_id) , .. } ) ) = node
1004
+ && let body = hir. body ( * body_id)
1005
+ && let hir:: ExprKind :: Block ( blk, _) = & body. value . kind
1006
+ && sig. decl . output . span ( ) . overlaps ( span)
1007
+ && blk. expr . is_none ( )
1008
+ && * trait_pred. self_ty ( ) . skip_binder ( ) . kind ( ) == ty:: Tuple ( ty:: List :: empty ( ) )
1009
+ // FIXME(estebank): When encountering a method with a trait
1010
+ // bound not satisfied in the return type with a body that has
1011
+ // no return, suggest removal of semicolon on last statement.
1012
+ // Once that is added, close #54771.
1013
+ && let Some ( stmt) = blk. stmts . last ( )
1014
+ && let hir:: StmtKind :: Semi ( _) = stmt. kind
1012
1015
{
1013
- let body = hir. body ( * body_id) ;
1014
- if let hir:: ExprKind :: Block ( blk, _) = & body. value . kind {
1015
- if sig. decl . output . span ( ) . overlaps ( span)
1016
- && blk. expr . is_none ( )
1017
- && is_empty_tuple ( trait_pred. self_ty ( ) )
1018
- {
1019
- // FIXME(estebank): When encountering a method with a trait
1020
- // bound not satisfied in the return type with a body that has
1021
- // no return, suggest removal of semicolon on last statement.
1022
- // Once that is added, close #54771.
1023
- if let Some ( ref stmt) = blk. stmts . last ( ) {
1024
- if let hir:: StmtKind :: Semi ( _) = stmt. kind {
1025
- let sp = self . tcx . sess . source_map ( ) . end_point ( stmt. span ) ;
1026
- err. span_label ( sp, "consider removing this semicolon" ) ;
1027
- }
1028
- }
1029
- }
1030
- }
1016
+ let sp = self . tcx . sess . source_map ( ) . end_point ( stmt. span ) ;
1017
+ err. span_label ( sp, "consider removing this semicolon" ) ;
1031
1018
}
1032
1019
}
1033
1020
@@ -2481,17 +2468,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2481
2468
debug ! ( "suggest_await_before_try: try_trait_obligation {:?}" , try_obligation) ;
2482
2469
if self . predicate_may_hold ( & try_obligation)
2483
2470
&& impls_future. must_apply_modulo_regions ( )
2471
+ && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
2472
+ && snippet. ends_with ( '?' )
2484
2473
{
2485
- if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
2486
- if snippet. ends_with ( '?' ) {
2487
- err. span_suggestion_verbose (
2488
- span. with_hi ( span. hi ( ) - BytePos ( 1 ) ) . shrink_to_hi ( ) ,
2489
- "consider `await`ing on the `Future`" ,
2490
- ".await" . to_string ( ) ,
2491
- Applicability :: MaybeIncorrect ,
2492
- ) ;
2493
- }
2494
- }
2474
+ err. span_suggestion_verbose (
2475
+ span. with_hi ( span. hi ( ) - BytePos ( 1 ) ) . shrink_to_hi ( ) ,
2476
+ "consider `await`ing on the `Future`" ,
2477
+ ".await" . to_string ( ) ,
2478
+ Applicability :: MaybeIncorrect ,
2479
+ ) ;
2495
2480
}
2496
2481
}
2497
2482
}
0 commit comments