@@ -115,6 +115,8 @@ pub enum Lint {
115
115
DeprecatedOwnedVector ,
116
116
117
117
Warnings ,
118
+
119
+ RawPointerDeriving ,
118
120
}
119
121
120
122
pub fn level_to_str ( lv : level ) -> & ' static str {
@@ -406,6 +408,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
406
408
desc : "use of a `~[T]` vector" ,
407
409
default : allow,
408
410
} ) ,
411
+
412
+ ( "raw_pointer_deriving" ,
413
+ LintSpec {
414
+ lint : RawPointerDeriving ,
415
+ desc : "uses of #[deriving] with raw pointers are rarely correct" ,
416
+ default : warn,
417
+ } ) ,
409
418
] ;
410
419
411
420
/*
@@ -959,6 +968,37 @@ fn check_heap_item(cx: &Context, it: &ast::Item) {
959
968
}
960
969
}
961
970
971
+ struct RawPtrDerivingVisitor < ' a > {
972
+ cx : & ' a Context < ' a >
973
+ }
974
+
975
+ impl < ' a > Visitor < ( ) > for RawPtrDerivingVisitor < ' a > {
976
+ fn visit_ty ( & mut self , ty : & ast:: Ty , _: ( ) ) {
977
+ static MSG : & ' static str = "use of `#[deriving]` with a raw pointer" ;
978
+ match ty. node {
979
+ ast:: TyPtr ( ..) => self . cx . span_lint ( RawPointerDeriving , ty. span , MSG ) ,
980
+ _ => { }
981
+ }
982
+ visit:: walk_ty ( self , ty, ( ) ) ;
983
+ }
984
+ // explicit override to a no-op to reduce code bloat
985
+ fn visit_expr ( & mut self , _: & ast:: Expr , _: ( ) ) { }
986
+ fn visit_block ( & mut self , _: & ast:: Block , _: ( ) ) { }
987
+ }
988
+
989
+ fn check_raw_ptr_deriving ( cx : & Context , item : & ast:: Item ) {
990
+ if !attr:: contains_name ( item. attrs . as_slice ( ) , "deriving" ) {
991
+ return
992
+ }
993
+ match item. node {
994
+ ast:: ItemStruct ( ..) | ast:: ItemEnum ( ..) => {
995
+ let mut visitor = RawPtrDerivingVisitor { cx : cx } ;
996
+ visit:: walk_item ( & mut visitor, item, ( ) ) ;
997
+ }
998
+ _ => { }
999
+ }
1000
+ }
1001
+
962
1002
static crate_attrs: & ' static [ & ' static str ] = & [
963
1003
"crate_type" , "feature" , "no_start" , "no_main" , "no_std" , "crate_id" ,
964
1004
"desc" , "comment" , "license" , "copyright" , // not used in rustc now
@@ -1585,6 +1625,7 @@ impl<'a> Visitor<()> for Context<'a> {
1585
1625
check_heap_item ( cx, it) ;
1586
1626
check_missing_doc_item ( cx, it) ;
1587
1627
check_attrs_usage ( cx, it. attrs . as_slice ( ) ) ;
1628
+ check_raw_ptr_deriving ( cx, it) ;
1588
1629
1589
1630
cx. visit_ids ( |v| v. visit_item ( it, ( ) ) ) ;
1590
1631
0 commit comments