Skip to content

Commit a1d9010

Browse files
Add ICE regression test with unboxed closures
This code used to produce the following ICE: error: internal compiler error: get_unique_type_id_of_type() - unexpected type: closure, ty_unboxed_closure(syntax::ast::DefId{krate: 0u32, node: 66u32}, ReScope(63u32)) This is a regression test for issue rust-lang#17021.
1 parent c964cb2 commit a1d9010

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#![feature(unboxed_closures, overloaded_calls)]
21+
22+
use std::ptr;
23+
24+
pub fn replace_map<'a, T, F>(src: &mut T, prod: F)
25+
where F: |: T| -> T {
26+
unsafe { *src = prod(ptr::read(src as *mut T as *const T)); }
27+
}
28+
29+
pub fn main() {
30+
let mut a = 7u;
31+
let b = &mut a;
32+
replace_map(b, |: x: uint| x * 2);
33+
assert_eq!(*b, 14u);
34+
}

0 commit comments

Comments
 (0)