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 issue #55 #61

Merged
merged 1 commit into from
Mar 10, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ fn format_with(
let fmt_path = fmt_path();
let phantom_path = phantom_path();

let ctor_generics = generics.clone();
let (_, ctor_ty_generics, _) = ctor_generics.split_for_impl();

generics
.make_where_clause()
.predicates
Expand Down Expand Up @@ -179,12 +176,16 @@ fn format_with(

// Leave off the type parameter bounds, defaults, and attributes
let phantom = generics.type_params().map(|tp| &tp.ident);


let mut ctor_generics = generics.clone();
*ctor_generics.lifetimes_mut().last().expect("There must be a '_derivative lifetime")
= syn::LifetimeDef::new(parse_quote!('_));
let (_, ctor_ty_generics, _) = ctor_generics.split_for_impl();
let ctor_ty_generics = ctor_ty_generics.as_turbofish();

quote_spanned!(f.span=>
let #arg_n = {
struct Dummy #ty_generics (&'_derivative #ty, #phantom_path <(#(#phantom),*)>) #where_clause;
struct Dummy #impl_generics (&'_derivative #ty, #phantom_path <(#(#phantom,)*)>) #where_clause;

impl #impl_generics #debug_trait_path for Dummy #ty_generics #where_clause {
fn fmt(&self, __f: &mut #fmt_path::Formatter) -> #fmt_path::Result {
Expand Down
21 changes: 21 additions & 0 deletions tests/issue-55.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[cfg(feature = "use_core")]
extern crate core;

#[macro_use]
extern crate derivative;

trait Foo {}

fn fmt<T>(_: &T, _: &mut std::fmt::Formatter) -> std::fmt::Result {
unimplemented!()
}

#[derive(Debug)]
struct Qux<'a, T: Foo>(&'a T);

#[derive(Derivative)]
#[derivative(Debug)]
struct Bar<'a, T: Foo>(#[derivative(Debug(format_with="fmt"))] Qux<'a, T>);

fn main() {
}