]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-unique-type-id.rs
Auto merge of #107054 - petrochenkov:effvisdoc3, r=GuillaumeGomez
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-unique-type-id.rs
1 // run-pass
2
3 // This code used to produce the following ICE:
4 //
5 //    error: internal compiler error: get_unique_type_id_of_type() -
6 //    unexpected type: closure,
7 //    Closure(rustc_ast::DefId{krate: 0, node: 66},
8 //    ReScope(63))
9 //
10 // This is a regression test for issue #17021.
11 //
12 // compile-flags: -g
13 // ignore-asmjs wasm2js does not support source maps yet
14
15 use std::ptr;
16
17 pub fn replace_map<'a, T, F>(src: &mut T, prod: F) where F: FnOnce(T) -> T {
18     unsafe { *src = prod(ptr::read(src as *mut T as *const T)); }
19 }
20
21 pub fn main() {
22     let mut a = 7;
23     let b = &mut a;
24     replace_map(b, |x: usize| x * 2);
25     assert_eq!(*b, 14);
26 }