From 94ddb51c9c0a53103dc0c2a4c0260e71f62e6ef8 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 23 Oct 2014 10:43:18 -0500 Subject: DSTify [T]/str extension traits This PR changes the signature of several methods from `foo(self, ...)` to `foo(&self, ...)`/`foo(&mut self, ...)`, but there is no breakage of the usage of these methods due to the autoref nature of `method.call()`s. This PR also removes the lifetime parameter from some traits (`Trait<'a>` -> `Trait`). These changes break any use of the extension traits for generic programming, but those traits are not meant to be used for generic programming in the first place. In the whole rust distribution there was only one misuse of a extension trait as a bound, which got corrected (the bound was unnecessary and got removed) as part of this PR. [breaking-change] --- src/libstd/ascii.rs | 19 ++++++++++--------- src/libstd/path/posix.rs | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index c2e88bfdbcf..6b6b08c5e6e 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -15,6 +15,7 @@ #![experimental] use collections::Collection; +use core::kinds::Sized; use fmt; use iter::Iterator; use mem; @@ -272,7 +273,7 @@ impl OwnedAsciiCast for Vec { /// Trait for converting an ascii type to a string. Needed to convert /// `&[Ascii]` to `&str`. -pub trait AsciiStr { +pub trait AsciiStr for Sized? { /// Convert to a string. fn as_str_ascii<'a>(&'a self) -> &'a str; @@ -291,13 +292,13 @@ pub trait AsciiStr { fn to_uppercase(&self) -> Vec; /// Compares two Ascii strings ignoring case. - fn eq_ignore_case(self, other: &[Ascii]) -> bool; + fn eq_ignore_case(&self, other: &[Ascii]) -> bool; } -impl<'a> AsciiStr for &'a [Ascii] { +impl AsciiStr for [Ascii] { #[inline] fn as_str_ascii<'a>(&'a self) -> &'a str { - unsafe { mem::transmute(*self) } + unsafe { mem::transmute(self) } } #[inline] @@ -321,7 +322,7 @@ impl<'a> AsciiStr for &'a [Ascii] { } #[inline] - fn eq_ignore_case(self, other: &[Ascii]) -> bool { + fn eq_ignore_case(&self, other: &[Ascii]) -> bool { self.iter().zip(other.iter()).all(|(&a, &b)| a.eq_ignore_case(b)) } } @@ -372,7 +373,7 @@ pub trait OwnedAsciiExt { } /// Extension methods for ASCII-subset only operations on string slices -pub trait AsciiExt { +pub trait AsciiExt for Sized? { /// Makes a copy of the string in ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', /// but non-ASCII letters are unchanged. @@ -386,10 +387,10 @@ pub trait AsciiExt { /// Check that two strings are an ASCII case-insensitive match. /// Same as `to_ascii_lower(a) == to_ascii_lower(b)`, /// but without allocating and copying temporary strings. - fn eq_ignore_ascii_case(&self, other: Self) -> bool; + fn eq_ignore_ascii_case(&self, other: &Self) -> bool; } -impl<'a> AsciiExt for &'a str { +impl AsciiExt for str { #[inline] fn to_ascii_upper(&self) -> String { // Vec::to_ascii_upper() preserves the UTF-8 invariant. @@ -422,7 +423,7 @@ impl OwnedAsciiExt for String { } } -impl<'a> AsciiExt> for &'a [u8] { +impl AsciiExt> for [u8] { #[inline] fn to_ascii_upper(&self) -> Vec { self.iter().map(|&byte| ASCII_UPPER_MAP[byte as uint]).collect() diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 69b6dd76676..f27a1c1feda 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -367,7 +367,7 @@ impl Path { /// Returns a normalized byte vector representation of a path, by removing all empty /// components, and unnecessary . and .. components. - fn normalize+CloneableVector>(v: V) -> Vec { + fn normalize>(v: V) -> Vec { // borrowck is being very picky let val = { let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE; -- cgit 1.4.1-3-g733a5