about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-04-06 01:15:31 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-04-06 01:15:31 +0000
commitaa53bc0b04cb53ca59285b48679adce0f33a4410 (patch)
treeb5a09c31ba01cda433507f34e803d73cf4fc62f5 /compiler
parent76cf07d5df52c07c3cd4cfeea1ab32b1cfba71bf (diff)
downloadrust-aa53bc0b04cb53ca59285b48679adce0f33a4410.tar.gz
rust-aa53bc0b04cb53ca59285b48679adce0f33a4410.zip
Do not ICE when calling incorrectly defined `transmute` intrinsic
Fix #123442
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index d3e6eb124f7..6d9dc098fbe 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -547,13 +547,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
                 && tcx.item_name(did) == sym::transmute
             {
-                let from = fn_sig.inputs().skip_binder()[0];
+                let Some(from) = fn_sig.inputs().skip_binder().get(0) else {
+                    let e = self.dcx().span_delayed_bug(
+                        tcx.def_span(did),
+                        "intrinsic fn `transmute` defined with no parameters",
+                    );
+                    self.set_tainted_by_errors(e);
+                    return Ty::new_error(tcx, e);
+                };
                 let to = fn_sig.output().skip_binder();
                 // We defer the transmute to the end of typeck, once all inference vars have
                 // been resolved or we errored. This is important as we can only check transmute
                 // on concrete types, but the output type may not be known yet (it would only
                 // be known if explicitly specified via turbofish).
-                self.deferred_transmute_checks.borrow_mut().push((from, to, expr.hir_id));
+                self.deferred_transmute_checks.borrow_mut().push((*from, to, expr.hir_id));
             }
             if !tcx.features().unsized_fn_params {
                 // We want to remove some Sized bounds from std functions,