about summary refs log tree commit diff
path: root/src/test/run-pass
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-03-20 15:58:10 +0000
committerbors <bors@rust-lang.org>2017-03-20 15:58:10 +0000
commit134c4a0f08a3d1f55ea8968fbe728fa935c71698 (patch)
treef965ee88718069e91c5398a6084d33c64f4c03dc /src/test/run-pass
parent244f893ed704a60841d4615445d540a21a8d7722 (diff)
parent5dc8548050514b0781af7b21a4706552da18dd50 (diff)
downloadrust-134c4a0f08a3d1f55ea8968fbe728fa935c71698.tar.gz
rust-134c4a0f08a3d1f55ea8968fbe728fa935c71698.zip
Auto merge of #39628 - arielb1:shimmir, r=eddyb
Translate shims using MIR

This removes one large remaining part of old trans.
Diffstat (limited to 'src/test/run-pass')
-rw-r--r--src/test/run-pass/issue-29948.rs17
-rw-r--r--src/test/run-pass/mir_calls_to_shims.rs56
2 files changed, 72 insertions, 1 deletions
diff --git a/src/test/run-pass/issue-29948.rs b/src/test/run-pass/issue-29948.rs
index ec2b53313fa..281dde15bd3 100644
--- a/src/test/run-pass/issue-29948.rs
+++ b/src/test/run-pass/issue-29948.rs
@@ -8,6 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::panic;
+
+impl<'a> panic::UnwindSafe for Foo<'a> {}
+impl<'a> panic::RefUnwindSafe for Foo<'a> {}
+
 struct Foo<'a>(&'a mut bool);
 
 impl<'a> Drop for Foo<'a> {
@@ -28,5 +33,15 @@ fn main() {
         f(x);
     }
     assert!(ran_drop);
-}
 
+    let mut ran_drop = false;
+    {
+        let x = Foo(&mut ran_drop);
+        let result = panic::catch_unwind(move || {
+            let x = move || { let _ = x; panic!() };
+            f(x);
+        });
+        assert!(result.is_err());
+    }
+    assert!(ran_drop);
+}
diff --git a/src/test/run-pass/mir_calls_to_shims.rs b/src/test/run-pass/mir_calls_to_shims.rs
new file mode 100644
index 00000000000..7300a322ec4
--- /dev/null
+++ b/src/test/run-pass/mir_calls_to_shims.rs
@@ -0,0 +1,56 @@
+// Copyright 2016 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.
+
+#![feature(fn_traits)]
+#![feature(never_type)]
+
+use std::panic;
+
+fn foo(x: u32, y: u32) -> u32 { x/y }
+fn foo_diverges() -> ! { panic!() }
+
+fn test_fn_ptr<T>(mut t: T)
+    where T: Fn(u32, u32) -> u32,
+{
+    let as_fn = <T as Fn<(u32, u32)>>::call;
+    assert_eq!(as_fn(&t, (9, 3)), 3);
+    let as_fn_mut = <T as FnMut<(u32, u32)>>::call_mut;
+    assert_eq!(as_fn_mut(&mut t, (18, 3)), 6);
+    let as_fn_once = <T as FnOnce<(u32, u32)>>::call_once;
+    assert_eq!(as_fn_once(t, (24, 3)), 8);
+}
+
+fn assert_panics<F>(f: F) where F: FnOnce() {
+    let f = panic::AssertUnwindSafe(f);
+    let result = panic::catch_unwind(move || {
+        f.0()
+    });
+    if let Ok(..) = result {
+        panic!("diverging function returned");
+    }
+}
+
+fn test_fn_ptr_panic<T>(mut t: T)
+    where T: Fn() -> !
+{
+    let as_fn = <T as Fn<()>>::call;
+    assert_panics(|| as_fn(&t, ()));
+    let as_fn_mut = <T as FnMut<()>>::call_mut;
+    assert_panics(|| as_fn_mut(&mut t, ()));
+    let as_fn_once = <T as FnOnce<()>>::call_once;
+    assert_panics(|| as_fn_once(t, ()));
+}
+
+fn main() {
+    test_fn_ptr(foo);
+    test_fn_ptr(foo as fn(u32, u32) -> u32);
+    test_fn_ptr_panic(foo_diverges);
+    test_fn_ptr_panic(foo_diverges as fn() -> !);
+}