Skip to content

Commit 56094b3

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

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

libc-test/test/style/mod.rs

+19-4
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
@@ -212,7 +215,6 @@ impl<'ast> Visit<'ast> for StyleChecker {
212215
let meta_str = meta_list.tokens.to_string();
213216
if meta_list.path.is_ident("cfg")
214217
&& !(meta_str.contains("target_endian") || meta_str.contains("target_arch"))
215-
&& self.state != State::Structs
216218
{
217219
self.error_with_help(
218220
"#[cfg] over cfg_if!".to_string(),
@@ -256,6 +258,19 @@ impl<'ast> Visit<'ast> for StyleChecker {
256258
visit::visit_item_const(self, item_const);
257259
}
258260

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+
259274
fn visit_item_type(&mut self, item_type: &'ast syn::ItemType) {
260275
let span = item_type.span();
261276
self.set_state(State::Typedefs, span);

src/teeos/mod.rs

+3-3
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)