about summary refs log tree commit diff
path: root/src/test/run-pass
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-02-10 19:52:04 +0000
committerbors <bors@rust-lang.org>2015-02-10 19:52:04 +0000
commitbc87efef2cceaec99d30e809cac2b8d22b9e25fc (patch)
tree1f59e50bc58a426615cc15594cade8b69f24bdbf /src/test/run-pass
parent88d8ba5ab3b1d22288b021708c3d87464e43b880 (diff)
parent3e10785e21b731d536cf9ad9b911e8261862bde7 (diff)
downloadrust-bc87efef2cceaec99d30e809cac2b8d22b9e25fc.tar.gz
rust-bc87efef2cceaec99d30e809cac2b8d22b9e25fc.zip
Auto merge of #22153 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/test/run-pass')
-rw-r--r--src/test/run-pass/cfg-attr-cfg.rs15
-rw-r--r--src/test/run-pass/cfg-attr-crate.rs15
-rw-r--r--src/test/run-pass/infer-container-across-object-cast.rs59
-rw-r--r--src/test/run-pass/unboxed-closures-infer-upvar.rs22
4 files changed, 111 insertions, 0 deletions
diff --git a/src/test/run-pass/cfg-attr-cfg.rs b/src/test/run-pass/cfg-attr-cfg.rs
new file mode 100644
index 00000000000..09ab7019486
--- /dev/null
+++ b/src/test/run-pass/cfg-attr-cfg.rs
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+// main is conditionally compiled, but the conditional compilation
+// is conditional too!
+
+#[cfg_attr(foo, cfg(bar))]
+fn main() { }
diff --git a/src/test/run-pass/cfg-attr-crate.rs b/src/test/run-pass/cfg-attr-crate.rs
new file mode 100644
index 00000000000..e6bd8afad28
--- /dev/null
+++ b/src/test/run-pass/cfg-attr-crate.rs
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044
+
+#![cfg_attr(not_used, no_std)]
+
+fn main() { }
diff --git a/src/test/run-pass/infer-container-across-object-cast.rs b/src/test/run-pass/infer-container-across-object-cast.rs
new file mode 100644
index 00000000000..979e76b1ff9
--- /dev/null
+++ b/src/test/run-pass/infer-container-across-object-cast.rs
@@ -0,0 +1,59 @@
+// Copyright 2015 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.
+
+// Given `<expr> as Box<Trait>`, we should be able to infer that a
+// `Box<_>` is the expected type.
+
+trait Foo { fn foo(&self) -> u32; }
+impl Foo for u32 { fn foo(&self) -> u32 { *self } }
+
+// (another impl to ensure trait-matching cannot just choose from a singleton set)
+impl Foo for  () { fn foo(&self) -> u32 { -176 } }
+
+trait Boxed { fn make() -> Self; }
+impl Boxed for Box<u32> { fn make() -> Self { Box::new(7) } }
+
+// (another impl to ensure trait-matching cannot just choose from a singleton set)
+impl Boxed for () { fn make() -> Self { () } }
+
+fn boxed_foo() {
+    let b7 = Boxed::make() as Box<Foo>;
+    assert_eq!(b7.foo(), 7);
+}
+
+trait Refed<'a,T> { fn make(&'a T) -> Self; }
+impl<'a> Refed<'a, u32> for &'a u32 { fn make(x: &'a u32) -> Self { x } }
+
+// (another impl to ensure trait-matching cannot just choose from a singleton set)
+impl<'a,'b> Refed<'a, ()> for &'b () { fn make(_: &'a ()) -> Self { static U: () = (); &U } }
+
+fn refed_foo() {
+    let a = 8;
+    let b7 = Refed::make(&a) as &Foo;
+    assert_eq!(b7.foo(), 8);
+}
+
+fn check_subtyping_works() {
+    fn inner<'short, 'long:'short>(_s: &'short u32,
+                                   l: &'long u32) -> &'short (Foo+'short) {
+        Refed::make(l) as &Foo
+    }
+
+    let a = 9;
+    let b = 10;
+    let r = inner(&b, &a);
+    assert_eq!(r.foo(), 9);
+}
+
+pub fn main() {
+    boxed_foo();
+    refed_foo();
+    check_subtyping_works();
+}
diff --git a/src/test/run-pass/unboxed-closures-infer-upvar.rs b/src/test/run-pass/unboxed-closures-infer-upvar.rs
new file mode 100644
index 00000000000..087ef5dcf05
--- /dev/null
+++ b/src/test/run-pass/unboxed-closures-infer-upvar.rs
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+
+// Test that the type variable in the type(`Vec<_>`) of a closed over
+// variable does not interfere with type inference.
+
+fn f<F: FnMut()>(mut f: F) {
+    f();
+}
+
+fn main() {
+    let mut v: Vec<_> = vec![];
+    f(|| v.push(0));
+    assert_eq!(v, vec![0]);
+}