-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow reifying intrinsics to
fn
pointers.
- Loading branch information
1 parent
3baa20b
commit c9bb59a
Showing
11 changed files
with
126 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
//@ check-fail | ||
//@ run-pass | ||
|
||
#![feature(core_intrinsics, intrinsics)] | ||
|
||
fn a() { | ||
let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = std::mem::transmute; | ||
//~^ ERROR cannot coerce | ||
// NOTE(eddyb) `#[inline(never)]` and returning `fn` pointers from functions is | ||
// done to force codegen (of the reification-to-`fn`-ptr shims around intrinsics). | ||
|
||
#[inline(never)] | ||
fn a() -> unsafe fn(isize) -> usize { | ||
let f: unsafe fn(isize) -> usize = std::mem::transmute; | ||
f | ||
} | ||
|
||
fn b() { | ||
let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize) -> usize; | ||
//~^ ERROR casting | ||
#[inline(never)] | ||
fn b() -> unsafe fn(isize) -> usize { | ||
let f = std::mem::transmute as unsafe fn(isize) -> usize; | ||
f | ||
} | ||
|
||
fn c() { | ||
let _: [unsafe extern "rust-intrinsic" fn(bool) -> bool; 2] = [ | ||
std::intrinsics::likely, //~ ERROR cannot coerce | ||
#[inline(never)] | ||
fn c() -> [fn(bool) -> bool; 2] { | ||
let fs = [ | ||
std::intrinsics::likely, | ||
std::intrinsics::unlikely, | ||
]; | ||
fs | ||
} | ||
|
||
fn main() {} | ||
fn main() { | ||
unsafe { | ||
assert_eq!(a()(-1), !0); | ||
assert_eq!(b()(-1), !0); | ||
} | ||
|
||
let [likely_ptr, unlikely_ptr] = c(); | ||
assert!(likely_ptr(true)); | ||
assert!(unlikely_ptr(true)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//@ normalize-stderr-test "\d+ bits" -> "N bits" | ||
|
||
// Tests that `transmute` cannot be indirectly called on types of different size. | ||
|
||
#![allow(warnings)] | ||
#![feature(specialization)] | ||
|
||
use std::mem::transmute; | ||
|
||
unsafe fn f() { | ||
let _: i8 = (transmute as unsafe fn(_) -> _)(16i16); | ||
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types | ||
} | ||
|
||
unsafe fn g<T>(x: &T) { | ||
let _: i8 = (transmute as unsafe fn(_) -> _)(x); | ||
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types | ||
} | ||
|
||
trait Specializable { type Output; } | ||
|
||
impl<T> Specializable for T { | ||
default type Output = u16; | ||
} | ||
|
||
unsafe fn specializable<T>(x: u16) -> <T as Specializable>::Output { | ||
(transmute as unsafe fn(_) -> _)(x) | ||
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types | ||
} | ||
|
||
fn main() {} |
30 changes: 30 additions & 0 deletions
30
tests/ui/transmute/transmute-different-sizes-reified.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types | ||
--> $DIR/transmute-different-sizes-reified.rs:11:18 | ||
| | ||
LL | let _: i8 = (transmute as unsafe fn(_) -> _)(16i16); | ||
| ^^^^^^^^^ | ||
| | ||
= note: source type: `i16` (N bits) | ||
= note: target type: `i8` (N bits) | ||
|
||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types | ||
--> $DIR/transmute-different-sizes-reified.rs:16:18 | ||
| | ||
LL | let _: i8 = (transmute as unsafe fn(_) -> _)(x); | ||
| ^^^^^^^^^ | ||
| | ||
= note: source type: `&T` (N bits) | ||
= note: target type: `i8` (N bits) | ||
|
||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types | ||
--> $DIR/transmute-different-sizes-reified.rs:27:6 | ||
| | ||
LL | (transmute as unsafe fn(_) -> _)(x) | ||
| ^^^^^^^^^ | ||
| | ||
= note: source type: `u16` (N bits) | ||
= note: target type: `<T as Specializable>::Output` (this type does not have a fixed size) | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0512`. |