@@ -30,6 +30,7 @@ pub struct StyleChecker {
30
30
errors : Vec < FileError > ,
31
31
/// Path of the currently active file
32
32
path : PathBuf ,
33
+ in_impl : bool ,
33
34
}
34
35
35
36
#[ derive( Default , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
@@ -121,7 +122,7 @@ impl StyleChecker {
121
122
}
122
123
123
124
fn set_state ( & mut self , new_state : State , span : Span ) {
124
- if self . state > new_state {
125
+ if self . state > new_state && ! self . in_impl {
125
126
self . error_with_help (
126
127
"incorrect module layout" . to_string ( ) ,
127
128
span,
@@ -160,8 +161,10 @@ impl StyleChecker {
160
161
// (self.on_err)(line, "multiple s! macros in one module");
161
162
// }
162
163
163
- self . state = new_state;
164
- self . state_span = Some ( span) ;
164
+ if self . state != new_state {
165
+ self . state = new_state;
166
+ self . state_span = Some ( span) ;
167
+ }
165
168
}
166
169
167
170
/// Visit the items inside the [ExprCfgIf], restoring the state after
@@ -212,7 +215,6 @@ impl<'ast> Visit<'ast> for StyleChecker {
212
215
let meta_str = meta_list. tokens . to_string ( ) ;
213
216
if meta_list. path . is_ident ( "cfg" )
214
217
&& !( meta_str. contains ( "target_endian" ) || meta_str. contains ( "target_arch" ) )
215
- && self . state != State :: Structs
216
218
{
217
219
self . error_with_help (
218
220
"#[cfg] over cfg_if!" . to_string ( ) ,
@@ -256,6 +258,19 @@ impl<'ast> Visit<'ast> for StyleChecker {
256
258
visit:: visit_item_const ( self , item_const) ;
257
259
}
258
260
261
+ fn visit_item_impl ( & mut self , item_impl : & ' ast syn:: ItemImpl ) {
262
+ self . in_impl = true ;
263
+ visit:: visit_item_impl ( self , item_impl) ;
264
+ self . in_impl = false ;
265
+ }
266
+
267
+ fn visit_item_struct ( & mut self , item_struct : & ' ast syn:: ItemStruct ) {
268
+ let span = item_struct. span ( ) ;
269
+ self . set_state ( State :: Structs , span) ;
270
+
271
+ visit:: visit_item_struct ( self , item_struct) ;
272
+ }
273
+
259
274
fn visit_item_type ( & mut self , item_type : & ' ast syn:: ItemType ) {
260
275
let span = item_type. span ( ) ;
261
276
self . set_state ( State :: Typedefs , span) ;
0 commit comments