@@ -51,15 +51,13 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
51
51
match path. res {
52
52
Res :: Def ( _, def_id) if cx. tcx . has_attr ( def_id, sym:: rustc_pass_by_value) => {
53
53
let name = cx. tcx . item_name ( def_id) . to_ident_string ( ) ;
54
- return Some ( format ! ( "{}{}" , name, gen_args( path. segments. last( ) . unwrap( ) ) ) ) ;
54
+ let path_segment = path. segments . last ( ) . unwrap ( ) ;
55
+ return Some ( format ! ( "{}{}" , name, gen_args( cx, path_segment) ) ) ;
55
56
}
56
57
Res :: SelfTy ( None , Some ( ( did, _) ) ) => {
57
58
if let ty:: Adt ( adt, substs) = cx. tcx . type_of ( did) . kind ( ) {
58
59
if cx. tcx . has_attr ( adt. did , sym:: rustc_pass_by_value) {
59
- let name = cx. tcx . item_name ( adt. did ) . to_ident_string ( ) ;
60
- let param =
61
- substs. first ( ) . map ( |s| format ! ( "<{}>" , s) ) . unwrap_or ( "" . to_string ( ) ) ;
62
- return Some ( format ! ( "{}{}" , name, param) ) ;
60
+ return Some ( cx. tcx . def_path_str_with_substs ( adt. did , substs) ) ;
63
61
}
64
62
}
65
63
}
@@ -70,22 +68,29 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
70
68
None
71
69
}
72
70
73
- fn gen_args ( segment : & PathSegment < ' _ > ) -> String {
71
+ fn gen_args ( cx : & LateContext < ' _ > , segment : & PathSegment < ' _ > ) -> String {
74
72
if let Some ( args) = & segment. args {
75
- let lifetimes = args
73
+ let params = args
76
74
. args
77
75
. iter ( )
78
- . filter_map ( |arg| {
79
- if let GenericArg :: Lifetime ( lt) = arg {
80
- Some ( lt. name . ident ( ) . to_string ( ) )
81
- } else {
82
- None
76
+ . filter_map ( |arg| match arg {
77
+ GenericArg :: Lifetime ( lt) => Some ( lt. name . ident ( ) . to_string ( ) ) ,
78
+ GenericArg :: Type ( ty) => {
79
+ let snippet =
80
+ cx. tcx . sess . source_map ( ) . span_to_snippet ( ty. span ) . unwrap_or_default ( ) ;
81
+ Some ( snippet)
83
82
}
83
+ GenericArg :: Const ( c) => {
84
+ let snippet =
85
+ cx. tcx . sess . source_map ( ) . span_to_snippet ( c. span ) . unwrap_or_default ( ) ;
86
+ Some ( snippet)
87
+ }
88
+ _ => None ,
84
89
} )
85
90
. collect :: < Vec < _ > > ( ) ;
86
91
87
- if !lifetimes . is_empty ( ) {
88
- return format ! ( "<{}>" , lifetimes . join( ", " ) ) ;
92
+ if !params . is_empty ( ) {
93
+ return format ! ( "<{}>" , params . join( ", " ) ) ;
89
94
}
90
95
}
91
96
0 commit comments