@@ -4,7 +4,7 @@ use syntax::ast::*;
44use syntax:: codemap:: { Span , Spanned } ;
55use syntax:: visit:: FnKind ;
66
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} ;
88
99/// **What it does:** This lint checks for return statements at the end of a block. It is `Warn` by default.
1010///
@@ -37,7 +37,7 @@ impl ReturnPass {
3737 } else if let Some ( stmt) = block. stmts . last ( ) {
3838 if let StmtSemi ( ref expr, _) = stmt. node {
3939 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 ) ) ;
4141 }
4242 }
4343 }
@@ -73,10 +73,15 @@ impl ReturnPass {
7373
7474 fn emit_return_lint ( & mut self , cx : & EarlyContext , spans : ( Span , Span ) ) {
7575 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+ } ) ;
8085 }
8186
8287 // Check for "let x = EXPR; x"
0 commit comments