diff options
| author | bors <bors@rust-lang.org> | 2019-04-20 18:22:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-20 18:22:53 +0000 |
| commit | 54e80c7b34d391ba37f814517ec23f1897cdae18 (patch) | |
| tree | 01c792484c4ac92bb621d05eb6ae54d55a422a2b | |
| parent | fc1c2f5f1aad73d58673fc64952fc144e3e50bf7 (diff) | |
| parent | 158aa39a7c83164c949d5130cb114e444e8b38af (diff) | |
| download | rust-54e80c7b34d391ba37f814517ec23f1897cdae18.tar.gz rust-54e80c7b34d391ba37f814517ec23f1897cdae18.zip | |
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
| -rw-r--r-- | clippy_lints/src/misc.rs | 13 | ||||
| -rw-r--r-- | tests/ui/toplevel_ref_arg.rs | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 774a878b331..6e41249ea64 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -13,8 +13,8 @@ use crate::consts::{constant, Constant}; use crate::utils::sugg::Sugg; use crate::utils::{ get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal, iter_input_pats, - last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then, walk_ptrs_ty, - SpanlessEq, + last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then, + span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq, }; declare_clippy_lint! { @@ -282,19 +282,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { if let Some(ref init) = l.init; then { if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut { - let init = Sugg::hir(cx, init, ".."); + let sugg_init = Sugg::hir(cx, init, ".."); let (mutopt,initref) = if an == BindingAnnotation::RefMut { - ("mut ", init.mut_addr()) + ("mut ", sugg_init.mut_addr()) } else { - ("", init.addr()) + ("", sugg_init.addr()) }; let tyopt = if let Some(ref ty) = l.ty { format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_")) } else { String::new() }; - span_lint_and_then(cx, + span_lint_hir_and_then(cx, TOPLEVEL_REF_ARG, + init.hir_id, l.pat.span, "`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead", |db| { diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index 3bc0448234e..a412c387a0d 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -22,4 +22,8 @@ fn main() { let (ref x, _) = (1, 2); // ok, not top level println!("The answer is {}.", x); + + // Make sure that allowing the lint works + #[allow(clippy::toplevel_ref_arg)] + let ref mut x = 1_234_543; } |
