]> git.lizzy.rs Git - rust.git/commitdiff
Allow allowing of toplevel_ref_arg lint
authorPhilipp Hansch <dev@phansch.net>
Fri, 19 Apr 2019 13:18:32 +0000 (15:18 +0200)
committerPhilipp Hansch <dev@phansch.net>
Fri, 19 Apr 2019 13:18:32 +0000 (15:18 +0200)
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`.

clippy_lints/src/misc.rs
tests/ui/toplevel_ref_arg.rs

index 774a878b331f82a45cbf3455f9828f14a22d1ea3..6e41249ea6488e04aff575125225fe899095746b 100644 (file)
@@ -13,8 +13,8 @@
 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 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
             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| {
index 3bc0448234ef63ddd0d8593ab69852408610ad81..a412c387a0dd0814f32a7af1986cf49baa7185c0 100644 (file)
@@ -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;
 }