Skip to content

Commit

Permalink
Added specific check for pub(crate | self | super | in)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorKoenders committed Jan 16, 2024
1 parent d61fb94 commit 8a0a3e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/parse/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ fn issue_77() {
};
assert_eq!(t.len(), 1);
assert_eq!(t[0].r#type[0].to_string(), "[u8 ; 32]");

let stream = &mut token_stream("struct Foo(pub (u8, ))");
let (data_type, ident) = super::DataType::take(stream).unwrap();
assert_eq!(data_type, super::DataType::Struct);
assert_eq!(ident, "Foo");
let body = StructBody::take(stream).unwrap();
let fields = body.fields.unwrap();
let Fields::Tuple(t) = fields else {
panic!("Fields is not a tuple")
};
assert_eq!(t.len(), 1);
assert_eq!(t[0].r#type[0].to_string(), "(u8 ,)");
}

/// The body of an enum
Expand Down
13 changes: 11 additions & 2 deletions src/parse/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ impl Visibility {
// check if the next token is `pub(...)`
if let Some(TokenTree::Group(g)) = input.peek() {
if g.delimiter() == Delimiter::Parenthesis {
// we just consume the visibility, we're not actually using it for generation
assume_group(input.next());
// check if this is one of:
// - pub ( crate )
// - pub ( self )
// - pub ( super )
// - pub ( in ... )
if let Some(TokenTree::Ident(i)) = g.stream().into_iter().next() {
if matches!(i.to_string().as_str(), "crate" | "self" | "super" | "in") {
// it is, ignore this token
assume_group(input.next());
}
}
}
}

Expand Down

0 comments on commit 8a0a3e9

Please sign in to comment.