1
1
use clippy_utils:: {
2
- diagnostics:: span_lint_and_sugg ,
2
+ diagnostics:: span_lint_hir_and_then ,
3
3
get_async_fn_body, is_async_fn,
4
4
source:: { snippet_with_applicability, snippet_with_context, walk_span_to_context} ,
5
5
visitors:: expr_visitor_no_bodies,
@@ -43,31 +43,38 @@ declare_clippy_lint! {
43
43
44
44
declare_lint_pass ! ( ImplicitReturn => [ IMPLICIT_RETURN ] ) ;
45
45
46
- fn lint_return ( cx : & LateContext < ' _ > , span : Span ) {
46
+ fn lint_return ( cx : & LateContext < ' _ > , emission_place : HirId , span : Span ) {
47
47
let mut app = Applicability :: MachineApplicable ;
48
48
let snip = snippet_with_applicability ( cx, span, ".." , & mut app) ;
49
- span_lint_and_sugg (
49
+ span_lint_hir_and_then (
50
50
cx,
51
51
IMPLICIT_RETURN ,
52
+ emission_place,
52
53
span,
53
54
"missing `return` statement" ,
54
- "add `return` as shown" ,
55
- format ! ( "return {}" , snip) ,
56
- app ,
55
+ |diag| {
56
+ diag . span_suggestion ( span , "add `return` as shown" , format ! ( "return {}" , snip) , app ) ;
57
+ } ,
57
58
) ;
58
59
}
59
60
60
- fn lint_break ( cx : & LateContext < ' _ > , break_span : Span , expr_span : Span ) {
61
+ fn lint_break ( cx : & LateContext < ' _ > , emission_place : HirId , break_span : Span , expr_span : Span ) {
61
62
let mut app = Applicability :: MachineApplicable ;
62
63
let snip = snippet_with_context ( cx, expr_span, break_span. ctxt ( ) , ".." , & mut app) . 0 ;
63
- span_lint_and_sugg (
64
+ span_lint_hir_and_then (
64
65
cx,
65
66
IMPLICIT_RETURN ,
67
+ emission_place,
66
68
break_span,
67
69
"missing `return` statement" ,
68
- "change `break` to `return` as shown" ,
69
- format ! ( "return {}" , snip) ,
70
- app,
70
+ |diag| {
71
+ diag. span_suggestion (
72
+ break_span,
73
+ "change `break` to `return` as shown" ,
74
+ format ! ( "return {}" , snip) ,
75
+ app,
76
+ ) ;
77
+ } ,
71
78
) ;
72
79
}
73
80
@@ -152,7 +159,7 @@ fn lint_implicit_returns(
152
159
// At this point sub_expr can be `None` in async functions which either diverge, or return
153
160
// the unit type.
154
161
if let Some ( sub_expr) = sub_expr {
155
- lint_break ( cx, e. span , sub_expr. span ) ;
162
+ lint_break ( cx, e. hir_id , e . span , sub_expr. span ) ;
156
163
}
157
164
} else {
158
165
// the break expression is from a macro call, add a return to the loop
@@ -166,10 +173,10 @@ fn lint_implicit_returns(
166
173
if add_return {
167
174
#[ expect( clippy:: option_if_let_else) ]
168
175
if let Some ( span) = call_site_span {
169
- lint_return ( cx, span) ;
176
+ lint_return ( cx, expr . hir_id , span) ;
170
177
LintLocation :: Parent
171
178
} else {
172
- lint_return ( cx, expr. span ) ;
179
+ lint_return ( cx, expr. hir_id , expr . span ) ;
173
180
LintLocation :: Inner
174
181
}
175
182
} else {
@@ -198,10 +205,10 @@ fn lint_implicit_returns(
198
205
{
199
206
#[ expect( clippy:: option_if_let_else) ]
200
207
if let Some ( span) = call_site_span {
201
- lint_return ( cx, span) ;
208
+ lint_return ( cx, expr . hir_id , span) ;
202
209
LintLocation :: Parent
203
210
} else {
204
- lint_return ( cx, expr. span ) ;
211
+ lint_return ( cx, expr. hir_id , expr . span ) ;
205
212
LintLocation :: Inner
206
213
}
207
214
} ,
0 commit comments