@@ -4,7 +4,7 @@ use syntax::ast::*;
4
4
use syntax:: codemap:: { Span , Spanned } ;
5
5
use syntax:: visit:: FnKind ;
6
6
7
- use utils:: { span_lint, snippet , match_path_ast, in_external_macro} ;
7
+ use utils:: { span_lint, span_lint_and_then , snippet_opt , match_path_ast, in_external_macro} ;
8
8
9
9
/// **What it does:** This lint checks for return statements at the end of a block. It is `Warn` by default.
10
10
///
@@ -37,7 +37,7 @@ impl ReturnPass {
37
37
} else if let Some ( stmt) = block. stmts . last ( ) {
38
38
if let StmtSemi ( ref expr, _) = stmt. node {
39
39
if let ExprRet ( Some ( ref inner) ) = expr. node {
40
- self . emit_return_lint ( cx, ( expr . span , inner. span ) ) ;
40
+ self . emit_return_lint ( cx, ( stmt . span , inner. span ) ) ;
41
41
}
42
42
}
43
43
}
@@ -73,10 +73,15 @@ impl ReturnPass {
73
73
74
74
fn emit_return_lint ( & mut self , cx : & EarlyContext , spans : ( Span , Span ) ) {
75
75
if in_external_macro ( cx, spans. 1 ) { return ; }
76
- span_lint ( cx, NEEDLESS_RETURN , spans. 0 , & format ! (
77
- "unneeded return statement. Consider using `{}` \
78
- without the return and trailing semicolon",
79
- snippet( cx, spans. 1 , ".." ) ) )
76
+ span_lint_and_then ( cx, NEEDLESS_RETURN , spans. 0 ,
77
+ "unneeded return statement" ,
78
+ || {
79
+ if let Some ( snippet) = snippet_opt ( cx, spans. 1 ) {
80
+ cx. sess ( ) . span_suggestion ( spans. 0 ,
81
+ "remove `return` as shown:" ,
82
+ snippet) ;
83
+ }
84
+ } ) ;
80
85
}
81
86
82
87
// Check for "let x = EXPR; x"
0 commit comments