Skip to content

Commit

Permalink
Merge pull request #97 from AldaronLau/fix-private-type-leak
Browse files Browse the repository at this point in the history
Fix private type leak
  • Loading branch information
idanarye committed Jun 24, 2023
2 parents 20d0cf1 + 0846ad7 commit 7d7b54b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
27 changes: 27 additions & 0 deletions tests/no_type_leakage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// As long as this test compiles, it passes (test does not occur at runtime)

use typed_builder::TypedBuilder;

#[derive(PartialEq, TypedBuilder)]
#[builder(
build_method(vis="pub", into=Bar),
builder_method(vis=""),
builder_type(vis="pub", name=BarBuilder),
)]
struct Foo {
x: i32,
}

pub struct Bar(Foo);

impl Bar {
pub fn builder() -> BarBuilder {
Foo::builder()
}
}

impl From<Foo> for Bar {
fn from(wrapped: Foo) -> Self {
Bar(wrapped)
}
}
11 changes: 3 additions & 8 deletions typed-builder-macro/src/struct_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ impl<'a> StructInfo<'a> {
}

pub fn required_field_impl(&self, field: &FieldInfo) -> TokenStream {
let StructInfo {
ref name,
ref builder_name,
..
} = self;
let StructInfo { ref builder_name, .. } = self;

let FieldInfo {
name: ref field_name, ..
Expand Down Expand Up @@ -355,7 +351,6 @@ impl<'a> StructInfo<'a> {

builder_generics.push(syn::GenericArgument::Type(builder_generics_tuple.into()));
let (impl_generics, _, where_clause) = generics.split_for_impl();
let (_, ty_generics, _) = self.generics.split_for_impl();

let early_build_error_type_name = syn::Ident::new(
&format!(
Expand All @@ -380,8 +375,8 @@ impl<'a> StructInfo<'a> {
#[deprecated(
note = #early_build_error_message
)]
#build_method_visibility fn #build_method_name(self, _: #early_build_error_type_name) -> #name #ty_generics {
panic!();
#build_method_visibility fn #build_method_name(self, _: #early_build_error_type_name) -> ! {
panic!()
}
}
}
Expand Down

0 comments on commit 7d7b54b

Please sign in to comment.