Skip to content

Commit 55366e3

Browse files
committed
Fix error handling in check_transmutes
1 parent e614b3f commit 55366e3

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

compiler/rustc_hir_typeck/src/intrinsicck.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ fn check_transmute<'tcx>(
115115
&& let SizeSkeleton::Known(size_to, _) = sk_to
116116
&& size_to == Pointer(tcx.data_layout.instruction_address_space).size(&tcx)
117117
{
118-
struct_span_code_err!(tcx.sess.dcx(), span(), E0591, "can't transmute zero-sized type")
119-
.with_note(format!("source type: {from}"))
120-
.with_note(format!("target type: {to}"))
121-
.with_help("cast with `as` to a pointer instead")
122-
.emit();
123-
return Ok(());
118+
let err = struct_span_code_err!(
119+
tcx.sess.dcx(),
120+
span(),
121+
E0591,
122+
"can't transmute zero-sized type"
123+
)
124+
.with_note(format!("source type: {from}"))
125+
.with_note(format!("target type: {to}"))
126+
.with_help("cast with `as` to a pointer instead")
127+
.emit();
128+
return Err(err);
124129
}
125130
}
126131

@@ -150,7 +155,7 @@ pub(crate) fn check_transmutes(tcx: TyCtxt<'_>, owner: LocalDefId) -> Result<(),
150155
let typing_env = ty::TypingEnv::post_analysis(tcx, owner);
151156
let mut result = Ok(());
152157
for &(from, to, hir_id) in &typeck_results.transmutes_to_check {
153-
result = check_transmute(tcx, typing_env, from, to, hir_id);
158+
result = result.and(check_transmute(tcx, typing_env, from, to, hir_id));
154159
}
155160
result
156161
}

0 commit comments

Comments
 (0)