File tree 2 files changed +24
-1
lines changed
compiler/rustc_builtin_macros/src/deriving/generic
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(
412
412
413
413
impl < ' a , ' b > visit:: Visitor < ' a > for Visitor < ' a , ' b > {
414
414
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
+
415
424
if let ast:: TyKind :: Path ( _, path) = & ty. kind
416
425
&& let Some ( segment) = path. segments . first ( )
417
426
&& self . ty_param_names . contains ( & segment. ident . name )
@@ -422,7 +431,8 @@ fn find_type_parameters(
422
431
} ) ;
423
432
}
424
433
425
- visit:: walk_ty ( self , ty)
434
+ visit:: walk_ty ( self , ty) ;
435
+ self . bound_generic_params_stack . truncate ( stack_len) ;
426
436
}
427
437
428
438
// 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