1
Fork 0

Two more tests

This commit is contained in:
est31 2017-02-23 22:31:21 +01:00
parent f753a6ef02
commit 21c38988f4
2 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,24 @@
// Copyright 2017 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.
// Ensure that capturing closures are never coerced to fns
// Especially interesting as non-capturing closures can be.
fn main() {
let mut a = 0u8;
let foo :fn(u8) -> u8 = |v: u8| { a += v; a };
//~^ ERROR mismatched types
let b = 0u8;
let bar :fn() -> u8 = || { b };
//~^ ERROR mismatched types
let baz :fn() -> u8 = || { b } as fn() -> u8;
//~^ ERROR mismatched types
//~^^ ERROR non-scalar cast
}

View file

@ -0,0 +1,45 @@
// Copyright 2017 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.
// ignore-stage0: new feature, remove this when SNAP
// revisions: a b
#[cfg(a)]
mod a {
const FOO :fn(u8) -> u8 = |v: u8| { v };
//[a]~^ ERROR non-capturing closure to fn coercion is experimental
//[a]~^^ ERROR mismatched types
const BAR: [fn(&mut u32); 1] = [
|v: &mut u32| *v += 1,
//[a]~^ ERROR non-capturing closure to fn coercion is experimental
//[a]~^^ ERROR mismatched types
];
}
#[cfg(b)]
mod b {
fn func_specific() -> (fn() -> u32) {
|| return 42
//[b]~^ ERROR non-capturing closure to fn coercion is experimental
//[b]~^^ ERROR mismatched types
}
fn foo() {
// Items
assert_eq!(func_specific()(), 42);
let foo :fn(u8) -> u8 = |v: u8| { v };
//[b]~^ ERROR non-capturing closure to fn coercion is experimental
//[b]~^^ ERROR mismatched types
}
}