Skip to content

Commit

Permalink
Fix checking transmutes with adjusted types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Mar 16, 2022
1 parent 911e105 commit dc045f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/transmute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
// And see https://github.com/rust-lang/rust/issues/51911 for dereferencing raw pointers.
let const_context = in_constant(cx, e.hir_id);

let from_ty = cx.typeck_results().expr_ty(arg);
let from_ty = cx.typeck_results().expr_ty_adjusted(arg);
// Adjustments for `to_ty` happen after the call to `transmute`, so don't use them.
let to_ty = cx.typeck_results().expr_ty(e);

// If useless_transmute is triggered, the other lints can be skipped.
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/transmute_undefined_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,7 @@ fn main() {

let _: MaybeUninit<Ty2<u32, u32>> = transmute(value::<Ty2<u32, u32>>()); // Ok
let _: Ty2<u32, u32> = transmute(value::<MaybeUninit<Ty2<u32, u32>>>()); // Ok

let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec<u32>>()); // Ok
}
}

0 comments on commit dc045f2

Please sign in to comment.