Skip to content

Commit 66f6bb5

Browse files
committed
---
yaml --- r: 163499 b: refs/heads/snap-stage3 c: 3925b4d h: refs/heads/master i: 163497: 17b662a 163495: 7019b4c v: v3
1 parent 24c4228 commit 66f6bb5

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 13e7f9c0a7ced7c20ea909e46bc6c520a9a2b260
4+
refs/heads/snap-stage3: 3925b4d5c94c10f6e3cff05afcb5866d62a7235c
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2014 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+
// Test that type IDs correctly account for higher-rank lifetimes
12+
// Also acts as a regression test for an ICE (issue #19791)
13+
14+
#![feature(unboxed_closures)]
15+
16+
use std::intrinsics::TypeId;
17+
18+
fn main() {
19+
// Bare fns
20+
{
21+
let a = TypeId::of::<fn(&'static int, &'static int)>();
22+
let b = TypeId::of::<for<'a> fn(&'static int, &'a int)>();
23+
let c = TypeId::of::<for<'a, 'b> fn(&'a int, &'b int)>();
24+
let d = TypeId::of::<for<'a, 'b> fn(&'b int, &'a int)>();
25+
assert!(a != b);
26+
assert!(a != c);
27+
assert!(a != d);
28+
assert!(b != c);
29+
assert!(b != d);
30+
assert_eq!(c, d);
31+
32+
// Make sure De Bruijn indices are handled correctly
33+
let e = TypeId::of::<for<'a> fn(fn(&'a int) -> &'a int)>();
34+
let f = TypeId::of::<fn(for<'a> fn(&'a int) -> &'a int)>();
35+
assert!(e != f);
36+
}
37+
// Stack closures
38+
{
39+
let a = TypeId::of::<|&'static int, &'static int|>();
40+
let b = TypeId::of::<for<'a> |&'static int, &'a int|>();
41+
let c = TypeId::of::<for<'a, 'b> |&'a int, &'b int|>();
42+
let d = TypeId::of::<for<'a, 'b> |&'b int, &'a int|>();
43+
assert!(a != b);
44+
assert!(a != c);
45+
assert!(a != d);
46+
assert!(b != c);
47+
assert!(b != d);
48+
assert_eq!(c, d);
49+
50+
// Make sure De Bruijn indices are handled correctly
51+
let e = TypeId::of::<for<'a> |(|&'a int| -> &'a int)|>();
52+
let f = TypeId::of::<|for<'a> |&'a int| -> &'a int|>();
53+
assert!(e != f);
54+
}
55+
// Boxed unboxed closures
56+
{
57+
let a = TypeId::of::<Box<Fn(&'static int, &'static int)>>();
58+
let b = TypeId::of::<Box<for<'a> Fn(&'static int, &'a int)>>();
59+
let c = TypeId::of::<Box<for<'a, 'b> Fn(&'a int, &'b int)>>();
60+
let d = TypeId::of::<Box<for<'a, 'b> Fn(&'b int, &'a int)>>();
61+
assert!(a != b);
62+
assert!(a != c);
63+
assert!(a != d);
64+
assert!(b != c);
65+
assert!(b != d);
66+
assert_eq!(c, d);
67+
68+
// Make sure De Bruijn indices are handled correctly
69+
let e = TypeId::of::<Box<for<'a> Fn(Box<Fn(&'a int) -> &'a int>)>>();
70+
let f = TypeId::of::<Box<Fn(Box<for<'a> Fn(&'a int) -> &'a int>)>>();
71+
assert!(e != f);
72+
}
73+
// Raw unboxed closures
74+
// Note that every unboxed closure has its own anonymous type,
75+
// so no two IDs should equal each other, even when compatible
76+
{
77+
let a = id(|&: _: &int, _: &int| {});
78+
let b = id(|&: _: &int, _: &int| {});
79+
assert!(a != b);
80+
}
81+
82+
fn id<T:'static>(_: T) -> TypeId {
83+
TypeId::of::<T>()
84+
}
85+
}

0 commit comments

Comments
 (0)