@@ -30,6 +30,7 @@ pub struct StyleChecker {
3030 errors : Vec < FileError > ,
3131 /// Path of the currently active file
3232 path : PathBuf ,
33+ in_impl : bool ,
3334}
3435
3536#[ derive( Default , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
@@ -121,7 +122,7 @@ impl StyleChecker {
121122 }
122123
123124 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 {
125126 self . error_with_help (
126127 "incorrect module layout" . to_string ( ) ,
127128 span,
@@ -160,8 +161,10 @@ impl StyleChecker {
160161 // (self.on_err)(line, "multiple s! macros in one module");
161162 // }
162163
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+ }
165168 }
166169
167170 /// Visit the items inside the [ExprCfgIf], restoring the state after
@@ -256,6 +259,19 @@ impl<'ast> Visit<'ast> for StyleChecker {
256259 visit:: visit_item_const ( self , item_const) ;
257260 }
258261
262+ fn visit_item_impl ( & mut self , item_impl : & ' ast syn:: ItemImpl ) {
263+ self . in_impl = true ;
264+ visit:: visit_item_impl ( self , item_impl) ;
265+ self . in_impl = false ;
266+ }
267+
268+ fn visit_item_struct ( & mut self , item_struct : & ' ast syn:: ItemStruct ) {
269+ let span = item_struct. span ( ) ;
270+ self . set_state ( State :: Structs , span) ;
271+
272+ visit:: visit_item_struct ( self , item_struct) ;
273+ }
274+
259275 fn visit_item_type ( & mut self , item_type : & ' ast syn:: ItemType ) {
260276 let span = item_type. span ( ) ;
261277 self . set_state ( State :: Typedefs , span) ;
0 commit comments