@@ -192,7 +192,7 @@ declare_clippy_lint! {
192
192
declare_clippy_lint ! {
193
193
pub TRANSMUTE_PTR_TO_PTR ,
194
194
complexity,
195
- "transmutes from a pointer to a reference type "
195
+ "transmutes from a pointer to a pointer / a reference to a reference "
196
196
}
197
197
198
198
pub struct Transmute ;
@@ -363,23 +363,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
363
363
}
364
364
)
365
365
} else {
366
- span_lint_and_then(
367
- cx,
368
- TRANSMUTE_PTR_TO_PTR ,
369
- e. span,
370
- "transmute from a reference to a reference" ,
371
- |db| if let Some ( arg) = sugg:: Sugg :: hir_opt( cx, & args[ 0 ] ) {
372
- let ty_from_and_mut = ty:: TypeAndMut { ty: ty_from, mutbl: from_mutbl } ;
373
- let ty_to_and_mut = ty:: TypeAndMut { ty: ty_to, mutbl: to_mutbl } ;
374
- let sugg_paren = arg. as_ty( cx. tcx. mk_ptr( ty_from_and_mut) ) . as_ty( cx. tcx. mk_ptr( ty_to_and_mut) ) ;
375
- let sugg = if to_mutbl == Mutability :: MutMutable {
376
- sugg_paren. mut_addr_deref( )
377
- } else {
378
- sugg_paren. addr_deref( )
379
- } ;
380
- db. span_suggestion( e. span, "try" , sugg. to_string( ) ) ;
381
- } ,
382
- )
366
+ // In this case they differ only in lifetime
367
+ if ty_from != ty_to {
368
+ span_lint_and_then(
369
+ cx,
370
+ TRANSMUTE_PTR_TO_PTR ,
371
+ e. span,
372
+ "transmute from a reference to a reference" ,
373
+ |db| if let Some ( arg) = sugg:: Sugg :: hir_opt( cx, & args[ 0 ] ) {
374
+ let ty_from_and_mut = ty:: TypeAndMut { ty: ty_from, mutbl: from_mutbl } ;
375
+ let ty_to_and_mut = ty:: TypeAndMut { ty: ty_to, mutbl: to_mutbl } ;
376
+ let sugg_paren = arg. as_ty( cx. tcx. mk_ptr( ty_from_and_mut) ) . as_ty( cx. tcx. mk_ptr( ty_to_and_mut) ) ;
377
+ let sugg = if to_mutbl == Mutability :: MutMutable {
378
+ sugg_paren. mut_addr_deref( )
379
+ } else {
380
+ sugg_paren. addr_deref( )
381
+ } ;
382
+ db. span_suggestion( e. span, "try" , sugg. to_string( ) ) ;
383
+ } ,
384
+ )
385
+ }
383
386
}
384
387
}
385
388
} ,
0 commit comments