Skip to content

Commit

Permalink
Merge pull request #4684 from erickt/incoming
Browse files Browse the repository at this point in the history
core: convert ToStr::to_str to take explicit &self
  • Loading branch information
brson committed Feb 4, 2013
2 parents 750f246 + 9adfa59 commit 27e1ac5
Show file tree
Hide file tree
Showing 26 changed files with 88 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ pub pure fn to_str_digits(num: f32, dig: uint) -> ~str {

impl f32: to_str::ToStr {
#[inline(always)]
pure fn to_str() -> ~str { to_str_digits(self, 8) }
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
}

impl f32: num::ToStrRadix {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ pub pure fn to_str_digits(num: f64, dig: uint) -> ~str {

impl f64: to_str::ToStr {
#[inline(always)]
pure fn to_str() -> ~str { to_str_digits(self, 8) }
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
}

impl f64: num::ToStrRadix {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub pure fn to_str_digits(num: float, digits: uint) -> ~str {
impl float: to_str::ToStr {
#[inline(always)]
pure fn to_str() -> ~str { to_str_digits(self, 8) }
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
}
impl float: num::ToStrRadix {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ pub pure fn str(i: T) -> ~str { to_str(i) }
impl T : ToStr {
#[inline(always)]
pure fn to_str() -> ~str {
to_str(self)
pure fn to_str(&self) -> ~str {
to_str(*self)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ pub pure fn str(i: T) -> ~str { to_str(i) }
impl T : ToStr {
#[inline(always)]
pure fn to_str() -> ~str {
to_str(self)
pure fn to_str(&self) -> ~str {
to_str(*self)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl Path {
}

impl PosixPath : ToStr {
pure fn to_str() -> ~str {
pure fn to_str(&self) -> ~str {
let mut s = ~"";
if self.is_absolute {
s += "/";
Expand Down Expand Up @@ -531,7 +531,7 @@ impl PosixPath : GenericPath {


impl WindowsPath : ToStr {
pure fn to_str() -> ~str {
pure fn to_str(&self) -> ~str {
let mut s = ~"";
match self.host {
Some(ref h) => { s += "\\\\"; s += *h; }
Expand Down
52 changes: 34 additions & 18 deletions src/libcore/to_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,68 @@ use kinds::Copy;
use str;
use vec;

pub trait ToStr { pub pure fn to_str() -> ~str; }
pub trait ToStr {
pure fn to_str(&self) -> ~str;
}

impl bool: ToStr {
#[inline(always)]
pure fn to_str() -> ~str { ::bool::to_str(self) }
pure fn to_str(&self) -> ~str { ::bool::to_str(*self) }
}
impl (): ToStr {
#[inline(always)]
pure fn to_str() -> ~str { ~"()" }
pure fn to_str(&self) -> ~str { ~"()" }
}
impl ~str: ToStr {
#[inline(always)]
pure fn to_str() -> ~str { copy self }
pure fn to_str(&self) -> ~str { copy *self }
}
impl &str: ToStr {
#[inline(always)]
pure fn to_str() -> ~str { ::str::from_slice(self) }
pure fn to_str(&self) -> ~str { ::str::from_slice(*self) }
}
impl @str: ToStr {
#[inline(always)]
pure fn to_str() -> ~str { ::str::from_slice(self) }
pure fn to_str(&self) -> ~str { ::str::from_slice(*self) }
}

impl<A: ToStr Copy, B: ToStr Copy> (A, B): ToStr {
impl<A: ToStr, B: ToStr> (A, B): ToStr {
#[inline(always)]
pure fn to_str() -> ~str {
let (a, b) = self;
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
pure fn to_str(&self) -> ~str {
// FIXME(#4760): this causes an llvm assertion
//let &(ref a, ref b) = self;
match *self {
(ref a, ref b) => {
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
}
}
}
}
impl<A: ToStr Copy, B: ToStr Copy, C: ToStr Copy> (A, B, C): ToStr {
impl<A: ToStr, B: ToStr, C: ToStr> (A, B, C): ToStr {
#[inline(always)]
pure fn to_str() -> ~str {
let (a, b, c) = self;
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
pure fn to_str(&self) -> ~str {
// FIXME(#4760): this causes an llvm assertion
//let &(ref a, ref b, ref c) = self;
match *self {
(ref a, ref b, ref c) => {
fmt!("(%s, %s, %s)",
(*a).to_str(),
(*b).to_str(),
(*c).to_str()
)
}
}
}
}

impl<A: ToStr> ~[A]: ToStr {
#[inline(always)]
pure fn to_str() -> ~str {
pure fn to_str(&self) -> ~str {
unsafe {
// Bleh -- not really unsafe
// push_str and push_char
let mut acc = ~"[", first = true;
for vec::each(self) |elt| {
for self.each |elt| {
unsafe {
if first { first = false; }
else { str::push_str(&mut acc, ~", "); }
Expand All @@ -82,11 +98,11 @@ impl<A: ToStr> ~[A]: ToStr {
impl<A: ToStr> @A: ToStr {
#[inline(always)]
pure fn to_str() -> ~str { ~"@" + (*self).to_str() }
pure fn to_str(&self) -> ~str { ~"@" + (**self).to_str() }
}
impl<A: ToStr> ~A: ToStr {
#[inline(always)]
pure fn to_str() -> ~str { ~"~" + (*self).to_str() }
pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() }
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ pub fn check_crate(tcx: ty::ctxt,
}

impl LiveNode: to_str::ToStr {
pure fn to_str() -> ~str { fmt!("ln(%u)", *self) }
pure fn to_str(&self) -> ~str { fmt!("ln(%u)", **self) }
}

impl Variable: to_str::ToStr {
pure fn to_str() -> ~str { fmt!("v(%u)", *self) }
pure fn to_str(&self) -> ~str { fmt!("v(%u)", **self) }
}

// ______________________________________________________________________
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub struct EnvValue {
}

pub impl EnvAction {
fn to_str() -> ~str {
match self {
fn to_str(&self) -> ~str {
match *self {
EnvCopy => ~"EnvCopy",
EnvMove => ~"EnvMove",
EnvRef => ~"EnvRef"
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ pub impl block {
fn ty_to_str(t: ty::t) -> ~str {
ty_to_str(self.tcx(), t)
}
fn to_str() -> ~str {
fn to_str(&self) -> ~str {
match self.node_info {
Some(node_info) => {
fmt!("[block %d]", node_info.id)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ pub impl DatumBlock {
self.bcx.tcx()
}

fn to_str() -> ~str {
fn to_str(&self) -> ~str {
self.datum.to_str(self.ccx())
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,43 +667,43 @@ pub impl TyVid: Vid {
}

pub impl TyVid: ToStr {
pure fn to_str() -> ~str { fmt!("<V%u>", self.to_uint()) }
pure fn to_str(&self) -> ~str { fmt!("<V%u>", self.to_uint()) }
}

pub impl IntVid: Vid {
pure fn to_uint() -> uint { *self }
}

pub impl IntVid: ToStr {
pure fn to_str() -> ~str { fmt!("<VI%u>", self.to_uint()) }
pure fn to_str(&self) -> ~str { fmt!("<VI%u>", self.to_uint()) }
}

pub impl FloatVid: Vid {
pure fn to_uint() -> uint { *self }
}

pub impl FloatVid: ToStr {
pure fn to_str() -> ~str { fmt!("<VF%u>", self.to_uint()) }
pure fn to_str(&self) -> ~str { fmt!("<VF%u>", self.to_uint()) }
}

pub impl RegionVid: Vid {
pure fn to_uint() -> uint { *self }
}

pub impl RegionVid: ToStr {
pure fn to_str() -> ~str { fmt!("%?", self) }
pure fn to_str(&self) -> ~str { fmt!("%?", self) }
}

pub impl FnSig : ToStr {
pure fn to_str() -> ~str {
pure fn to_str(&self) -> ~str {
// grr, without tcx not much we can do.
return ~"(...)";
}
}

pub impl InferTy: ToStr {
pure fn to_str() -> ~str {
match self {
pure fn to_str(&self) -> ~str {
match *self {
TyVar(ref v) => v.to_str(),
IntVar(ref v) => v.to_str(),
FloatVar(ref v) => v.to_str()
Expand All @@ -712,8 +712,8 @@ pub impl InferTy: ToStr {
}

pub impl IntVarValue : ToStr {
pure fn to_str() -> ~str {
match self {
pure fn to_str(&self) -> ~str {
match *self {
IntType(ref v) => v.to_str(),
UintType(ref v) => v.to_str(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl BigUint : Ord {
}

impl BigUint : ToStr {
pure fn to_str() -> ~str { self.to_str_radix(10) }
pure fn to_str(&self) -> ~str { self.to_str_radix(10) }
}

impl BigUint : from_str::FromStr {
Expand Down Expand Up @@ -605,7 +605,7 @@ impl BigInt : Ord {
}

impl BigInt : ToStr {
pure fn to_str() -> ~str { self.to_str_radix(10) }
pure fn to_str(&self) -> ~str { self.to_str_radix(10) }
}

impl BigInt : from_str::FromStr {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl Bitv {
* The resulting string has the same length as `self`, and each
* character is either '0' or '1'.
*/
fn to_str() -> ~str {
fn to_str(&self) -> ~str {
let mut rs = ~"";
for self.each() |i| { if i { rs += ~"1"; } else { rs += ~"0"; } };
rs
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,11 @@ impl <A: ToJson> Option<A>: ToJson {
}
impl Json: to_str::ToStr {
pure fn to_str() -> ~str { to_str(&self) }
pure fn to_str(&self) -> ~str { to_str(self) }
}
impl Error: to_str::ToStr {
pure fn to_str() -> ~str {
pure fn to_str(&self) -> ~str {
fmt!("%u:%u: %s", self.line, self.col, *self.msg)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/net_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ pub pure fn to_str(url: &Url) -> ~str {
}

impl Url: to_str::ToStr {
pub pure fn to_str() -> ~str {
to_str(&self)
pub pure fn to_str(&self) -> ~str {
to_str(self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/oldmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub mod chained {
}

impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> T<K, V>: ToStr {
pure fn to_str() -> ~str {
pure fn to_str(&self) -> ~str {
unsafe {
// Meh -- this should be safe
do io::with_str_writer |wr| { self.to_writer(wr) }
Expand Down
20 changes: 10 additions & 10 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,8 @@ pub enum trait_method {
pub enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, }
pub impl int_ty : ToStr {
pure fn to_str() -> ~str {
::ast_util::int_ty_to_str(self)
pure fn to_str(&self) -> ~str {
::ast_util::int_ty_to_str(*self)
}
}
Expand Down Expand Up @@ -959,8 +959,8 @@ pub impl int_ty : cmp::Eq {
pub enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, }
pub impl uint_ty : ToStr {
pure fn to_str() -> ~str {
::ast_util::uint_ty_to_str(self)
pure fn to_str(&self) -> ~str {
::ast_util::uint_ty_to_str(*self)
}
}
Expand Down Expand Up @@ -993,8 +993,8 @@ pub impl uint_ty : cmp::Eq {
pub enum float_ty { ty_f, ty_f32, ty_f64, }
pub impl float_ty : ToStr {
pure fn to_str() -> ~str {
::ast_util::float_ty_to_str(self)
pure fn to_str(&self) -> ~str {
::ast_util::float_ty_to_str(*self)
}
}
Expand Down Expand Up @@ -1096,8 +1096,8 @@ pub enum Onceness {
}
pub impl Onceness : ToStr {
pure fn to_str() -> ~str {
match self {
pure fn to_str(&self) -> ~str {
match *self {
Once => ~"once",
Many => ~"many"
}
Expand Down Expand Up @@ -1188,8 +1188,8 @@ pub enum purity {
}
pub impl purity : ToStr {
pure fn to_str() -> ~str {
match self {
pure fn to_str(&self) -> ~str {
match *self {
impure_fn => ~"impure",
unsafe_fn => ~"unsafe",
pure_fn => ~"pure",
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/pipes/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub impl direction : cmp::Eq {
}

pub impl direction: ToStr {
pure fn to_str() -> ~str {
match self {
pure fn to_str(&self) -> ~str {
match *self {
send => ~"Send",
recv => ~"Recv"
}
Expand Down
Loading

0 comments on commit 27e1ac5

Please sign in to comment.