@@ -3,7 +3,7 @@ use clippy_utils::source::{snippet_with_applicability, snippet_with_context, wal
33use clippy_utils:: visitors:: for_each_expr_without_closures;
44use clippy_utils:: { get_async_fn_body, is_async_fn, is_from_proc_macro} ;
55use core:: ops:: ControlFlow ;
6- use rustc_errors:: Applicability ;
6+ use rustc_errors:: { Applicability , SuggestionStyle } ;
77use rustc_hir:: intravisit:: FnKind ;
88use rustc_hir:: { Block , Body , Expr , ExprKind , FnDecl , FnRetTy , HirId } ;
99use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
@@ -45,35 +45,42 @@ declare_clippy_lint! {
4545declare_lint_pass ! ( ImplicitReturn => [ IMPLICIT_RETURN ] ) ;
4646
4747fn 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) ;
5048 span_lint_hir_and_then (
5149 cx,
5250 IMPLICIT_RETURN ,
5351 emission_place,
5452 span,
5553 "missing `return` statement" ,
5654 |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+ ) ;
5864 } ,
5965 ) ;
6066}
6167
6268fn 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 ;
6569 span_lint_hir_and_then (
6670 cx,
6771 IMPLICIT_RETURN ,
6872 emission_place,
6973 break_span,
7074 "missing `return` statement" ,
7175 |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 (
7379 break_span,
7480 "change `break` to `return` as shown" ,
7581 format ! ( "return {snip}" ) ,
7682 app,
83+ SuggestionStyle :: ShowAlways ,
7784 ) ;
7885 } ,
7986 ) ;
0 commit comments