|
1 |
| -use clippy_utils::diagnostics::{span_lint, span_lint_and_then, span_lint_hir_and_then}; |
| 1 | +use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir, span_lint_hir_and_then}; |
2 | 2 | use clippy_utils::source::{snippet, snippet_with_context};
|
3 | 3 | use clippy_utils::sugg::Sugg;
|
4 | 4 | use clippy_utils::{
|
@@ -114,40 +114,35 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
|
114 | 114 | k: FnKind<'tcx>,
|
115 | 115 | decl: &'tcx FnDecl<'_>,
|
116 | 116 | body: &'tcx Body<'_>,
|
117 |
| - span: Span, |
| 117 | + _: Span, |
118 | 118 | _: LocalDefId,
|
119 | 119 | ) {
|
120 |
| - if let FnKind::Closure = k { |
121 |
| - // Does not apply to closures |
122 |
| - return; |
123 |
| - } |
124 |
| - if in_external_macro(cx.tcx.sess, span) { |
125 |
| - return; |
126 |
| - } |
127 |
| - for arg in iter_input_pats(decl, body) { |
128 |
| - // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue. |
129 |
| - if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) { |
130 |
| - return; |
131 |
| - } |
132 |
| - if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind { |
133 |
| - span_lint( |
134 |
| - cx, |
135 |
| - TOPLEVEL_REF_ARG, |
136 |
| - arg.pat.span, |
137 |
| - "`ref` directly on a function argument is ignored. \ |
138 |
| - Consider using a reference type instead", |
139 |
| - ); |
| 120 | + if !matches!(k, FnKind::Closure) { |
| 121 | + for arg in iter_input_pats(decl, body) { |
| 122 | + if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind |
| 123 | + && is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) |
| 124 | + && !in_external_macro(cx.tcx.sess, arg.span) |
| 125 | + { |
| 126 | + span_lint_hir( |
| 127 | + cx, |
| 128 | + TOPLEVEL_REF_ARG, |
| 129 | + arg.hir_id, |
| 130 | + arg.pat.span, |
| 131 | + "`ref` directly on a function argument is ignored. \ |
| 132 | + Consider using a reference type instead", |
| 133 | + ); |
| 134 | + } |
140 | 135 | }
|
141 | 136 | }
|
142 | 137 | }
|
143 | 138 |
|
144 | 139 | fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
145 |
| - if !in_external_macro(cx.tcx.sess, stmt.span) |
146 |
| - && let StmtKind::Let(local) = stmt.kind |
| 140 | + if let StmtKind::Let(local) = stmt.kind |
147 | 141 | && let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind
|
148 | 142 | && let Some(init) = local.init
|
149 | 143 | // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
|
150 | 144 | && is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id)
|
| 145 | + && !in_external_macro(cx.tcx.sess, stmt.span) |
151 | 146 | {
|
152 | 147 | let ctxt = local.span.ctxt();
|
153 | 148 | let mut app = Applicability::MachineApplicable;
|
|
0 commit comments