Skip to content

Commit 34573d1

Browse files
committed
add visitor for struct and check if in impl
1 parent 5213e6f commit 34573d1

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

libc-test/test/style/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/teeos/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ pub type c_long = i64;
5151

5252
pub type c_ulong = u64;
5353

54-
#[repr(align(16))]
55-
pub struct _CLongDouble(pub u128);
56-
5754
// long double in C means A float point value, which has 128bit length.
5855
// but some bit maybe not used, so the real length of long double could be 80(x86) or 128(power pc/IEEE)
5956
// this is different from f128(not stable and not included default) in Rust, so we use u128 for FFI(Rust to C).
@@ -88,6 +85,9 @@ pub type wctype_t = c_ulong;
8885

8986
pub type cmpfunc = extern "C" fn(x: *const c_void, y: *const c_void) -> c_int;
9087

88+
#[repr(align(16))]
89+
pub struct _CLongDouble(pub u128);
90+
9191
#[repr(align(8))]
9292
#[repr(C)]
9393
pub struct pthread_cond_t {

0 commit comments

Comments
 (0)