Skip to content

Commit 9fc51ef

Browse files
committed
Stabilize std::convert and related code
* Marks `#[stable]` the contents of the `std::convert` module. * Added methods `PathBuf::as_path`, `OsString::as_os_str`, `String::as_str`, `Vec::{as_slice, as_mut_slice}`. * Deprecates `OsStr::from_str` in favor of a new, stable, and more general `OsStr::new`. * Adds unstable methods `OsString::from_bytes` and `OsStr::{to_bytes, to_cstring}` for ergonomic FFI usage. [breaking-change]
1 parent 6cf3b0b commit 9fc51ef

File tree

25 files changed

+132
-70
lines changed

25 files changed

+132
-70
lines changed

src/compiletest/compiletest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![feature(std_misc)]
1919
#![feature(test)]
2020
#![feature(path_ext)]
21-
#![feature(convert)]
2221
#![feature(str_char)]
2322

2423
#![deny(warnings)]

src/libcollections/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#![feature(unsafe_no_drop_flag, filling_drop)]
3939
#![feature(step_by)]
4040
#![feature(str_char)]
41-
#![feature(convert)]
4241
#![feature(slice_patterns)]
4342
#![feature(debug_builders)]
4443
#![cfg_attr(test, feature(rand, rustc_private, test, hash, collections))]

src/libcollections/string.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ impl String {
364364
self.vec
365365
}
366366

367+
/// Extract a string slice containing the entire string.
368+
#[inline]
369+
#[unstable(feature = "convert",
370+
reason = "waiting on RFC revision")]
371+
pub fn as_str(&self) -> &str {
372+
self
373+
}
374+
367375
/// Pushes the given string onto this string buffer.
368376
///
369377
/// # Examples
@@ -848,7 +856,6 @@ impl<'a, 'b> PartialEq<Cow<'a, str>> for &'b str {
848856
#[allow(deprecated)]
849857
impl Str for String {
850858
#[inline]
851-
#[stable(feature = "rust1", since = "1.0.0")]
852859
fn as_slice(&self) -> &str {
853860
unsafe { mem::transmute(&*self.vec) }
854861
}

src/libcollections/vec.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,18 @@ impl<T> Vec<T> {
423423
}
424424
}
425425

426+
/// Extract a slice containing the entire vector.
427+
#[inline]
428+
#[unstable(feature = "convert",
429+
reason = "waiting on RFC revision")]
430+
pub fn as_slice(&self) -> &[T] {
431+
self
432+
}
433+
426434
/// Deprecated: use `&mut s[..]` instead.
427435
#[inline]
428-
#[unstable(feature = "collections",
429-
reason = "will be replaced by slice syntax")]
430-
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
436+
#[unstable(feature = "convert",
437+
reason = "waiting on RFC revision")]
431438
pub fn as_mut_slice(&mut self) -> &mut [T] {
432439
&mut self[..]
433440
}
@@ -1640,13 +1647,6 @@ impl<T> AsRef<Vec<T>> for Vec<T> {
16401647
}
16411648
}
16421649

1643-
#[stable(feature = "rust1", since = "1.0.0")]
1644-
impl<T> Into<Vec<T>> for Vec<T> {
1645-
fn into(self) -> Vec<T> {
1646-
self
1647-
}
1648-
}
1649-
16501650
#[stable(feature = "rust1", since = "1.0.0")]
16511651
impl<T> AsRef<[T]> for Vec<T> {
16521652
fn as_ref(&self) -> &[T] {

src/libcore/convert.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,57 @@
1414
//! conversions from one type to another. They follow the standard
1515
//! Rust conventions of `as`/`to`/`into`/`from`.
1616
17-
#![unstable(feature = "convert",
18-
reason = "recently added, experimental traits")]
17+
#![stable(feature = "rust1", since = "1.0.0")]
1918

2019
use marker::Sized;
2120

2221
/// A cheap, reference-to-reference conversion.
22+
#[stable(feature = "rust1", since = "1.0.0")]
2323
pub trait AsRef<T: ?Sized> {
2424
/// Perform the conversion.
25+
#[stable(feature = "rust1", since = "1.0.0")]
2526
fn as_ref(&self) -> &T;
2627
}
2728

2829
/// A cheap, mutable reference-to-mutable reference conversion.
30+
#[stable(feature = "rust1", since = "1.0.0")]
2931
pub trait AsMut<T: ?Sized> {
3032
/// Perform the conversion.
33+
#[stable(feature = "rust1", since = "1.0.0")]
3134
fn as_mut(&mut self) -> &mut T;
3235
}
3336

3437
/// A conversion that consumes `self`, which may or may not be
3538
/// expensive.
39+
#[stable(feature = "rust1", since = "1.0.0")]
3640
pub trait Into<T>: Sized {
3741
/// Perform the conversion.
42+
#[stable(feature = "rust1", since = "1.0.0")]
3843
fn into(self) -> T;
3944
}
4045

