]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/unboxed-closures-unique-type-id.rs
40071ec9754e2617bcda034310e6c48b16ca29d6
[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 //    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 use std::ptr;
23
24 pub fn replace_map<'a, T, F>(src: &mut T, prod: F) where F: FnOnce(T) -> T {
25     unsafe { *src = prod(ptr::read(src as *mut T as *const T)); }
26 }
27
28 pub fn main() {
29     let mut a = 7;
30     let b = &mut a;
31     replace_map(b, |x: usize| x * 2);
32     assert_eq!(*b, 14);
33 }