File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -331,8 +331,9 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
331
331
if let Some ( def_id) = cx. qpath_res( qpath, path_expr. hir_id) . opt_def_id( ) ;
332
332
if match_def_path( cx, def_id, & paths:: TRANSMUTE ) ;
333
333
then {
334
- // Avoid suggesting from/to bits in const contexts.
334
+ // Avoid suggesting from/to bits and dereferencing raw pointers in const contexts.
335
335
// See https://github.com/rust-lang/rust/issues/73736 for progress on making them `const fn`.
336
+ // And see https://github.com/rust-lang/rust/issues/51911 for dereferencing raw pointers.
336
337
let const_context = in_constant( cx, e. hir_id) ;
337
338
338
339
let from_ty = cx. typeck_results( ) . expr_ty( & args[ 0 ] ) ;
@@ -486,7 +487,8 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
486
487
Applicability :: Unspecified ,
487
488
) ;
488
489
} else {
489
- if cx. tcx. erase_regions( & from_ty) != cx. tcx. erase_regions( & to_ty) {
490
+ if ( cx. tcx. erase_regions( & from_ty) != cx. tcx. erase_regions( & to_ty) )
491
+ && !const_context {
490
492
span_lint_and_then(
491
493
cx,
492
494
TRANSMUTE_PTR_TO_PTR ,
Original file line number Diff line number Diff line change @@ -51,4 +51,12 @@ fn transmute_ptr_to_ptr() {
51
51
let _: & GenericParam < & LifetimeParam < ' static > > = unsafe { std:: mem:: transmute ( & GenericParam { t : & lp } ) } ;
52
52
}
53
53
54
+ // dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959)
55
+ const _: & ( ) = {
56
+ struct ZST ;
57
+ let zst = & ZST ;
58
+
59
+ unsafe { std:: mem:: transmute :: < & ' static ZST , & ' static ( ) > ( zst) }
60
+ } ;
61
+
54
62
fn main ( ) { }
You can’t perform that action at this time.
0 commit comments