@@ -3,7 +3,7 @@ use clippy_utils::source::{snippet_with_applicability, snippet_with_context, wal
3
3
use clippy_utils:: visitors:: for_each_expr_without_closures;
4
4
use clippy_utils:: { get_async_fn_body, is_async_fn, is_from_proc_macro} ;
5
5
use core:: ops:: ControlFlow ;
6
- use rustc_errors:: Applicability ;
6
+ use rustc_errors:: { Applicability , SuggestionStyle } ;
7
7
use rustc_hir:: intravisit:: FnKind ;
8
8
use rustc_hir:: { Block , Body , Expr , ExprKind , FnDecl , FnRetTy , HirId } ;
9
9
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
@@ -45,35 +45,42 @@ declare_clippy_lint! {
45
45
declare_lint_pass ! ( ImplicitReturn => [ IMPLICIT_RETURN ] ) ;
46
46
47
47
fn lint_return ( cx : & LateContext < ' _ > , emission_place : HirId , span : Span ) {
48
- let mut app = Applicability :: MachineApplicable ;
49
- let snip = snippet_with_applicability ( cx, span, ".." , & mut app) ;
50
48
span_lint_hir_and_then (
51
49
cx,
52
50
IMPLICIT_RETURN ,
53
51
emission_place,
54
52
span,
55
53
"missing `return` statement" ,
56
54
|diag| {
57
- diag. span_suggestion ( span, "add `return` as shown" , format ! ( "return {snip}" ) , app) ;
55
+ let mut app = Applicability :: MachineApplicable ;
56
+ let snip = snippet_with_applicability ( cx, span, ".." , & mut app) ;
57
+ diag. span_suggestion_with_style (
58
+ span,
59
+ "add `return` as shown" ,
60
+ format ! ( "return {snip}" ) ,
61
+ app,
62
+ SuggestionStyle :: ShowAlways ,
63
+ ) ;
58
64
} ,
59
65
) ;
60
66
}
61
67
62
68
fn lint_break ( cx : & LateContext < ' _ > , emission_place : HirId , break_span : Span , expr_span : Span ) {
63
- let mut app = Applicability :: MachineApplicable ;
64
- let snip = snippet_with_context ( cx, expr_span, break_span. ctxt ( ) , ".." , & mut app) . 0 ;
65
69
span_lint_hir_and_then (
66
70
cx,
67
71
IMPLICIT_RETURN ,
68
72
emission_place,
69
73
break_span,
70
74
"missing `return` statement" ,
71
75
|diag| {
72
- diag. span_suggestion (
76
+ let mut app = Applicability :: MachineApplicable ;
77
+ let snip = snippet_with_context ( cx, expr_span, break_span. ctxt ( ) , ".." , & mut app) . 0 ;
78
+ diag. span_suggestion_with_style (
73
79
break_span,
74
80
"change `break` to `return` as shown" ,
75
81
format ! ( "return {snip}" ) ,
76
82
app,
83
+ SuggestionStyle :: ShowAlways ,
77
84
) ;
78
85
} ,
79
86
) ;
0 commit comments