Skip to content

Commit fc2dbbb

Browse files
authored
Rollup merge of #123526 - estebank:issue-123442, r=compiler-errors
Do not ICE when calling incorrectly defined `transmute` intrinsic Fix #123442
2 parents ad3df49 + aa53bc0 commit fc2dbbb

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
544544
if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
545545
&& tcx.item_name(did) == sym::transmute
546546
{
547-
let from = fn_sig.inputs().skip_binder()[0];
547+
let Some(from) = fn_sig.inputs().skip_binder().get(0) else {
548+
let e = self.dcx().span_delayed_bug(
549+
tcx.def_span(did),
550+
"intrinsic fn `transmute` defined with no parameters",
551+
);
552+
self.set_tainted_by_errors(e);
553+
return Ty::new_error(tcx, e);
554+
};
548555
let to = fn_sig.output().skip_binder();
549556
// We defer the transmute to the end of typeck, once all inference vars have
550557
// been resolved or we errored. This is important as we can only check transmute
551558
// on concrete types, but the output type may not be known yet (it would only
552559
// be known if explicitly specified via turbofish).
553-
self.deferred_transmute_checks.borrow_mut().push((from, to, expr.hir_id));
560+
self.deferred_transmute_checks.borrow_mut().push((*from, to, expr.hir_id));
554561
}
555562
if !tcx.features().unsized_fn_params {
556563
// We want to remove some Sized bounds from std functions,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
transmute(); // does not ICE
3+
}
4+
5+
extern "rust-intrinsic" fn transmute() {}
6+
//~^ ERROR intrinsic has wrong number of type parameters: found 0, expected 2
7+
//~| ERROR intrinsics are subject to change
8+
//~| ERROR intrinsic must be in `extern "rust-intrinsic" { ... }` block
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0658]: intrinsics are subject to change
2+
--> $DIR/incorrect-transmute.rs:5:8
3+
|
4+
LL | extern "rust-intrinsic" fn transmute() {}
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(intrinsics)]` to the crate attributes to enable
8+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9+
10+
error[E0094]: intrinsic has wrong number of type parameters: found 0, expected 2
11+
--> $DIR/incorrect-transmute.rs:5:37
12+
|
13+
LL | extern "rust-intrinsic" fn transmute() {}
14+
| ^ expected 2 type parameters
15+
16+
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
17+
--> $DIR/incorrect-transmute.rs:5:40
18+
|
19+
LL | extern "rust-intrinsic" fn transmute() {}
20+
| ^^
21+
22+
error: aborting due to 3 previous errors
23+
24+
Some errors have detailed explanations: E0094, E0658.
25+
For more information about an error, try `rustc --explain E0094`.

0 commit comments

Comments
 (0)