rustc: use FromPrimitive for decoding astencode_tag.
This commit is contained in:
parent
5918d33fef
commit
7be460ff37
@ -12,7 +12,6 @@
|
||||
|
||||
pub use self::astencode_tag::*;
|
||||
|
||||
use std::mem;
|
||||
use back::svh::Svh;
|
||||
|
||||
// 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;
|
||||
pub const tag_items_data_item_reexport_name: uint = 0x3a;
|
||||
|
||||
// used to encode crate_ctxt side tables
|
||||
#[derive(Copy, PartialEq)]
|
||||
#[derive(Copy, PartialEq, FromPrimitive)]
|
||||
#[repr(uint)]
|
||||
pub enum astencode_tag { // Reserves 0x40 -- 0x5f
|
||||
tag_ast = 0x40,
|
||||
@ -146,17 +145,6 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
|
||||
tag_table_object_cast_map = 0x58,
|
||||
}
|
||||
|
||||
static first_astencode_tag: uint = tag_ast as uint;
|
||||
static last_astencode_tag: uint = tag_table_object_cast_map as uint;
|
||||
impl astencode_tag {
|
||||
pub fn from_uint(value : uint) -> Option<astencode_tag> {
|
||||
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
|
||||
if !is_a_tag { None } else {
|
||||
Some(unsafe { mem::transmute::<uint, astencode_tag>(value) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const tag_item_trait_item_sort: uint = 0x60;
|
||||
|
||||
pub const tag_item_trait_parent_sort: uint = 0x61;
|
||||
|
@ -38,6 +38,7 @@ use syntax::ptr::P;
|
||||
use syntax;
|
||||
|
||||
use std::old_io::Seek;
|
||||
use std::num::FromPrimitive;
|
||||
use std::rc::Rc;
|
||||
|
||||
use rbml::io::SeekableMemWriter;
|
||||
@ -1836,8 +1837,8 @@ fn decode_side_tables(dcx: &DecodeContext,
|
||||
debug!(">> Side table document with tag 0x{:x} \
|
||||
found for id {} (orig {})",
|
||||
tag, id, id0);
|
||||
|
||||
match c::astencode_tag::from_uint(tag) {
|
||||
let decoded_tag: Option<c::astencode_tag> = FromPrimitive::from_uint(tag);
|
||||
match decoded_tag {
|
||||
None => {
|
||||
dcx.tcx.sess.bug(
|
||||
&format!("unknown tag found in side tables: {:x}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user