Skip to content

Port to usize/isize in libsyntax #21340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ impl UnusedMut {
let ident = path1.node;
if let ast::BindByValue(ast::MutMutable) = mode {
if !token::get_ident(ident).get().starts_with("_") {
match mutables.entry(ident.name.uint()) {
match mutables.entry(ident.name.usize()) {
Vacant(entry) => { entry.insert(vec![id]); },
Occupied(mut entry) => { entry.get_mut().push(id); },
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
fn explain_span(cx: &ctxt, heading: &str, span: Span)
-> (String, Option<Span>) {
let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize()),
Some(span))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let module_name = self.module_to_string(&*search_module);
let mut span = span;
let msg = if "???" == &module_name[] {
span.hi = span.lo + Pos::from_uint(segment_name.get().len());
span.hi = span.lo + Pos::from_usize(segment_name.get().len());

match search_parent_externals(name,
&self.current_module) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/save/span_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl<'a> SpanUtils<'a> {
format!("file_name,{},file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\
file_line_end,{},file_col_end,{},extent_end,{},extent_end_bytes,{}",
lo_loc.file.name,
lo_loc.line, lo_loc.col.to_uint(), lo_pos.to_uint(), lo_pos_byte.to_uint(),
hi_loc.line, hi_loc.col.to_uint(), hi_pos.to_uint(), hi_pos_byte.to_uint())
lo_loc.line, lo_loc.col.to_usize(), lo_pos.to_usize(), lo_pos_byte.to_usize(),
hi_loc.line, hi_loc.col.to_usize(), hi_pos.to_usize(), hi_pos_byte.to_usize())
}

// sub_span starts at span.lo, so we need to adjust the positions etc.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub fn return_type_is_void(ccx: &CrateContext, ty: Ty) -> bool {
/// Generates a unique symbol based off the name given. This is used to create
/// unique symbols for things like closures.
pub fn gensym_name(name: &str) -> PathElem {
let num = token::gensym(name).uint();
let num = token::gensym(name).usize();
// use one colon which will get translated to a period by the mangler, and
// we're guaranteed that `num` is globally unique for this crate.
PathName(token::gensym(&format!("{}:{}", name, num)[]))
Expand Down Expand Up @@ -848,7 +848,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
!null_terminated as Bool);

let gsym = token::gensym("str");
let buf = CString::from_vec(format!("str{}", gsym.uint()).into_bytes());
let buf = CString::from_vec(format!("str{}", gsym.usize()).into_bytes());
let g = llvm::LLVMAddGlobal(cx.llmod(), val_ty(sc).to_ref(), buf.as_ptr());
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True);
Expand All @@ -873,7 +873,7 @@ pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef {
let lldata = C_bytes(cx, data);

let gsym = token::gensym("binary");
let name = format!("binary{}", gsym.uint());
let name = format!("binary{}", gsym.usize());
let name = CString::from_vec(name.into_bytes());
let g = llvm::LLVMAddGlobal(cx.llmod(), val_ty(lldata).to_ref(),
name.as_ptr());
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_trans/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ pub fn set_source_location(fcx: &FunctionContext,

set_debug_location(cx, DebugLocation::new(scope,
loc.line,
loc.col.to_uint()));
loc.col.to_usize()));
} else {
set_debug_location(cx, UnknownLocation);
}
Expand Down Expand Up @@ -1719,7 +1719,7 @@ fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,

set_debug_location(cx, DebugLocation::new(scope_metadata,
loc.line,
loc.col.to_uint()));
loc.col.to_usize()));
unsafe {
let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd(
DIB(cx),
Expand Down Expand Up @@ -3282,7 +3282,7 @@ fn create_scope_map(cx: &CrateContext,
parent_scope,
file_metadata,
loc.line as c_uint,
loc.col.to_uint() as c_uint)
loc.col.to_usize() as c_uint)
};

scope_stack.push(ScopeStackEntry { scope_metadata: scope_metadata,
Expand Down Expand Up @@ -3404,7 +3404,7 @@ fn create_scope_map(cx: &CrateContext,
parent_scope,
file_metadata,
loc.line as c_uint,
loc.col.to_uint() as c_uint)
loc.col.to_usize() as c_uint)
};

