Skip to content

Commit 29d3e49

Browse files
committed
remove expect() in unnecessary_transmutes
1 parent 862156d commit 29d3e49

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'a, 'tcx> UnnecessaryTransmuteChecker<'a, 'tcx> {
2727
fn is_unnecessary_transmute(
2828
&self,
2929
function: &Operand<'tcx>,
30-
arg: String,
30+
arg: &str,
3131
span: Span,
3232
) -> Option<Error> {
3333
let fn_sig = function.ty(self.body, self.tcx).fn_sig(self.tcx).skip_binder();
@@ -89,7 +89,7 @@ impl<'tcx> Visitor<'tcx> for UnnecessaryTransmuteChecker<'_, 'tcx> {
8989
&& let span = self.body.source_info(location).span
9090
&& let Some(lint) = self.is_unnecessary_transmute(
9191
func,
92-
self.tcx.sess.source_map().span_to_snippet(arg).expect("ok"),
92+
self.tcx.sess.source_map().span_to_snippet(arg).as_deref().unwrap_or("…"),
9393
span,
9494
)
9595
&& let Some(hir_id) = terminator.source_info.scope.lint_root(&self.body.source_scopes)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ compile-flags: --remap-path-prefix=/=/non-existent
2+
3+
#[macro_export]
4+
macro_rules! transmute {
5+
($e:expr) => {{
6+
let e = $e;
7+
std::mem::transmute(e)
8+
}};
9+
}

tests/ui/transmute/issue-140277.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ aux-crate: zerocopy=issue-140277-trans.rs
2+
//@ check-pass
3+
4+
fn bytes_at_home(x: [u8; 4]) -> u32 {
5+
unsafe { zerocopy::transmute!(x) }
6+
}
7+
fn main() {}

0 commit comments

Comments
 (0)