Rollup merge of #84404 - tmiasko:intrinsics-in-coercion-lub, r=Mark-Simulacrum
Check for intrinsics before coercing to a function pointer Return an error if coercing function items / non-capturing closures to a common function pointer type would require reifying an intrinsic. Turns ICE reported in #84297 into a proper error.
This commit is contained in:
commit
f180c1e05d
3 changed files with 26 additions and 1 deletions
|
@ -973,6 +973,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let (Some(a_sig), Some(b_sig)) = (a_sig, b_sig) {
|
if let (Some(a_sig), Some(b_sig)) = (a_sig, b_sig) {
|
||||||
|
// Intrinsics are not coercible to function pointers.
|
||||||
|
if a_sig.abi() == Abi::RustIntrinsic
|
||||||
|
|| a_sig.abi() == Abi::PlatformIntrinsic
|
||||||
|
|| b_sig.abi() == Abi::RustIntrinsic
|
||||||
|
|| b_sig.abi() == Abi::PlatformIntrinsic
|
||||||
|
{
|
||||||
|
return Err(TypeError::IntrinsicCast);
|
||||||
|
}
|
||||||
// The signature must match.
|
// The signature must match.
|
||||||
let a_sig = self.normalize_associated_types_in(new.span, a_sig);
|
let a_sig = self.normalize_associated_types_in(new.span, a_sig);
|
||||||
let b_sig = self.normalize_associated_types_in(new.span, b_sig);
|
let b_sig = self.normalize_associated_types_in(new.span, b_sig);
|
||||||
|
|
|
@ -12,4 +12,12 @@ fn b() {
|
||||||
//~^ ERROR casting
|
//~^ ERROR casting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn c() {
|
||||||
|
let _ = [
|
||||||
|
std::intrinsics::copy_nonoverlapping::<i32>,
|
||||||
|
std::intrinsics::copy::<i32>,
|
||||||
|
//~^ ERROR cannot coerce
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -19,7 +19,16 @@ error[E0606]: casting `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_,
|
||||||
LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize) -> usize;
|
LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize) -> usize;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error[E0308]: cannot coerce intrinsics to function pointers
|
||||||
|
--> $DIR/reify-intrinsic.rs:18:9
|
||||||
|
|
|
||||||
|
LL | std::intrinsics::copy::<i32>,
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
|
||||||
|
|
|
||||||
|
= note: expected type `unsafe extern "rust-intrinsic" fn(_, _, _) {copy_nonoverlapping::<i32>}`
|
||||||
|
found fn item `unsafe extern "rust-intrinsic" fn(_, _, _) {std::intrinsics::copy::<i32>}`
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0308, E0606.
|
Some errors have detailed explanations: E0308, E0606.
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
For more information about an error, try `rustc --explain E0308`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue