Skip to content

Commit

Permalink
Use sym constansts for PrimitiveTypeTable keys
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Jun 14, 2019
1 parent 4e212c6 commit 5c84cd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,37 +1518,32 @@ impl<'a> NameBinding<'a> {
///
/// All other types are defined somewhere and possibly imported, but the primitive ones need
/// special handling, since they have no place of origin.
#[derive(Default)]
struct PrimitiveTypeTable {
primitive_types: FxHashMap<Name, PrimTy>,
}

impl PrimitiveTypeTable {
fn new() -> PrimitiveTypeTable {
let mut table = PrimitiveTypeTable::default();

table.intern("bool", Bool);
table.intern("char", Char);
table.intern("f32", Float(FloatTy::F32));
table.intern("f64", Float(FloatTy::F64));
table.intern("isize", Int(IntTy::Isize));
table.intern("i8", Int(IntTy::I8));
table.intern("i16", Int(IntTy::I16));
table.intern("i32", Int(IntTy::I32));
table.intern("i64", Int(IntTy::I64));
table.intern("i128", Int(IntTy::I128));
table.intern("str", Str);
table.intern("usize", Uint(UintTy::Usize));
table.intern("u8", Uint(UintTy::U8));
table.intern("u16", Uint(UintTy::U16));
table.intern("u32", Uint(UintTy::U32));
table.intern("u64", Uint(UintTy::U64));
table.intern("u128", Uint(UintTy::U128));
table
}

fn intern(&mut self, string: &str, primitive_type: PrimTy) {
self.primitive_types.insert(Symbol::intern(string), primitive_type);
let mut table = FxHashMap::default();

table.insert(sym::bool, Bool);
table.insert(sym::char, Char);
table.insert(sym::f32, Float(FloatTy::F32));
table.insert(sym::f64, Float(FloatTy::F64));
table.insert(sym::isize, Int(IntTy::Isize));
table.insert(sym::i8, Int(IntTy::I8));
table.insert(sym::i16, Int(IntTy::I16));
table.insert(sym::i32, Int(IntTy::I32));
table.insert(sym::i64, Int(IntTy::I64));
table.insert(sym::i128, Int(IntTy::I128));
table.insert(sym::str, Str);
table.insert(sym::usize, Uint(UintTy::Usize));
table.insert(sym::u8, Uint(UintTy::U8));
table.insert(sym::u16, Uint(UintTy::U16));
table.insert(sym::u32, Uint(UintTy::U32));
table.insert(sym::u64, Uint(UintTy::U64));
table.insert(sym::u128, Uint(UintTy::U128));
Self { primitive_types: table }
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ symbols! {
bin,
bind_by_move_pattern_guards,
block,
bool,
borrowck_graphviz_postflow,
borrowck_graphviz_preflow,
box_patterns,
Expand All @@ -171,6 +172,7 @@ symbols! {
cfg_target_has_atomic,
cfg_target_thread_local,
cfg_target_vendor,
char,
clone,
Clone,
clone_closures,
Expand Down

0 comments on commit 5c84cd3

Please sign in to comment.