From d8d3ee907bafc690f466e34ab790f568dbeeea36 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 2 Jan 2016 21:49:53 +0530 Subject: [PATCH] Add macro check for box vec (fixes #529) --- src/types.rs | 7 ++++--- tests/compile-fail/box_vec.rs | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/types.rs b/src/types.rs index f332659188b..e119ef63436 100644 --- a/src/types.rs +++ b/src/types.rs @@ -9,9 +9,7 @@ use syntax::ast::IntTy::*; use syntax::ast::UintTy::*; use syntax::ast::FloatTy::*; -use utils::{match_type, snippet, span_lint, span_help_and_lint}; -use utils::{is_from_for_desugar, in_macro, in_external_macro}; -use utils::{LL_PATH, VEC_PATH}; +use utils::*; /// Handles all the linting of funky types #[allow(missing_copy_implementations)] @@ -50,6 +48,9 @@ impl LintPass for TypePass { impl LateLintPass for TypePass { fn check_ty(&mut self, cx: &LateContext, ast_ty: &Ty) { + if in_macro(cx, ast_ty.span) { + return + } if let Some(ty) = cx.tcx.ast_ty_to_ty_cache.borrow().get(&ast_ty.id) { if let ty::TyBox(ref inner) = ty.sty { if match_type(cx, inner, &VEC_PATH) { diff --git a/tests/compile-fail/box_vec.rs b/tests/compile-fail/box_vec.rs index 58e780f190c..4fd98cd52ff 100644 --- a/tests/compile-fail/box_vec.rs +++ b/tests/compile-fail/box_vec.rs @@ -3,6 +3,15 @@ #![plugin(clippy)] #![deny(clippy)] +macro_rules! boxit { + ($init:expr, $x:ty) => { + let _: Box<$x> = Box::new($init); + } +} + +fn test_macro() { + boxit!(Vec::new(), Vec); +} pub fn test(foo: Box>) { //~ ERROR you seem to be trying to use `Box>` println!("{:?}", foo.get(0)) } @@ -14,4 +23,5 @@ pub fn test2(foo: Box)>) { // pass if #31 is fixed fn main(){ test(Box::new(Vec::new())); test2(Box::new(|v| println!("{:?}", v))); + test_macro(); }