Skip to content

Commit 6fcf43e

Browse files
committed
auto merge of #13511 : Meyermagic/rust/enum_typeid, r=alexcrichton
Fixes #13507. I haven't familiarized myself with this part of the rust compiler, so hopefully there are no mistakes (despite the simplicity of the commit). It is also 5am.
2 parents 10f94e3 + b9f7ac5 commit 6fcf43e

File tree

3 files changed

+139
-1
lines changed

3 files changed

+139
-1
lines changed

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4565,7 +4565,7 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 {
45654565
}
45664566
ty_enum(d, _) => {
45674567
byte!(8);
4568-
hash!(d)
4568+
did(&mut state, d);
45694569
}
45704570
ty_box(_) => {
45714571
byte!(9);

src/test/auxiliary/issue13507.rs

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2012-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+
pub mod testtypes {
12+
use std::intrinsics::TypeId;
13+
14+
pub fn type_ids() -> Vec<TypeId> {
15+
let mut ids = vec!();
16+
ids.push(TypeId::of::<FooNil>());
17+
ids.push(TypeId::of::<FooBool>());
18+
ids.push(TypeId::of::<FooInt>());
19+
ids.push(TypeId::of::<FooUint>());
20+
ids.push(TypeId::of::<FooFloat>());
21+
ids.push(TypeId::of::<FooEnum>());
22+
ids.push(TypeId::of::<FooUniq>());
23+
ids.push(TypeId::of::<FooPtr>());
24+
ids.push(TypeId::of::<FooClosure>());
25+
ids.push(TypeId::of::<&'static FooTrait>());
26+
ids.push(TypeId::of::<FooStruct>());
27+
ids.push(TypeId::of::<FooTuple>());
28+
ids
29+
}
30+
31+
// Tests ty_nil
32+
pub type FooNil = ();
33+
34+
// Skipping ty_bot
35+
36+
// Tests ty_bool
37+
pub type FooBool = bool;
38+
39+
// Tests ty_char
40+
pub type FooChar = char;
41+
42+
// Tests ty_int (does not test all variants of IntTy)
43+
pub type FooInt = int;
44+
45+
// Tests ty_uint (does not test all variants of UintTy)
46+
pub type FooUint = uint;
47+
48+
// Tests ty_float (does not test all variants of FloatTy)
49+
pub type FooFloat = f64;
50+
51+
// For ty_str, what kind of string should I use? &'static str? ~str? Raw str?
52+
53+
// Tests ty_enum
54+
pub enum FooEnum {
55+
VarA(uint),
56+
VarB(uint, uint)
57+
}
58+
59+
// Skipping ty_box
60+
61+
// Tests ty_uniq (of u8)
62+
pub type FooUniq = ~u8;
63+
64+
// As with ty_str, what type should be used for ty_vec?
65+
66+
// Tests ty_ptr
67+
pub type FooPtr = *u8;
68+
69+
// Skipping ty_rptr
70+
71+
// Skipping ty_bare_fn (how do you get a bare function type, rather than proc or closure?)
72+
73+
// Tests ty_closure (does not test all types of closures)
74+
pub type FooClosure = |arg: u8|: 'static -> u8;
75+
76+
// Tests ty_trait
77+
pub trait FooTrait {
78+
fn foo_method(&self) -> uint;
79+
fn foo_static_method() -> uint;
80+
}
81+
82+
// Tests ty_struct
83+
pub struct FooStruct {
84+
pub pub_foo_field: uint,
85+
foo_field: uint
86+
}
87+
88+
// Tests ty_tup
89+
pub type FooTuple = (u8, i8, bool);
90+
91+
// Skipping ty_param
92+
93+
// Skipping ty_self
94+
95+
// Skipping ty_self
96+
97+
// Skipping ty_infer
98+
99+
// Skipping ty_err
100+
}

src/test/run-pass/issue-13507-2.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2012-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+
// aux-build:issue13507.rs
12+
extern crate issue13507;
13+
use issue13507::testtypes;
14+
15+
use std::intrinsics::TypeId;
16+
17+
pub fn type_ids() -> Vec<TypeId> {
18+
let mut ids = vec!();
19+
ids.push(TypeId::of::<testtypes::FooNil>());
20+
ids.push(TypeId::of::<testtypes::FooBool>());
21+
ids.push(TypeId::of::<testtypes::FooInt>());
22+
ids.push(TypeId::of::<testtypes::FooUint>());
23+
ids.push(TypeId::of::<testtypes::FooFloat>());
24+
ids.push(TypeId::of::<testtypes::FooEnum>());
25+
ids.push(TypeId::of::<testtypes::FooUniq>());
26+
ids.push(TypeId::of::<testtypes::FooPtr>());
27+
ids.push(TypeId::of::<testtypes::FooClosure>());
28+
ids.push(TypeId::of::<&'static testtypes::FooTrait>());
29+
ids.push(TypeId::of::<testtypes::FooStruct>());
30+
ids.push(TypeId::of::<testtypes::FooTuple>());
31+
ids
32+
}
33+
34+
pub fn main() {
35+
let othercrate = testtypes::type_ids();
36+
let thiscrate = type_ids();
37+
assert_eq!(thiscrate, othercrate);
38+
}

0 commit comments

Comments
 (0)