@@ -2,7 +2,6 @@ use crate::{LateContext, LateLintPass, LintContext};
2
2
use rustc_errors:: Applicability ;
3
3
use rustc_hir as hir;
4
4
use rustc_hir:: def:: Res ;
5
- use rustc_hir:: def_id:: DefId ;
6
5
use rustc_hir:: { GenericArg , PathSegment , QPath , TyKind } ;
7
6
use rustc_middle:: ty;
8
7
use rustc_span:: symbol:: sym;
@@ -50,15 +49,17 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
50
49
fn path_for_pass_by_value ( cx : & LateContext < ' _ > , ty : & hir:: Ty < ' _ > ) -> Option < String > {
51
50
if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = & ty. kind {
52
51
match path. res {
53
- Res :: Def ( _, def_id) if has_pass_by_value_attr ( cx , def_id ) => {
52
+ Res :: Def ( _, def_id) if cx . tcx . has_attr ( def_id , sym :: rustc_pass_by_value ) => {
54
53
let name = cx. tcx . item_name ( def_id) . to_ident_string ( ) ;
55
54
return Some ( format ! ( "{}{}" , name, gen_args( path. segments. last( ) . unwrap( ) ) ) ) ;
56
55
}
57
56
Res :: SelfTy ( None , Some ( ( did, _) ) ) => {
58
57
if let ty:: Adt ( adt, substs) = cx. tcx . type_of ( did) . kind ( ) {
59
- if has_pass_by_value_attr ( cx , adt. did ) {
58
+ if cx . tcx . has_attr ( adt. did , sym :: rustc_pass_by_value ) {
60
59
let name = cx. tcx . item_name ( adt. did ) . to_ident_string ( ) ;
61
- return Some ( format ! ( "{}<{}>" , name, substs[ 0 ] ) ) ;
60
+ let param =
61
+ substs. first ( ) . map ( |s| format ! ( "<{}>" , s) ) . unwrap_or ( "" . to_string ( ) ) ;
62
+ return Some ( format ! ( "{}{}" , name, param) ) ;
62
63
}
63
64
}
64
65
}
@@ -69,15 +70,6 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
69
70
None
70
71
}
71
72
72
- fn has_pass_by_value_attr ( cx : & LateContext < ' _ > , def_id : DefId ) -> bool {
73
- for attr in cx. tcx . get_attrs ( def_id) . iter ( ) {
74
- if attr. has_name ( sym:: rustc_pass_by_value) {
75
- return true ;
76
- }
77
- }
78
- false
79
- }
80
-
81
73
fn gen_args ( segment : & PathSegment < ' _ > ) -> String {
82
74
if let Some ( args) = & segment. args {
83
75
let lifetimes = args
0 commit comments