core: convert ToStr::to_str to take explicit &self
This commit is contained in:
parent
9556629da2
commit
9adfa59d8e
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 += "/";
|
||||
@ -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; }
|
||||
|
@ -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, ~", "); }
|
||||
@ -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)]
|
||||
|
@ -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) }
|
||||
}
|
||||
|
||||
// ______________________________________________________________________
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -667,7 +667,7 @@ 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 {
|
||||
@ -675,7 +675,7 @@ pub impl IntVid: Vid {
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -683,7 +683,7 @@ pub impl FloatVid: Vid {
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -691,19 +691,19 @@ pub impl RegionVid: Vid {
|
||||
}
|
||||
|
||||
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()
|
||||
@ -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(),
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) }
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"
|
||||
}
|
||||
@ -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",
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ pub mod kitty {
|
||||
}
|
||||
|
||||
pub impl cat : ToStr {
|
||||
pure fn to_str() -> ~str { copy self.name }
|
||||
pure fn to_str(&self) -> ~str { copy self.name }
|
||||
}
|
||||
|
||||
priv impl cat {
|
||||
|
@ -20,7 +20,7 @@ impl Point : ToStr { //~ ERROR implements a method not defined in the trait
|
||||
Point { x: x, y: y }
|
||||
}
|
||||
|
||||
pure fn to_str() -> ~str {
|
||||
pure fn to_str(&self) -> ~str {
|
||||
fmt!("(%f, %f)", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
@ -14,5 +14,5 @@ struct S {
|
||||
|
||||
impl S: Cmp, ToStr { //~ ERROR: expected `{` but found `,`
|
||||
fn eq(&&other: S) { false }
|
||||
fn to_str() -> ~str { ~"hi" }
|
||||
}
|
||||
fn to_str(&self) -> ~str { ~"hi" }
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
}
|
||||
|
||||
impl cat: ToStr {
|
||||
pure fn to_str() -> ~str { copy self.name }
|
||||
pure fn to_str(&self) -> ~str { copy self.name }
|
||||
}
|
||||
|
||||
fn print_out<T: ToStr>(thing: T, expected: ~str) {
|
||||
|
@ -28,8 +28,8 @@ enum square {
|
||||
}
|
||||
|
||||
impl square: to_str::ToStr {
|
||||
pure fn to_str() -> ~str {
|
||||
match self {
|
||||
pure fn to_str(&self) -> ~str {
|
||||
match *self {
|
||||
bot => { ~"R" }
|
||||
wall => { ~"#" }
|
||||
rock => { ~"*" }
|
||||
|
@ -110,7 +110,7 @@ impl AsciiArt
|
||||
// Note that the %s fmt! specifier will not call this automatically.
|
||||
impl AsciiArt : ToStr
|
||||
{
|
||||
pure fn to_str() -> ~str
|
||||
pure fn to_str(&self) -> ~str
|
||||
{
|
||||
// Convert each line into a string.
|
||||
let lines = do self.lines.map |line| {str::from_chars(*line)};
|
||||
|
@ -4,7 +4,7 @@ struct Thingy {
|
||||
}
|
||||
|
||||
impl ToStr for Thingy {
|
||||
pure fn to_str() -> ~str {
|
||||
pure fn to_str(&self) -> ~str {
|
||||
fmt!("{ x: %d, y: %d }", self.x, self.y)
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@ struct PolymorphicThingy<T> {
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for PolymorphicThingy<T> {
|
||||
pure fn to_str() -> ~str {
|
||||
pure fn to_str(&self) -> ~str {
|
||||
self.x.to_str()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user