diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-03-17 15:22:11 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-03-17 17:29:07 -0400 |
| commit | 0947f4076ddbf5c0db63d60c19f28b6b79023638 (patch) | |
| tree | cd4568b62d70c02218711c0fe73d2b1ebf0aef56 /src/test/run-pass | |
| parent | 1b0f0ad28070c072f68ea0ab10bbae61b52706a8 (diff) | |
| download | rust-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.rs | 25 |
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); +} |
