about summary refs log tree commit diff
path: root/src/test/run-pass
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-03-17 15:22:11 -0400
committerNiko Matsakis <niko@alum.mit.edu>2015-03-17 17:29:07 -0400
commit0947f4076ddbf5c0db63d60c19f28b6b79023638 (patch)
treecd4568b62d70c02218711c0fe73d2b1ebf0aef56 /src/test/run-pass
parent1b0f0ad28070c072f68ea0ab10bbae61b52706a8 (diff)
downloadrust-0947f4076ddbf5c0db63d60c19f28b6b79023638.tar.gz
rust-0947f4076ddbf5c0db63d60c19f28b6b79023638.zip
Move unsafety out of the subtyping relation and into coercion.
Diffstat (limited to 'src/test/run-pass')
-rw-r--r--src/test/run-pass/unsafe-coercion.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/run-pass/unsafe-coercion.rs b/src/test/run-pass/unsafe-coercion.rs
new file mode 100644
index 00000000000..06980e162c8
--- /dev/null
+++ b/src/test/run-pass/unsafe-coercion.rs
@@ -0,0 +1,25 @@
+// Copyright 2013-2014 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.
+
+// Check that safe fns are not a subtype of unsafe fns.
+
+fn foo(x: i32) -> i32 {
+    x * 22
+}
+
+fn bar(x: fn(i32) -> i32) -> unsafe fn(i32) -> i32 {
+    x // OK, coercion!
+}
+
+fn main() {
+    let f = bar(foo);
+    let x = unsafe { f(2) };
+    assert_eq!(x, 44);
+}