|
1 | 1 | use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
|
2 |
| -use clippy_utils::source::snippet_opt; |
| 2 | +use clippy_utils::source::{snippet_opt, snippet_with_context}; |
3 | 3 | use clippy_utils::{fn_def_id, path_to_local_id};
|
4 | 4 | use if_chain::if_chain;
|
5 | 5 | use rustc_ast::ast::Attribute;
|
@@ -226,14 +226,10 @@ fn emit_return_lint(cx: &LateContext<'_>, ret_span: Span, inner_span: Option<Spa
|
226 | 226 | }
|
227 | 227 | match inner_span {
|
228 | 228 | Some(inner_span) => {
|
229 |
| - if in_external_macro(cx.tcx.sess, inner_span) || inner_span.from_expansion() { |
230 |
| - return; |
231 |
| - } |
232 |
| - |
| 229 | + let mut applicability = Applicability::MachineApplicable; |
233 | 230 | span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |diag| {
|
234 |
| - if let Some(snippet) = snippet_opt(cx, inner_span) { |
235 |
| - diag.span_suggestion(ret_span, "remove `return`", snippet, Applicability::MachineApplicable); |
236 |
| - } |
| 231 | + let (snippet, _) = snippet_with_context(cx, inner_span, ret_span.ctxt(), "..", &mut applicability); |
| 232 | + diag.span_suggestion(ret_span, "remove `return`", snippet, applicability); |
237 | 233 | });
|
238 | 234 | },
|
239 | 235 | None => match replacement {
|
@@ -287,7 +283,7 @@ struct BorrowVisitor<'a, 'tcx> {
|
287 | 283 |
|
288 | 284 | impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> {
|
289 | 285 | fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
290 |
| - if self.borrows { |
| 286 | + if self.borrows || expr.span.from_expansion() { |
291 | 287 | return;
|
292 | 288 | }
|
293 | 289 |
|
|
0 commit comments