scope_stack.push(ScopeStackEntry {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ pub fn make_vtable<I: Iterator<Item=ValueRef>>(ccx: &CrateContext,
unsafe {
let tbl = C_struct(ccx, &components[], false);
let sym = token::gensym("vtable");
let buf = CString::from_vec(format!("vtable{}", sym.uint()).into_bytes());
let buf = CString::from_vec(format!("vtable{}", sym.usize()).into_bytes());
let vt_gvar = llvm::LLVMAddGlobal(ccx.llmod(), val_ty(tbl).to_ref(),
buf.as_ptr());
llvm::LLVMSetInitializer(vt_gvar, tbl);
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1870,9 +1870,9 @@ impl Clean<Span> for syntax::codemap::Span {
Span {
filename: filename.to_string(),
loline: lo.line,
locol: lo.col.to_uint(),
locol: lo.col.to_usize(),
hiline: hi.line,
hicol: hi.col.to_uint(),
hicol: hi.col.to_usize(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub fn all_names() -> Vec<&'static str> {

impl Abi {
#[inline]
pub fn index(&self) -> uint {
*self as uint
pub fn index(&self) -> usize {
*self as usize
}

#[inline]
Expand Down
30 changes: 15 additions & 15 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Ident {

pub fn encode_with_hygiene(&self) -> String {
format!("\x00name_{},ctxt_{}\x00",
self.name.uint(),
self.name.usize(),
self.ctxt)
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl PartialEq for Ident {

/// A SyntaxContext represents a chain of macro-expandings
/// and renamings. Each macro expansion corresponds to
/// a fresh uint
/// a fresh usize

// I'm representing this syntax context as an index into
// a table, in order to work around a compiler bug
Expand Down Expand Up @@ -181,9 +181,9 @@ impl Name {
}
}

pub fn uint(&self) -> uint {
pub fn usize(&self) -> usize {
let Name(nm) = *self;
nm as uint
nm as usize
}

pub fn ident(&self) -> Ident {
Expand Down Expand Up @@ -740,7 +740,7 @@ pub enum Expr_ {
ExprAssign(P<Expr>, P<Expr>),
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
ExprField(P<Expr>, SpannedIdent),
ExprTupField(P<Expr>, Spanned<uint>),
ExprTupField(P<Expr>, Spanned<usize>),
ExprIndex(P<Expr>, P<Expr>),
ExprRange(Option<P<Expr>>, Option<P<Expr>>),

Expand Down Expand Up @@ -839,7 +839,7 @@ pub struct SequenceRepetition {
/// Whether the sequence can be repeated zero (*), or one or more times (+)
pub op: KleeneOp,
/// The number of `MatchNt`s that appear in the sequence (and subsequences)
pub num_captures: uint,
pub num_captures: usize,
}

/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
Expand Down Expand Up @@ -878,7 +878,7 @@ pub enum TokenTree {
}

impl TokenTree {
pub fn len(&self) -> uint {
pub fn len(&self) -> usize {
match *self {
TtToken(_, token::DocComment(_)) => 2,
TtToken(_, token::SpecialVarNt(..)) => 2,
Expand All @@ -893,7 +893,7 @@ impl TokenTree {
}
}

pub fn get_tt(&self, index: uint) -> TokenTree {
pub fn get_tt(&self, index: usize) -> TokenTree {
match (self, index) {
(&TtToken(sp, token::DocComment(_)), 0) => {
TtToken(sp, token::Pound)
Expand Down Expand Up @@ -963,7 +963,7 @@ pub enum Mac_ {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
pub enum StrStyle {
CookedStr,
RawStr(uint)
RawStr(usize)
}

pub type Lit = Spanned<Lit_>;
Expand Down Expand Up @@ -992,7 +992,7 @@ pub enum LitIntType {
}

impl LitIntType {
pub fn suffix_len(&self) -> uint {
pub fn suffix_len(&self) -> usize {
match *self {
UnsuffixedIntLit(_) => 0,
SignedIntLit(s, _) => s.suffix_len(),
Expand Down Expand Up @@ -1113,7 +1113,7 @@ impl fmt::String for IntTy {
}

impl IntTy {
pub fn suffix_len(&self) -> uint {
pub fn suffix_len(&self) -> usize {
match *self {
TyIs(true) /* i */ => 1,
TyIs(false) /* is */ | TyI8 => 2,
Expand Down Expand Up @@ -1146,7 +1146,7 @@ impl PartialEq for UintTy {
}

impl UintTy {
pub fn suffix_len(&self) -> uint {
pub fn suffix_len(&self) -> usize {
match *self {
TyUs(true) /* u */ => 1,
TyUs(false) /* us */ | TyU8 => 2,
Expand Down Expand Up @@ -1186,7 +1186,7 @@ impl fmt::String for FloatTy {
}

impl FloatTy {
pub fn suffix_len(&self) -> uint {
pub fn suffix_len(&self) -> usize {
match *self {
TyF32 | TyF64 => 3, // add F128 handling here
}
Expand Down Expand Up @@ -1274,7 +1274,7 @@ pub enum Ty_ {
TyPtr(MutTy),
/// A reference (`&'a T` or `&'a mut T`)
TyRptr(Option<Lifetime>, MutTy),
/// A bare function (e.g. `fn(uint) -> bool`)
/// A bare function (e.g. `fn(usize) -> bool`)
TyBareFn(P<BareFnTy>),
/// A tuple (`(A, B, C, D,...)`)
TyTup(Vec<P<Ty>> ),
Expand Down Expand Up @@ -1566,7 +1566,7 @@ pub enum AttrStyle {
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
pub struct AttrId(pub uint);
pub struct AttrId(pub usize);

/// Doc-comments are promoted to attributes that have is_sugared_doc = true
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ pub struct Map<'ast> {
}

impl<'ast> Map<'ast> {
fn entry_count(&self) -> uint {
fn entry_count(&self) -> usize {
self.map.borrow().len()
}

fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
self.map.borrow().get(id as uint).map(|e| *e)
self.map.borrow().get(id as usize).map(|e| *e)
}

pub fn krate(&self) -> &'ast Crate {
Expand Down Expand Up @@ -652,7 +652,7 @@ impl<'a, 'ast> Iterator for NodesMatchingSuffix<'a, 'ast> {
fn next(&mut self) -> Option<NodeId> {
loop {
let idx = self.idx;
if idx as uint >= self.map.entry_count() {
if idx as usize >= self.map.entry_count() {
return None;
}
self.idx += 1;
Expand Down Expand Up @@ -744,10 +744,10 @@ impl<'ast> NodeCollector<'ast> {
fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'ast>) {
debug!("ast_map: {:?} => {:?}", id, entry);
let len = self.map.len();
if id as uint >= len {
self.map.extend(repeat(NotPresent).take(id as uint - len + 1));
if id as usize >= len {
self.map.extend(repeat(NotPresent).take(id as usize - len + 1));
}
self.map[id as uint] = entry;
self.map[id as usize] = entry;
}

fn insert(&mut self, id: NodeId, node: Node<'ast>) {
Expand Down
24 changes: 12 additions & 12 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn int_ty_max(t: IntTy) -> u64 {
}

/// Get a string representation of an unsigned int type, with its value.
/// We want to avoid "42uint" in favor of "42u"
/// We want to avoid "42u" in favor of "42us". "42uint" is right out.
pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String {
let s = match t {
TyUs(true) if val.is_some() => "u",
Expand Down Expand Up @@ -319,25 +319,25 @@ pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
}

/// Maps a binary operator to its precedence
pub fn operator_prec(op: ast::BinOp) -> uint {
pub fn operator_prec(op: ast::BinOp) -> usize {
match op {
// 'as' sits here with 12
BiMul | BiDiv | BiRem => 11u,
BiAdd | BiSub => 10u,
BiShl | BiShr => 9u,
BiBitAnd => 8u,
BiBitXor => 7u,
BiBitOr => 6u,
BiLt | BiLe | BiGe | BiGt | BiEq | BiNe => 3u,
BiAnd => 2u,
BiOr => 1u
BiMul | BiDiv | BiRem => 11us,
BiAdd | BiSub => 10us,
BiShl | BiShr => 9us,
BiBitAnd => 8us,
BiBitXor => 7us,
BiBitOr => 6us,
BiLt | BiLe | BiGe | BiGt | BiEq | BiNe => 3us,
BiAnd => 2us,
BiOr => 1us
}
}

/// Precedence of the `as` operator, which is a binary operator
/// not appearing in the prior table.
#[allow(non_upper_case_globals)]
pub static as_prec: uint = 12u;
pub static as_prec: usize = 12us;

pub fn empty_generics() -> Generics {
Generics {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn mk_word_item(name: InternedString) -> P<MetaItem> {
P(dummy_spanned(MetaWord(name)))
}

thread_local! { static NEXT_ATTR_ID: Cell<uint> = Cell::new(0) }
thread_local! { static NEXT_ATTR_ID: Cell<usize> = Cell::new(0) }

pub fn mk_attr_id() -> AttrId {
let id = NEXT_ATTR_ID.with(|slot| {
Expand Down
Loading