1
- use crate :: utils:: * ;
1
+ //! Checks syntax of programs written in the 'hacspec' subset of rust
2
+ //! See https://github.com/hacspec/hacspec-rust/blob/franziskus-dev/LANGUAGE.md for the (BNF ?) syntax
3
+ //!
4
+ //!
5
+
6
+
7
+ use crate :: utils:: span_lint;
8
+ //might use crate::utils::higher to look into loops
2
9
use rustc:: lint:: in_external_macro;
3
10
use rustc_hir:: {
4
- intravisit, BindingAnnotation , Body , Expr , ExprKind , FnDecl , HirId , Item , ItemKind , Mod , Mutability , Param , Pat ,
5
- PatKind , Path , PathSegment , Ty , TyKind ,
11
+ intravisit, BindingAnnotation , Body , Expr , ExprKind , FnDecl , HirId , Item , ItemKind , Mod , Param , Pat ,
12
+ PatKind , Path , PathSegment , Ty , TyKind , StructField ,
6
13
} ;
7
14
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
8
15
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -13,7 +20,7 @@ use rustc_span::{
13
20
14
21
declare_clippy_lint ! {
15
22
pub HACSPEC ,
16
- pedantic,
23
+ nursery , // pedantic, corectness or restriction, but shouldn't interfere with other lints ? or shipped completely separately
17
24
"Checks whether the code belongs to the hacspec subset of Rust"
18
25
}
19
26
@@ -56,7 +63,10 @@ fn allowed_type(typ: &Ty<'_>) -> bool {
56
63
}
57
64
}
58
65
66
+
67
+
59
68
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for Hacspec {
69
+
60
70
fn check_path ( & mut self , cx : & LateContext < ' a , ' tcx > , path : & ' tcx Path < ' tcx > , _: HirId ) {
61
71
// Items used in the code are whitelisted
62
72
if in_external_macro ( cx. sess ( ) , path. span ) {
@@ -132,22 +142,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Hacspec {
132
142
}
133
143
}
134
144
145
+ fn check_struct_field (
146
+ & mut self ,
147
+ cx : & LateContext < ' a , ' tcx > ,
148
+ sf : & ' tcx StructField < ' tcx >
149
+ ) {
150
+ // The types of struct (incl. tuples) declaration parameters cannot be references
151
+ if !( allowed_type ( sf. ty ) ) {
152
+ span_lint ( cx, HACSPEC , sf. span , & "[HACSPEC] Unsupported type" )
153
+ }
154
+ }
155
+
156
+
135
157
fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item < ' tcx > ) {
136
158
if in_external_macro ( cx. sess ( ) , item. span ) {
137
159
return ;
138
160
}
139
161
match & item. kind {
140
162
ItemKind :: TyAlias ( ref typ, _) | ItemKind :: Const ( ref typ, _) => {
141
163
if !allowed_type ( typ) {
142
- span_lint ( cx, HACSPEC , item. span , & "[HACSPEC] Unauthorized type for alias" )
143
- }
144
- } ,
145
- ItemKind :: Static ( typ, m, _) => {
146
- if !allowed_type ( typ) || * m == Mutability :: Mut {
147
- span_lint ( cx, HACSPEC , item. span , & "[HACSPEC] Unauthorized static item" )
164
+ span_lint ( cx, HACSPEC , item. span , & "[HACSPEC] Unsupported type" )
148
165
}
149
166
} ,
150
- ItemKind :: ExternCrate ( _) | ItemKind :: Use ( _, _) | ItemKind :: Fn ( _, _, _) => ( ) ,
167
+ ItemKind :: Enum ( _, _) | ItemKind :: Struct ( _, _) |
168
+ ItemKind :: Fn ( _, _, _) |
169
+ ItemKind :: ExternCrate ( _) | ItemKind :: Use ( _, _) => ( ) ,
151
170
_ => span_lint ( cx, HACSPEC , item. span , & "[HACSPEC] Unauthorized item" ) ,
152
171
}
153
172
}
0 commit comments