]> git.lizzy.rs Git - rust.git/blob - tests/ui/functions-closures/fn-item-type-cast.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / functions-closures / fn-item-type-cast.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // Test explicit coercions from a fn item type to a fn pointer type.
5
6
7 fn foo(x: isize) -> isize { x * 2 }
8 fn bar(x: isize) -> isize { x * 4 }
9 type IntMap = fn(isize) -> isize;
10
11 fn eq<T>(x: T, y: T) { }
12
13 static TEST: Option<IntMap> = Some(foo as IntMap);
14
15 fn main() {
16     let f = foo as IntMap;
17
18     let f = if true { foo as IntMap } else { bar as IntMap };
19     assert_eq!(f(4), 8);
20
21     eq(foo as IntMap, bar as IntMap);
22 }