]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/unboxed-closures-unique-type-id.rs
Imported Upstream version 1.2.0+dfsg1
[rustc.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 // TyClosure(syntax::ast::DefId{krate: 0, node: 66},
16 // ReScope(63))
17 //
18 // This is a regression test for issue #17021.
19 //
20 // compile-flags: -g
21
22
23 #![feature(unboxed_closures)]
24
25 use std::ptr;
26
27 pub fn replace_map<'a, T, F>(src: &mut T, prod: F) where F: FnOnce(T) -> T {
28 unsafe { *src = prod(ptr::read(src as *mut T as *const T)); }
29 }
30
31 pub fn main() {
32 let mut a = 7;
33 let b = &mut a;
34 replace_map(b, |x: usize| x * 2);
35 assert_eq!(*b, 14);
36 }