@@ -361,9 +361,8 @@ declare_lint! {
361
361
/// ```rust
362
362
/// x.clone()
363
363
/// ```
364
- declare_lint ! {
364
+ declare_restriction_lint ! {
365
365
pub CLONE_ON_REF_PTR ,
366
- Warn ,
367
366
"using 'clone' on a ref-counted pointer"
368
367
}
369
368
@@ -1013,24 +1012,26 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
1013
1012
fn lint_clone_on_ref_ptr ( cx : & LateContext , expr : & hir:: Expr , arg : & hir:: Expr ) {
1014
1013
let ( obj_ty, _) = walk_ptrs_ty_depth ( cx. tables . expr_ty ( arg) ) ;
1015
1014
1016
- let caller_type = if match_type ( cx, obj_ty, & paths:: RC ) {
1017
- "Rc"
1018
- } else if match_type ( cx, obj_ty, & paths:: ARC ) {
1019
- "Arc"
1020
- } else if match_type ( cx, obj_ty, & paths:: WEAK_RC ) || match_type ( cx, obj_ty, & paths:: WEAK_ARC ) {
1021
- "Weak"
1022
- } else {
1023
- return ;
1024
- } ;
1015
+ if let ty:: TyAdt ( _, subst) = obj_ty. sty {
1016
+ let caller_type = if match_type ( cx, obj_ty, & paths:: RC ) {
1017
+ "Rc"
1018
+ } else if match_type ( cx, obj_ty, & paths:: ARC ) {
1019
+ "Arc"
1020
+ } else if match_type ( cx, obj_ty, & paths:: WEAK_RC ) || match_type ( cx, obj_ty, & paths:: WEAK_ARC ) {
1021
+ "Weak"
1022
+ } else {
1023
+ return ;
1024
+ } ;
1025
1025
1026
- span_lint_and_sugg (
1027
- cx,
1028
- CLONE_ON_REF_PTR ,
1029
- expr. span ,
1030
- "using '.clone()' on a ref-counted pointer" ,
1031
- "try this" ,
1032
- format ! ( "{}::clone(&{})" , caller_type, snippet( cx, arg. span, "_" ) ) ,
1033
- ) ;
1026
+ span_lint_and_sugg (
1027
+ cx,
1028
+ CLONE_ON_REF_PTR ,
1029
+ expr. span ,
1030
+ "using '.clone()' on a ref-counted pointer" ,
1031
+ "try this" ,
1032
+ format ! ( "{}<{}>::clone(&{})" , caller_type, subst. type_at( 0 ) , snippet( cx, arg. span, "_" ) ) ,
1033
+ ) ;
1034
+ }
1034
1035
}
1035
1036
1036
1037
0 commit comments