Skip to content

Commit 520ff67

Browse files
committed
Automatically make fields of pub enums pub
1 parent af8cce5 commit 520ff67

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/imp.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn recurse_through_definition(
5656
match &mut parsed {
5757
Declaration::Struct(s) => {
5858
strike_through_attributes(&mut s.attributes, &mut strike_attrs, ret);
59-
recurse_through_struct_fields(&mut s.fields, &strike_attrs, ret, &None);
59+
recurse_through_struct_fields(&mut s.fields, &strike_attrs, ret, &None, false);
6060
if make_pub {
6161
s.vis_marker.get_or_insert_with(make_pub_marker);
6262
}
@@ -69,6 +69,7 @@ pub(crate) fn recurse_through_definition(
6969
&strike_attrs,
7070
ret,
7171
&Some(v.name.clone()),
72+
is_plain_pub(&e.vis_marker),
7273
);
7374
}
7475
if make_pub {
@@ -155,6 +156,7 @@ fn recurse_through_struct_fields(
155156
strike_attrs: &[Attribute],
156157
ret: &mut TokenStream,
157158
name_hint: &Option<Ident>,
159+
in_pub_enum: bool,
158160
) {
159161
match fields {
160162
StructFields::Named(n) => {
@@ -171,7 +173,7 @@ fn recurse_through_struct_fields(
171173
strike_attrs,
172174
ret,
173175
&Some(name_hint),
174-
is_plain_pub(&field.vis_marker),
176+
is_plain_pub(&field.vis_marker) || in_pub_enum,
175177
&mut field.ty.tokens,
176178
);
177179
}
@@ -211,7 +213,7 @@ fn recurse_through_struct_fields(
211213
strike_attrs,
212214
ret,
213215
name_hint,
214-
is_plain_pub(&field.vis_marker),
216+
is_plain_pub(&field.vis_marker) || in_pub_enum,
215217
&mut field.ty.tokens,
216218
);
217219
}

src/test.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ fn pub_markers_sane() {
446446
#[test]
447447
fn issue_2() {
448448
let from = quote! {
449-
pub enum Expr<'src> {
449+
enum Expr<'src> {
450450
Binary(struct<'src> {
451451
left: Box<Expr<'src>>,
452452
operator: BinaryOp,
@@ -461,7 +461,26 @@ fn issue_2() {
461461
let out = quote! {
462462
struct Binary < 'src > { left : Box < Expr < 'src >> , operator : BinaryOp , right : Box < Expr < 'src >> , }
463463
enum Literal < 'src > { StringLit (& 'src str) , NumLit (& 'src str) , }
464-
pub enum Expr < 'src > { Binary (Binary<'src>) , Literal (Literal<'src>) , }
464+
enum Expr < 'src > { Binary (Binary<'src>) , Literal (Literal<'src>) , }
465465
};
466466
check(from, out)
467467
}
468+
469+
#[test]
470+
fn pub_enum_autopubs() {
471+
let from = quote! {
472+
pub enum Outer {
473+
An(struct ()),
474+
Ny(struct {}),
475+
};
476+
};
477+
let out = quote! {
478+
pub struct An ();
479+
pub struct Ny {}
480+
pub enum Outer {
481+
An(An),
482+
Ny(Ny),
483+
}
484+
};
485+
check(from, out);
486+
}

0 commit comments

Comments
 (0)