]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/unboxed-closures-unique-type-id.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / unboxed-closures-unique-type-id.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 //
11 // This code used to produce the following ICE:
12 //
13 //    error: internal compiler error: get_unique_type_id_of_type() -
14 //    unexpected type: closure,
15 //    ty_unboxed_closure(syntax::ast::DefId{krate: 0u32, node: 66u32},
16 //    ReScope(63u32))
17 //
18 // This is a regression test for issue #17021.
19 //
20 // compile-flags: -g
21
22 #![feature(unboxed_closures)]
23
24 use std::ptr;
25
26 pub fn replace_map<'a, T, F>(src: &mut T, prod: F) where F: FnOnce(T) -> T {
27     unsafe { *src = prod(ptr::read(src as *mut T as *const T)); }
28 }
29
30 pub fn main() {
31     let mut a = 7u;
32     let b = &mut a;
33     replace_map(b, |: x: uint| x * 2);
34     assert_eq!(*b, 14u);
35 }