Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix private type leak #97

Merged
merged 3 commits into from Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/no_type_leakage.rs
@@ -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
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