@@ -598,11 +598,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
598
598
}
599
599
}
600
600
601
- pub fn report_selection_error ( & self ,
602
- obligation : & PredicateObligation < ' tcx > ,
603
- error : & SelectionError < ' tcx > ,
604
- fallback_has_occurred : bool )
605
- {
601
+ pub fn report_selection_error (
602
+ & self ,
603
+ obligation : & PredicateObligation < ' tcx > ,
604
+ error : & SelectionError < ' tcx > ,
605
+ fallback_has_occurred : bool ,
606
+ ) {
606
607
let span = obligation. cause . span ;
607
608
608
609
let mut err = match * error {
@@ -647,6 +648,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
647
648
trait_ref. to_predicate( ) , post_message)
648
649
) ) ;
649
650
651
+ let parent_node = self . tcx . hir ( ) . get_parent_node ( obligation. cause . body_id ) ;
652
+ let node = self . tcx . hir ( ) . find ( parent_node) ;
653
+ if let Some ( hir:: Node :: Item ( hir:: Item {
654
+ node : hir:: ItemKind :: Fn ( decl, _, _, body_id) ,
655
+ ..
656
+ } ) ) = node {
657
+ let body = self . tcx . hir ( ) . body ( * body_id) ;
658
+ if let hir:: ExprKind :: Block ( blk, _) = & body. value . node {
659
+ if decl. output . span ( ) . overlaps ( span) && blk. expr . is_none ( ) &&
660
+ "()" == & trait_ref. self_ty ( ) . to_string ( )
661
+ {
662
+ // When encountering a method with a trait bound not satisfied
663
+ // in the return type with a body that has no return, suggest
664
+ // removal of semicolon on last statement.
665
+ if let Some ( ref stmt) = blk. stmts . last ( ) {
666
+ let sp = self . tcx . sess . source_map ( ) . end_point ( stmt. span ) ;
667
+ err. span_label ( sp, "consider removing this semicolon" ) ;
668
+ }
669
+ }
670
+ }
671
+ }
650
672
let explanation =
651
673
if obligation. cause . code == ObligationCauseCode :: MainFunctionType {
652
674
"consider using `()`, or a `Result`" . to_owned ( )
0 commit comments