Skip to content

Commit 9b24eb8

Browse files
Jorge AparicioSimonSapin
Jorge Aparicio
authored andcommitted
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]
1 parent 7d917d5 commit 9b24eb8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/libstd/ascii.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![experimental]
1616

1717
use collections::Collection;
18+
use core::kinds::Sized;
1819
use fmt;
1920
use iter::Iterator;
2021
use mem;
@@ -272,7 +273,7 @@ impl OwnedAsciiCast for Vec<u8> {
272273

273274
/// Trait for converting an ascii type to a string. Needed to convert
274275
/// `&[Ascii]` to `&str`.
275-
pub trait AsciiStr {
276+
pub trait AsciiStr for Sized? {
276277
/// Convert to a string.
277278
fn as_str_ascii<'a>(&'a self) -> &'a str;
278279

@@ -291,13 +292,13 @@ pub trait AsciiStr {
291292
fn to_uppercase(&self) -> Vec<Ascii>;
292293

293294
/// Compares two Ascii strings ignoring case.
294-
fn eq_ignore_case(self, other: &[Ascii]) -> bool;
295+
fn eq_ignore_case(&self, other: &[Ascii]) -> bool;
295296
}
296297

297-
impl<'a> AsciiStr for &'a [Ascii] {
298+
impl AsciiStr for [Ascii] {
298299
#[inline]
299300
fn as_str_ascii<'a>(&'a self) -> &'a str {
300-
unsafe { mem::transmute(*self) }
301+
unsafe { mem::transmute(self) }
301302
}
302303

303304
#[inline]
@@ -321,7 +322,7 @@ impl<'a> AsciiStr for &'a [Ascii] {
321322
}
322323

323324
#[inline]
324-
fn eq_ignore_case(self, other: &[Ascii]) -> bool {
325+
fn eq_ignore_case(&self, other: &[Ascii]) -> bool {
325326
self.iter().zip(other.iter()).all(|(&a, &b)| a.eq_ignore_case(b))
326327
}
327328
}
@@ -372,7 +373,7 @@ pub trait OwnedAsciiExt {
372373
}
373374

374375
/// Extension methods for ASCII-subset only operations on string slices
375-
pub trait AsciiExt<T> {
376+
pub trait AsciiExt<T> for Sized? {
376377
/// Makes a copy of the string in ASCII upper case:
377378
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
378379
/// but non-ASCII letters are unchanged.
@@ -386,10 +387,10 @@ pub trait AsciiExt<T> {
386387
/// Check that two strings are an ASCII case-insensitive match.
387388
/// Same as `to_ascii_lower(a) == to_ascii_lower(b)`,
388389
/// but without allocating and copying temporary strings.
389-
fn eq_ignore_ascii_case(&self, other: Self) -> bool;
390+
fn eq_ignore_ascii_case(&self, other: &Self) -> bool;
390391
}
391392

392-
impl<'a> AsciiExt<String> for &'a str {
393+
impl AsciiExt<String> for str {
393394
#[inline]
394395
fn to_ascii_upper(&self) -> String {
395396
// Vec<u8>::to_ascii_upper() preserves the UTF-8 invariant.
@@ -422,7 +423,7 @@ impl OwnedAsciiExt for String {
422423
}
423424
}
424425

425-
impl<'a> AsciiExt<Vec<u8>> for &'a [u8] {
426+
impl AsciiExt<Vec<u8>> for [u8] {
426427
#[inline]
427428
fn to_ascii_upper(&self) -> Vec<u8> {
428429
self.iter().map(|&byte| ASCII_UPPER_MAP[byte as uint]).collect()

0 commit comments

Comments
 (0)