Skip to content

Commit 54e80c7

Browse files
committed
Auto merge of #4007 - phansch:fix_allowing_toplevel_ref_arg, r=flip1995
Allow allowing of toplevel_ref_arg lint I'm not sure why some lints need the `HirId` to be able to recognize the lint level attributes, but this commit makes the lint level attributes work for `toplevel_ref_arg`. Fixes #2332 changelog: Allow allowing of `toplevel_ref_arg` lint
2 parents fc1c2f5 + 158aa39 commit 54e80c7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

clippy_lints/src/misc.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::consts::{constant, Constant};
1313
use crate::utils::sugg::Sugg;
1414
use crate::utils::{
1515
get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal, iter_input_pats,
16-
last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then, walk_ptrs_ty,
17-
SpanlessEq,
16+
last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then,
17+
span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq,
1818
};
1919

2020
declare_clippy_lint! {
@@ -282,19 +282,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
282282
if let Some(ref init) = l.init;
283283
then {
284284
if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut {
285-
let init = Sugg::hir(cx, init, "..");
285+
let sugg_init = Sugg::hir(cx, init, "..");
286286
let (mutopt,initref) = if an == BindingAnnotation::RefMut {
287-
("mut ", init.mut_addr())
287+
("mut ", sugg_init.mut_addr())
288288
} else {
289-
("", init.addr())
289+
("", sugg_init.addr())
290290
};
291291
let tyopt = if let Some(ref ty) = l.ty {
292292
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_"))
293293
} else {
294294
String::new()
295295
};
296-
span_lint_and_then(cx,
296+
span_lint_hir_and_then(cx,
297297
TOPLEVEL_REF_ARG,
298+
init.hir_id,
298299
l.pat.span,
299300
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
300301
|db| {

tests/ui/toplevel_ref_arg.rs

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ fn main() {
2222

2323
let (ref x, _) = (1, 2); // ok, not top level
2424
println!("The answer is {}.", x);
25+
26+
// Make sure that allowing the lint works
27+
#[allow(clippy::toplevel_ref_arg)]
28+
let ref mut x = 1_234_543;
2529
}

0 commit comments

Comments
 (0)