]> git.lizzy.rs Git - rust.git/commitdiff
Add macro check for box vec (fixes #529)
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 2 Jan 2016 16:19:53 +0000 (21:49 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Sat, 2 Jan 2016 16:19:53 +0000 (21:49 +0530)
src/types.rs
tests/compile-fail/box_vec.rs

index f332659188b472301c171ad15f2e30551db93da6..e119ef63436a3c5e645c3f51949e3c94ed12c7f1 100644 (file)
@@ -9,9 +9,7 @@
 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 @@ fn get_lints(&self) -> LintArray {
 
 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) {
index 58e780f190ce89c9b7dfe231d9f248f36dadee00..4fd98cd52ff3be4fd3e30525a7572100f857a05c 100644 (file)
@@ -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<u8>);
+}
 pub fn test(foo: Box<Vec<bool>>) { //~ ERROR you seem to be trying to use `Box<Vec<T>>`
     println!("{:?}", foo.get(0))
 }
@@ -14,4 +23,5 @@ pub fn test2(foo: Box<Fn(Vec<u32>)>) { // pass if #31 is fixed
 fn main(){
     test(Box::new(Vec::new()));
     test2(Box::new(|v| println!("{:?}", v)));
+    test_macro();
 }