Skip to content

Commit 3bdce1e

Browse files
committed
rustc: use FromPrimitive for decoding astencode_tag.
1 parent 5715987 commit 3bdce1e

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/librustc/metadata/common.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
pub use self::astencode_tag::*;
1414

15-
use std::mem;
1615
use back::svh::Svh;
1716

1817
// EBML enum definitions and utils shared by the encoder and decoder
@@ -113,7 +112,7 @@ pub const tag_items_data_item_reexport_def_id: uint = 0x39;
113112
pub const tag_items_data_item_reexport_name: uint = 0x3a;
114113

115114
// used to encode crate_ctxt side tables
116-
#[derive(Copy, PartialEq)]
115+
#[derive(Copy, PartialEq, FromPrimitive)]
117116
#[repr(uint)]
118117
pub enum astencode_tag { // Reserves 0x40 -- 0x5f
119118
tag_ast = 0x40,
@@ -145,17 +144,6 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
145144
tag_table_object_cast_map = 0x57,
146145
}
147146

148-
static first_astencode_tag: uint = tag_ast as uint;
149-
static last_astencode_tag: uint = tag_table_object_cast_map as uint;
150-
impl astencode_tag {
151-
pub fn from_uint(value : uint) -> Option<astencode_tag> {
152-
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
153-
if !is_a_tag { None } else {
154-
Some(unsafe { mem::transmute::<uint, astencode_tag>(value) })
155-
}
156-
}
157-
}
158-
159147
pub const tag_item_trait_item_sort: uint = 0x60;
160148

161149
pub const tag_item_trait_parent_sort: uint = 0x61;

src/librustc/middle/astencode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use syntax::ptr::P;
3838
use syntax;
3939

4040
use std::old_io::Seek;
41+
use std::num::FromPrimitive;
4142
use std::rc::Rc;
4243

4344
use rbml::io::SeekableMemWriter;
@@ -1875,8 +1876,8 @@ fn decode_side_tables(dcx: &DecodeContext,
18751876
debug!(">> Side table document with tag 0x{:x} \
18761877
found for id {} (orig {})",
18771878
tag, id, id0);
1878-
1879-
match c::astencode_tag::from_uint(tag) {
1879+
let decoded_tag: Option<c::astencode_tag> = FromPrimitive::from_uint(tag);
1880+
match decoded_tag {
18801881
None => {
18811882
dcx.tcx.sess.bug(
18821883
&format!("unknown tag found in side tables: {:x}",

0 commit comments

Comments
 (0)