File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
compiler/rustc_builtin_macros/src/deriving/generic Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -412,6 +412,15 @@ fn find_type_parameters(
412412
413413 impl < ' a , ' b > visit:: Visitor < ' a > for Visitor < ' a , ' b > {
414414 fn visit_ty ( & mut self , ty : & ' a ast:: Ty ) {
415+ let stack_len = self . bound_generic_params_stack . len ( ) ;
416+ if let ast:: TyKind :: BareFn ( bare_fn) = & ty. kind
417+ && !bare_fn. generic_params . is_empty ( )
418+ {
419+ // Given a field `x: for<'a> fn(T::SomeType<'a>)`, we wan't to account for `'a` so
420+ // that we generate `where for<'a> T::SomeType<'a>: ::core::clone::Clone`. #122622
421+ self . bound_generic_params_stack . extend ( bare_fn. generic_params . iter ( ) . cloned ( ) ) ;
422+ }
423+
415424 if let ast:: TyKind :: Path ( _, path) = & ty. kind
416425 && let Some ( segment) = path. segments . first ( )
417426 && self . ty_param_names . contains ( & segment. ident . name )
@@ -422,7 +431,8 @@ fn find_type_parameters(
422431 } ) ;
423432 }
424433
425- visit:: walk_ty ( self , ty)
434+ visit:: walk_ty ( self , ty) ;
435+ self . bound_generic_params_stack . truncate ( stack_len) ;
426436 }
427437
428438 // Place bound generic params on a stack, to extract them when a type is encountered.
Original file line number Diff line number Diff line change 1+ //@ run-pass
2+ // Issue #122622: `#[derive(Clone)]` should work for HRTB function type taking an associated type
3+ #![ allow( dead_code) ]
4+ trait SomeTrait {
5+ type SomeType < ' a > ;
6+ }
7+
8+ #[ derive( Clone ) ]
9+ struct Foo < T : SomeTrait > {
10+ x : for <' a > fn ( T :: SomeType < ' a > )
11+ }
12+
13+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments