Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typeck: Disallow scalar casts to bare_fn.
Bare functions are another example of a scalar but non-numeric type (like char) that should be handled separately in casts. This disallows expressions like `0 as extern "Rust" fn() -> int;`. It might be advantageous to allow casts between bare functions and raw pointers in unsafe code in the future, to pass function pointers between Rust and C. Closes #8728
- Loading branch information
Showing
3 changed files
with
38 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn foo(_x: int) { } | ||
|
||
#[fixed_stack_segment] | ||
fn main() { | ||
let v: u64 = 5; | ||
let x = foo as extern "C" fn() -> int; | ||
//~^ ERROR non-scalar cast | ||
let y = v as extern "Rust" fn(int) -> (int, int); | ||
//~^ ERROR non-scalar cast | ||
y(x()); | ||
} |
e538c95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pnkfelix
at https://github.com/geoffhill/rust/commit/e538c95e4d5c7df475772639e983770e6425da32
e538c95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging geoffhill/rust/bare-fn-cast = e538c95 into auto
e538c95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
geoffhill/rust/bare-fn-cast = e538c95 merged ok, testing candidate = af62adf
e538c95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/2467
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/313
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/313
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/2471
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1577
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1576
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/2485
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1577
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1577
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/2486
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1577
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1577
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/1653
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/2471
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/1575
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/1577
success: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2249
e538c95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = af62adf