Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ impl<'tcx> Visitor<'tcx> for UnnecessaryTransmuteChecker<'_, 'tcx> {
&& let Some((func_def_id, _)) = func.const_fn_def()
&& self.tcx.is_intrinsic(func_def_id, sym::transmute)
&& let span = self.body.source_info(location).span
&& let Some(lint) = self.is_unnecessary_transmute(
func,
self.tcx.sess.source_map().span_to_snippet(arg).expect("ok"),
span,
)
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(arg)
&& let Some(lint) = self.is_unnecessary_transmute(func, snippet, span)
&& let Some(hir_id) = terminator.source_info.scope.lint_root(&self.body.source_scopes)
{
self.tcx.emit_node_span_lint(UNNECESSARY_TRANSMUTES, hir_id, span, lint);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ compile-flags: --remap-path-prefix=/=/non-existent
// helper for ../unnecessary-transmute-path-remap-ice-140277.rs

#[macro_export]
macro_rules! transmute {
($e:expr) => {{
let e = $e;
std::mem::transmute(e)
}};
}
10 changes: 10 additions & 0 deletions tests/ui/transmute/unnecessary-transmute-path-remap-ice-140277.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ aux-crate: zerocopy=unnecessary-transmute-path-remap-ice-140277-trans.rs
//@ check-pass
// tests for a regression in linting for unnecessary transmutes
// where a span was inacessible for snippet procuring,
// when remap-path-prefix was set, causing a panic.

fn bytes_at_home(x: [u8; 4]) -> u32 {
unsafe { zerocopy::transmute!(x) }
}
fn main() {}
Loading