diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-11-07 06:53:45 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-11-07 15:51:30 -0500 |
| commit | 244231720d29db856c5a28c0dda6c2efd7c9219a (patch) | |
| tree | 41648e7c6c16102a7a602be441b4f1cdad8e7411 /src/test | |
| parent | c18a1327e3ccf02ae9f755ca280d53177eeb298d (diff) | |
| download | rust-244231720d29db856c5a28c0dda6c2efd7c9219a.tar.gz rust-244231720d29db856c5a28c0dda6c2efd7c9219a.zip | |
Update parser with `for` syntax
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/issue-10291.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-fn-subtyping-return-static.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-fn-subtyping.rs | 24 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-name-undeclared.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-nested-fns-2.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-nested-fns.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-ret-borrowed-1.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/hrtb-parse.rs | 48 | ||||
| -rw-r--r-- | src/test/run-pass/nullable-pointer-ffi-compat.rs | 2 |
9 files changed, 74 insertions, 26 deletions
diff --git a/src/test/compile-fail/issue-10291.rs b/src/test/compile-fail/issue-10291.rs index 995ae7b3d44..924132c6de2 100644 --- a/src/test/compile-fail/issue-10291.rs +++ b/src/test/compile-fail/issue-10291.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test<'x>(x: &'x int) { - drop::< <'z>|&'z int| -> &'z int >(|z| { + drop::< for<'z>|&'z int| -> &'z int >(|z| { x //~^ ERROR cannot infer an appropriate lifetime }); diff --git a/src/test/compile-fail/regions-fn-subtyping-return-static.rs b/src/test/compile-fail/regions-fn-subtyping-return-static.rs index 4c90b1f0eea..ac56e8ce14d 100644 --- a/src/test/compile-fail/regions-fn-subtyping-return-static.rs +++ b/src/test/compile-fail/regions-fn-subtyping-return-static.rs @@ -22,11 +22,11 @@ struct S; // Given 'cx, return 'cx -type F = fn<'cx>(&'cx S) -> &'cx S; +type F = for<'cx> fn(&'cx S) -> &'cx S; fn want_F(f: F) { } // Given anything, return 'static -type G = fn<'cx>(&'cx S) -> &'static S; +type G = for<'cx> fn(&'cx S) -> &'static S; fn want_G(f: G) { } // Should meet both. diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs index 8e8d892a39f..91a6ff789ea 100644 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ b/src/test/compile-fail/regions-fn-subtyping.rs @@ -17,29 +17,29 @@ fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) { // subtype::<T1>(of::<T2>()) will typecheck // iff T1 <: T2. - subtype::< <'a>|&'a T|>( - of::< <'a>|&'a T|>()); + subtype::< for<'a>|&'a T|>( + of::< for<'a>|&'a T|>()); - subtype::< <'a>|&'a T|>( - of::< <'b>|&'b T|>()); + subtype::< for<'a>|&'a T|>( + of::< for<'b>|&'b T|>()); - subtype::< <'b>|&'b T|>( + subtype::< for<'b>|&'b T|>( of::<|&'x T|>()); subtype::<|&'x T|>( - of::< <'b>|&'b T|>()); //~ ERROR mismatched types + of::< for<'b>|&'b T|>()); //~ ERROR mismatched types - subtype::< <'a,'b>|&'a T, &'b T|>( - of::< <'a>|&'a T, &'a T|>()); + subtype::< for<'a,'b>|&'a T, &'b T|>( + of::< for<'a>|&'a T, &'a T|>()); - subtype::< <'a>|&'a T, &'a T|>( - of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types + subtype::< for<'a>|&'a T, &'a T|>( + of::< for<'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types - subtype::< <'a,'b>|&'a T, &'b T|>( + subtype::< for<'a,'b>|&'a T, &'b T|>( of::<|&'x T, &'y T|>()); subtype::<|&'x T, &'y T|>( - of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types + of::< for<'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types } fn main() {} diff --git a/src/test/compile-fail/regions-name-undeclared.rs b/src/test/compile-fail/regions-name-undeclared.rs index ba3d7bd29f4..e9e585e84d0 100644 --- a/src/test/compile-fail/regions-name-undeclared.rs +++ b/src/test/compile-fail/regions-name-undeclared.rs @@ -43,16 +43,16 @@ fn bar<'a>(x: &'a int) { // &'a CAN be declared on functions and used then: fn g<'a>(a: &'a int) { } // OK - fn h(a: <'a>|&'a int|) { } // OK + fn h(a: for<'a>|&'a int|) { } // OK } // Test nesting of lifetimes in fn type declarations fn fn_types(a: &'a int, //~ ERROR undeclared lifetime - b: <'a>|a: &'a int, - b: &'b int, //~ ERROR undeclared lifetime - c: <'b>|a: &'a int, - b: &'b int|, - d: &'b int|, //~ ERROR undeclared lifetime + b: for<'a>|a: &'a int, + b: &'b int, //~ ERROR undeclared lifetime + c: for<'b>|a: &'a int, + b: &'b int|, + d: &'b int|, //~ ERROR undeclared lifetime c: &'a int) //~ ERROR undeclared lifetime { } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index 60eae9ce80a..a08cf226389 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ignore(_f: <'z>|&'z int| -> &'z int) {} +fn ignore(_f: for<'z>|&'z int| -> &'z int) {} fn nested() { let y = 3; diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index 7dc57d37e24..cf0b615bb01 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -14,13 +14,13 @@ fn nested<'x>(x: &'x int) { let y = 3; let mut ay = &y; //~ ERROR cannot infer - ignore::< <'z>|&'z int|>(|z| { + ignore::< for<'z>|&'z int|>(|z| { ay = x; ay = &y; ay = z; }); - ignore::< <'z>|&'z int| -> &'z int>(|z| { + ignore::< for<'z>|&'z int| -> &'z int>(|z| { if false { return x; } //~ ERROR cannot infer an appropriate lifetime for automatic if false { return ay; } return z; diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index 6d9b2619171..997775efa84 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -12,7 +12,7 @@ // some point regions-ret-borrowed reported an error but this file did // not, due to special hardcoding around the anonymous region. -fn with<R>(f: <'a>|x: &'a int| -> R) -> R { +fn with<R>(f: for<'a>|x: &'a int| -> R) -> R { f(&3) } diff --git a/src/test/run-pass/hrtb-parse.rs b/src/test/run-pass/hrtb-parse.rs new file mode 100644 index 00000000000..080523f0060 --- /dev/null +++ b/src/test/run-pass/hrtb-parse.rs @@ -0,0 +1,48 @@ +// Copyright 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. + +// Test that we can parse all the various places that a `for` keyword +// can appear representing universal quantification. + +#![allow(unused_variables)] +#![allow(dead_code)] + +trait Get<A,R> { + fn get(&self, arg: A) -> R; +} + +// Parse HRTB with explicit `for` in a where-clause: + +fn foo00<T>(t: T) + where T : for<'a> Get<&'a int, &'a int> +{ +} + +fn foo01<T: for<'a> Get<&'a int, &'a int>>(t: T) +{ +} + +// Parse HRTB with explicit `for` in various sorts of types: + +fn foo10(t: Box<for<'a> Get<int, int>>) { } +fn foo11(t: Box<for<'a> Get(int) -> int>) { } + +fn foo20(t: for<'a> fn(int) -> int) { } +fn foo21(t: for<'a> unsafe fn(int) -> int) { } +fn foo22(t: for<'a> extern "C" fn(int) -> int) { } +fn foo23(t: for<'a> unsafe extern "C" fn(int) -> int) { } + +fn foo30(t: for<'a> |int| -> int) { } +fn foo31(t: for<'a> unsafe |int| -> int) { } + +//fn foo40(t: for<'a> proc(int) -> int) { } + +fn main() { +} diff --git a/src/test/run-pass/nullable-pointer-ffi-compat.rs b/src/test/run-pass/nullable-pointer-ffi-compat.rs index b5c541b0c63..32432c07dcf 100644 --- a/src/test/run-pass/nullable-pointer-ffi-compat.rs +++ b/src/test/run-pass/nullable-pointer-ffi-compat.rs @@ -29,7 +29,7 @@ static FOO: int = 0xDEADBEE; pub fn main() { unsafe { - let f: extern "C" fn<'a>(&'a int) -> &'a int = mem::transmute(foo); + let f: for<'a> extern "C" fn(&'a int) -> &'a int = mem::transmute(foo); assert_eq!(*f(&FOO), FOO); } } |
