@@ -648,28 +648,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
648
648
trait_ref. to_predicate( ) , post_message)
649
649
) ) ;
650
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
- // FIXME(estebank): When encountering a method with a trait
663
- // bound not satisfied in the return type with a body that has
664
- // no return, suggest removal of semicolon on last statement.
665
- // Once that is added, close #54771.
666
- if let Some ( ref stmt) = blk. stmts . last ( ) {
667
- let sp = self . tcx . sess . source_map ( ) . end_point ( stmt. span ) ;
668
- err. span_label ( sp, "consider removing this semicolon" ) ;
669
- }
670
- }
671
- }
672
- }
673
651
let explanation =
674
652
if obligation. cause . code == ObligationCauseCode :: MainFunctionType {
675
653
"consider using `()`, or a `Result`" . to_owned ( )
@@ -695,6 +673,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
695
673
696
674
self . suggest_borrow_on_unsized_slice ( & obligation. cause . code , & mut err) ;
697
675
self . suggest_remove_reference ( & obligation, & mut err, & trait_ref) ;
676
+ self . suggest_semicolon_removal ( & obligation, & mut err, span, & trait_ref) ;
698
677
699
678
// Try to report a help message
700
679
if !trait_ref. has_infer_types ( ) &&
@@ -923,9 +902,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
923
902
924
903
/// When encountering an assignment of an unsized trait, like `let x = ""[..];`, provide a
925
904
/// suggestion to borrow the initializer in order to use have a slice instead.
926
- fn suggest_borrow_on_unsized_slice ( & self ,
927
- code : & ObligationCauseCode < ' tcx > ,
928
- err : & mut DiagnosticBuilder < ' tcx > ) {
905
+ fn suggest_borrow_on_unsized_slice (
906
+ & self ,
907
+ code : & ObligationCauseCode < ' tcx > ,
908
+ err : & mut DiagnosticBuilder < ' tcx > ,
909
+ ) {
929
910
if let & ObligationCauseCode :: VariableType ( node_id) = code {
930
911
let parent_node = self . tcx . hir ( ) . get_parent_node ( node_id) ;
931
912
if let Some ( Node :: Local ( ref local) ) = self . tcx . hir ( ) . find ( parent_node) {
@@ -947,10 +928,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
947
928
948
929
/// Whenever references are used by mistake, like `for (i, e) in &vec.iter().enumerate()`,
949
930
/// suggest removing these references until we reach a type that implements the trait.
950
- fn suggest_remove_reference ( & self ,
951
- obligation : & PredicateObligation < ' tcx > ,
952
- err : & mut DiagnosticBuilder < ' tcx > ,
953
- trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ) {
931
+ fn suggest_remove_reference (
932
+ & self ,
933
+ obligation : & PredicateObligation < ' tcx > ,
934
+ err : & mut DiagnosticBuilder < ' tcx > ,
935
+ trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ,
936
+ ) {
954
937
let trait_ref = trait_ref. skip_binder ( ) ;
955
938
let span = obligation. cause . span ;
956
939
@@ -992,6 +975,40 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
992
975
}
993
976
}
994
977
978
+ fn suggest_semicolon_removal (
979
+ & self ,
980
+ obligation : & PredicateObligation < ' tcx > ,
981
+ err : & mut DiagnosticBuilder < ' tcx > ,
982
+ span : Span ,
983
+ trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ,
984
+ ) {
985
+ let hir = self . tcx . hir ( ) ;
986
+ let parent_node = hir. get_parent_node (
987
+ hir. hir_to_node_id ( obligation. cause . body_id ) ,
988
+ ) ;
989
+ let node = hir. find ( parent_node) ;
990
+ if let Some ( hir:: Node :: Item ( hir:: Item {
991
+ node : hir:: ItemKind :: Fn ( decl, _, _, body_id) ,
992
+ ..
993
+ } ) ) = node {
994
+ let body = hir. body ( * body_id) ;
995
+ if let hir:: ExprKind :: Block ( blk, _) = & body. value . node {
996
+ if decl. output . span ( ) . overlaps ( span) && blk. expr . is_none ( ) &&
997
+ "()" == & trait_ref. self_ty ( ) . to_string ( )
998
+ {
999
+ // FIXME(estebank): When encountering a method with a trait
1000
+ // bound not satisfied in the return type with a body that has
1001
+ // no return, suggest removal of semicolon on last statement.
1002
+ // Once that is added, close #54771.
1003
+ if let Some ( ref stmt) = blk. stmts . last ( ) {
1004
+ let sp = self . tcx . sess . source_map ( ) . end_point ( stmt. span ) ;
1005
+ err. span_label ( sp, "consider removing this semicolon" ) ;
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+
995
1012
/// Given some node representing a fn-like thing in the HIR map,
996
1013
/// returns a span and `ArgKind` information that describes the
997
1014
/// arguments it expects. This can be supplied to
0 commit comments