4146
/// Construct `Self` via a conversion.
47+
#[stable(feature = "rust1", since = "1.0.0")]
4248
pub trait From<T> {
4349
/// Perform the conversion.
50+
#[stable(feature = "rust1", since = "1.0.0")]
4451
fn from(T) -> Self;
4552
}
4653

4754
////////////////////////////////////////////////////////////////////////////////
4855
// GENERIC IMPLS
4956
////////////////////////////////////////////////////////////////////////////////
5057

51-
// As implies Into
52-
impl<'a, T: ?Sized, U: ?Sized> Into<&'a U> for &'a T where T: AsRef<U> {
53-
fn into(self) -> &'a U {
54-
self.as_ref()
55-
}
56-
}
57-
5858
// As lifts over &
59+
#[stable(feature = "rust1", since = "1.0.0")]
5960
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U> {
6061
fn as_ref(&self) -> &U {
6162
<T as AsRef<U>>::as_ref(*self)
6263
}
6364
}
6465

6566
// As lifts over &mut
67+
#[stable(feature = "rust1", since = "1.0.0")]
6668
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U> {
6769
fn as_ref(&self) -> &U {
6870
<T as AsRef<U>>::as_ref(*self)
@@ -77,14 +79,8 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U> {
7779
// }
7880
// }
7981

80-
// AsMut implies Into
81-
impl<'a, T: ?Sized, U: ?Sized> Into<&'a mut U> for &'a mut T where T: AsMut<U> {
82-
fn into(self) -> &'a mut U {
83-
(*self).as_mut()
84-
}
85-
}
86-
8782
// AsMut lifts over &mut
83+
#[stable(feature = "rust1", since = "1.0.0")]
8884
impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {
8985
fn as_mut(&mut self) -> &mut U {
9086
(*self).as_mut()
@@ -100,28 +96,38 @@ impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {
10096
// }
10197

10298
// From implies Into
99+
#[stable(feature = "rust1", since = "1.0.0")]
103100
impl<T, U> Into<U> for T where U: From<T> {
104101
fn into(self) -> U {
105102
U::from(self)
106103
}
107104
}
108105

106+
// From (and thus Into) is reflexive
107+
#[stable(feature = "rust1", since = "1.0.0")]
108+
impl<T> From<T> for T {
109+
fn from(t: T) -> T { t }
110+
}
111+
109112
////////////////////////////////////////////////////////////////////////////////
110113
// CONCRETE IMPLS
111114
////////////////////////////////////////////////////////////////////////////////
112115

116+
#[stable(feature = "rust1", since = "1.0.0")]
113117
impl<T> AsRef<[T]> for [T] {
114118
fn as_ref(&self) -> &[T] {
115119
self
116120
}
117121
}
118122

123+
#[stable(feature = "rust1", since = "1.0.0")]
119124
impl<T> AsMut<[T]> for [T] {
120125
fn as_mut(&mut self) -> &mut [T] {
121126
self
122127
}
123128
}
124129

130+
#[stable(feature = "rust1", since = "1.0.0")]
125131
impl AsRef<str> for str {
126132
fn as_ref(&self) -> &str {
127133
self

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#![feature(path_ext)]
4242
#![feature(str_words)]
4343
#![feature(str_char)]
44-
#![feature(convert)]
4544
#![feature(into_cow)]
4645
#![feature(slice_patterns)]
4746
#![cfg_attr(test, feature(test))]

src/librustc_back/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#![feature(path_ext)]
4747
#![feature(std_misc)]
4848
#![feature(step_by)]
49-
#![feature(convert)]
5049
#![cfg_attr(test, feature(test, rand))]
5150

5251
extern crate syntax;

src/librustc_driver/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#![feature(io)]
3939
#![feature(set_stdio)]
4040
#![feature(unicode)]
41-
#![feature(convert)]
4241

4342
extern crate arena;
4443
extern crate flate;

src/librustc_trans/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#![feature(unicode)]
4040
#![feature(path_ext)]
4141
#![feature(fs)]
42-
#![feature(convert)]
4342
#![feature(path_relative_from)]
4443

4544
#![allow(trivial_casts)]

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#![feature(file_path)]
3737
#![feature(path_ext)]
3838
#![feature(path_relative_from)]
39-
#![feature(convert)]
4039
#![feature(slice_patterns)]
4140

4241
extern crate arena;

src/libserialize/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Core encoding and decoding interfaces.
3636
#![feature(std_misc)]
3737
#![feature(unicode)]
3838
#![feature(str_char)]
39-
#![feature(convert)]
4039
#![cfg_attr(test, feature(test, old_io))]
4140

4241
// test harness access

src/libstd/dynamic_lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ mod dl {
190190
use ffi::{CStr, OsStr};
191191
use str;
192192
use libc;
193-
use os::unix::prelude::*;
194193
use ptr;
195194

196195
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> {

src/libstd/env.rs

-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ pub struct JoinPathsError {
327327
/// # Examples
328328
///
329329
/// ```
330-
/// # #![feature(convert)]
331330
/// use std::env;
332331
/// use std::path::PathBuf;
333332
///

0 commit comments

Comments
 (0)