Auto merge of #22561 - richo:as_slice-as_str, r=Manishearth

This may not be quite ready to go out, I fixed some docs but suspect I missed a bunch.

I also wound up fixing a bunch of redundant `[]` suffixes, but on closer inspection I don't believe that can land until after a snapshot.
This commit is contained in:
bors
2015-03-09 21:02:50 +00:00
26 changed files with 63 additions and 63 deletions

View File

@@ -22,9 +22,9 @@ fn write_info(info: &Info) -> Result<(), IoError> {
let mut file = File::open_mode(&Path::new("my_best_friends.txt"), let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
Open, Write); Open, Write);
// Early return on error // Early return on error
try!(file.write_line(format!("name: {}", info.name).as_slice())); try!(file.write_line(&format!("name: {}", info.name)));
try!(file.write_line(format!("age: {}", info.age).as_slice())); try!(file.write_line(&format!("age: {}", info.age)));
try!(file.write_line(format!("rating: {}", info.rating).as_slice())); try!(file.write_line(&format!("rating: {}", info.rating)));
return Ok(()); return Ok(());
} }
``` ```
@@ -44,15 +44,15 @@ fn write_info(info: &Info) -> Result<(), IoError> {
let mut file = File::open_mode(&Path::new("my_best_friends.txt"), let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
Open, Write); Open, Write);
// Early return on error // Early return on error
match file.write_line(format!("name: {}", info.name).as_slice()) { match file.write_line(&format!("name: {}", info.name)) {
Ok(_) => (), Ok(_) => (),
Err(e) => return Err(e) Err(e) => return Err(e)
} }
match file.write_line(format!("age: {}", info.age).as_slice()) { match file.write_line(&format!("age: {}", info.age)) {
Ok(_) => (), Ok(_) => (),
Err(e) => return Err(e) Err(e) => return Err(e)
} }
return file.write_line(format!("rating: {}", info.rating).as_slice()); return file.write_line(&format!("rating: {}", info.rating));
} }
``` ```

View File

@@ -198,7 +198,7 @@
//! // for details, and the function `pad` can be used to pad strings. //! // for details, and the function `pad` can be used to pad strings.
//! let decimals = f.precision().unwrap_or(3); //! let decimals = f.precision().unwrap_or(3);
//! let string = f64::to_str_exact(magnitude, decimals); //! let string = f64::to_str_exact(magnitude, decimals);
//! f.pad_integral(true, "", string.as_slice()) //! f.pad_integral(true, "", &string)
//! } //! }
//! } //! }
//! //!

View File

@@ -139,7 +139,7 @@ impl String {
/// ```rust /// ```rust
/// let input = b"Hello \xF0\x90\x80World"; /// let input = b"Hello \xF0\x90\x80World";
/// let output = String::from_utf8_lossy(input); /// let output = String::from_utf8_lossy(input);
/// assert_eq!(output.as_slice(), "Hello \u{FFFD}World"); /// assert_eq!(output, "Hello \u{FFFD}World");
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> { pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
@@ -355,7 +355,7 @@ impl String {
/// ``` /// ```
/// let mut s = String::from_str("foo"); /// let mut s = String::from_str("foo");
/// s.push_str("bar"); /// s.push_str("bar");
/// assert_eq!(s.as_slice(), "foobar"); /// assert_eq!(s, "foobar");
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@@ -450,7 +450,7 @@ impl String {
/// s.push('1'); /// s.push('1');
/// s.push('2'); /// s.push('2');
/// s.push('3'); /// s.push('3');
/// assert_eq!(s.as_slice(), "abc123"); /// assert_eq!(s, "abc123");
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@@ -503,7 +503,7 @@ impl String {
/// ``` /// ```
/// let mut s = String::from_str("hello"); /// let mut s = String::from_str("hello");
/// s.truncate(2); /// s.truncate(2);
/// assert_eq!(s.as_slice(), "he"); /// assert_eq!(s, "he");
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@@ -622,7 +622,7 @@ impl String {
/// assert!(vec == &[104, 101, 108, 108, 111]); /// assert!(vec == &[104, 101, 108, 108, 111]);
/// vec.reverse(); /// vec.reverse();
/// } /// }
/// assert_eq!(s.as_slice(), "olleh"); /// assert_eq!(s, "olleh");
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View File

@@ -178,13 +178,13 @@
//! fn write_info(info: &Info) -> Result<(), IoError> { //! fn write_info(info: &Info) -> Result<(), IoError> {
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); //! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
//! // Early return on error //! // Early return on error
//! if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) { //! if let Err(e) = file.write_line(&format!("name: {}", info.name)) {
//! return Err(e) //! return Err(e)
//! } //! }
//! if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) { //! if let Err(e) = file.write_line(&format!("age: {}", info.age)) {
//! return Err(e) //! return Err(e)
//! } //! }
//! return file.write_line(format!("rating: {}", info.rating).as_slice()); //! return file.write_line(&format!("rating: {}", info.rating));
//! } //! }
//! ``` //! ```
//! //!
@@ -202,9 +202,9 @@
//! fn write_info(info: &Info) -> Result<(), IoError> { //! fn write_info(info: &Info) -> Result<(), IoError> {
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); //! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
//! // Early return on error //! // Early return on error
//! try!(file.write_line(format!("name: {}", info.name).as_slice())); //! try!(file.write_line(&format!("name: {}", info.name)));
//! try!(file.write_line(format!("age: {}", info.age).as_slice())); //! try!(file.write_line(&format!("age: {}", info.age)));
//! try!(file.write_line(format!("rating: {}", info.rating).as_slice())); //! try!(file.write_line(&format!("rating: {}", info.rating)));
//! return Ok(()); //! return Ok(());
//! } //! }
//! ``` //! ```

View File

@@ -46,7 +46,7 @@
//! //!
//! fn print_usage(program: &str, opts: &[OptGroup]) { //! fn print_usage(program: &str, opts: &[OptGroup]) {
//! let brief = format!("Usage: {} [options]", program); //! let brief = format!("Usage: {} [options]", program);
//! print!("{}", usage(brief.as_slice(), opts)); //! print!("{}", usage(brief, opts));
//! } //! }
//! //!
//! fn main() { //! fn main() {
@@ -63,17 +63,17 @@
//! Err(f) => { panic!(f.to_string()) } //! Err(f) => { panic!(f.to_string()) }
//! }; //! };
//! if matches.opt_present("h") { //! if matches.opt_present("h") {
//! print_usage(program.as_slice(), opts); //! print_usage(program, opts);
//! return; //! return;
//! } //! }
//! let output = matches.opt_str("o"); //! let output = matches.opt_str("o");
//! let input = if !matches.free.is_empty() { //! let input = if !matches.free.is_empty() {
//! matches.free[0].clone() //! matches.free[0].clone()
//! } else { //! } else {
//! print_usage(program.as_slice(), opts); //! print_usage(program, opts);
//! return; //! return;
//! }; //! };
//! do_work(input.as_slice(), output); //! do_work(input, output);
//! } //! }
//! ``` //! ```

View File

@@ -493,7 +493,7 @@ impl<'a> CrateReader<'a> {
}; };
let dylib = library.dylib.clone(); let dylib = library.dylib.clone();
let register = should_link && self.existing_match(info.name.as_slice(), let register = should_link && self.existing_match(&info.name,
None, None,
PathKind::Crate).is_none(); PathKind::Crate).is_none();
let metadata = if register { let metadata = if register {

View File

@@ -276,7 +276,7 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
let subspan = p.span.lo <= err.span.lo && err.span.hi <= p.span.hi; let subspan = p.span.lo <= err.span.lo && err.span.hi <= p.span.hi;
cx.tcx.sess.span_err(err.span, cx.tcx.sess.span_err(err.span,
&format!("constant evaluation error: {}", &format!("constant evaluation error: {}",
err.description().as_slice())); err.description()));
if !subspan { if !subspan {
cx.tcx.sess.span_note(p.span, cx.tcx.sess.span_note(p.span,
"in pattern here") "in pattern here")

View File

@@ -204,7 +204,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val { pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val {
match eval_const_expr_partial(tcx, e, None) { match eval_const_expr_partial(tcx, e, None) {
Ok(r) => r, Ok(r) => r,
Err(s) => tcx.sess.span_fatal(s.span, s.description().as_slice()) Err(s) => tcx.sess.span_fatal(s.span, &s.description())
} }
} }
@@ -665,14 +665,14 @@ pub fn compare_lit_exprs<'tcx>(tcx: &ty::ctxt<'tcx>,
let a = match eval_const_expr_partial(tcx, a, ty_hint) { let a = match eval_const_expr_partial(tcx, a, ty_hint) {
Ok(a) => a, Ok(a) => a,
Err(e) => { Err(e) => {
tcx.sess.span_err(a.span, e.description().as_slice()); tcx.sess.span_err(a.span, &e.description());
return None; return None;
} }
}; };
let b = match eval_const_expr_partial(tcx, b, ty_hint) { let b = match eval_const_expr_partial(tcx, b, ty_hint) {
Ok(b) => b, Ok(b) => b,
Err(e) => { Err(e) => {
tcx.sess.span_err(b.span, e.description().as_slice()); tcx.sess.span_err(b.span, &e.description());
return None; return None;
} }
}; };

View File

@@ -5485,7 +5485,7 @@ pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
Err(err) => { Err(err) => {
span_err!(cx.sess, err.span, E0305, span_err!(cx.sess, err.span, E0305,
"constant evaluation error: {}", "constant evaluation error: {}",
err.description().as_slice()); err.description());
} }
} }
} else { } else {

View File

@@ -115,7 +115,7 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
region::CodeExtent::Misc(_) => tag, region::CodeExtent::Misc(_) => tag,
region::CodeExtent::DestructionScope(_) => { region::CodeExtent::DestructionScope(_) => {
new_string = format!("destruction scope surrounding {}", tag); new_string = format!("destruction scope surrounding {}", tag);
new_string.as_slice() &*new_string
} }
region::CodeExtent::Remainder(r) => { region::CodeExtent::Remainder(r) => {
new_string = format!("block suffix following statement {}", new_string = format!("block suffix following statement {}",

View File

@@ -86,7 +86,7 @@
/// let mut flags = FLAG_A | FLAG_B; /// let mut flags = FLAG_A | FLAG_B;
/// flags.clear(); /// flags.clear();
/// assert!(flags.is_empty()); /// assert!(flags.is_empty());
/// assert_eq!(format!("{:?}", flags).as_slice(), "hi!"); /// assert_eq!(format!("{:?}", flags), "hi!");
/// } /// }
/// ``` /// ```
/// ///

View File

@@ -704,9 +704,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
self.tcx self.tcx
.sess .sess
.span_err(span, .span_err(span,
(format!("partial reinitialization of uninitialized \ &format!("partial reinitialization of uninitialized \
structure `{}`", structure `{}`",
self.loan_path_to_string(lp))).as_slice()); self.loan_path_to_string(lp)));
} }
pub fn report_reassigned_immutable_variable(&self, pub fn report_reassigned_immutable_variable(&self,

View File

@@ -2080,7 +2080,7 @@ impl LintPass for InvalidNoMangleItems {
!cx.exported_items.contains(&it.id) { !cx.exported_items.contains(&it.id) {
let msg = format!("static {} is marked #[no_mangle], but not exported", let msg = format!("static {} is marked #[no_mangle], but not exported",
it.ident); it.ident);
cx.span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg.as_slice()); cx.span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, &msg);
} }
}, },
ast::ItemConst(..) => { ast::ItemConst(..) => {

View File

@@ -1404,7 +1404,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
ast_ty.span.lo <= r.span.lo && r.span.hi <= ast_ty.span.hi; ast_ty.span.lo <= r.span.lo && r.span.hi <= ast_ty.span.hi;
span_err!(tcx.sess, r.span, E0250, span_err!(tcx.sess, r.span, E0250,
"array length constant evaluation error: {}", "array length constant evaluation error: {}",
r.description().as_slice()); r.description());
if !subspan { if !subspan {
span_note!(tcx.sess, ast_ty.span, "for array length here") span_note!(tcx.sess, ast_ty.span, "for array length here")
} }

View File

@@ -298,8 +298,8 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>(
match rcx.tcx().region_maps.opt_encl_scope(scope) { match rcx.tcx().region_maps.opt_encl_scope(scope) {
Some(parent_scope) => ty::ReScope(parent_scope), Some(parent_scope) => ty::ReScope(parent_scope),
None => rcx.tcx().sess.span_bug( None => rcx.tcx().sess.span_bug(
span, format!("no enclosing scope found for scope: {:?}", span, &format!("no enclosing scope found for scope: {:?}",
scope).as_slice()), scope)),
}; };
regionck::type_must_outlive(rcx, origin(), typ, parent_region); regionck::type_must_outlive(rcx, origin(), typ, parent_region);

View File

@@ -4620,7 +4620,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
Err(ref err) => { Err(ref err) => {
span_err!(ccx.tcx.sess, err.span, E0080, span_err!(ccx.tcx.sess, err.span, E0080,
"constant evaluation error: {}", "constant evaluation error: {}",
err.description().as_slice()); err.description());
} }
} }
}, },

View File

@@ -963,9 +963,9 @@ fn check_safety_of_rvalue_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 't
rcx.tcx() rcx.tcx()
.sess .sess
.span_bug(span, .span_bug(span,
format!("unexpected rvalue region in rvalue \ &format!("unexpected rvalue region in rvalue \
destructor safety checking: `{}`", destructor safety checking: `{}`",
region.repr(rcx.tcx())).as_slice()); region.repr(rcx.tcx())));
} }
} }
} }

View File

@@ -411,9 +411,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
Some(def_id) => { Some(def_id) => {
self.tcx().sess.fileline_help( self.tcx().sess.fileline_help(
span, span,
format!("consider removing `{}` or using a marker such as `{}`", &format!("consider removing `{}` or using a marker such as `{}`",
param_name.user_string(self.tcx()), param_name.user_string(self.tcx()),
ty::item_path_str(self.tcx(), def_id)).as_slice()); ty::item_path_str(self.tcx(), def_id)));
} }
None => { None => {
// no lang items, no help! // no lang items, no help!

View File

@@ -1590,8 +1590,8 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
ast::ItemMac(..) => { ast::ItemMac(..) => {
tcx.sess.span_bug( tcx.sess.span_bug(
it.span, it.span,
format!("compute_type_scheme_of_item: unexpected item type: {:?}", &format!("compute_type_scheme_of_item: unexpected item type: {:?}",
it.node).as_slice()); it.node));
} }
} }
} }

View File

@@ -188,7 +188,7 @@
//! let json_str: String = json_obj.to_string(); //! let json_str: String = json_obj.to_string();
//! //!
//! // Deserialize like before //! // Deserialize like before
//! let decoded: TestStruct = json::decode(json_str.as_slice()).unwrap(); //! let decoded: TestStruct = json::decode(json_str)).unwrap();
//! } //! }
//! ``` //! ```

View File

@@ -780,8 +780,8 @@ mod tests {
i += 1; i += 1;
} }
let n = make_rand_name(); let n = make_rand_name();
set_var(&n, s.as_slice()); set_var(&n, &s);
eq(var_os(&n), Some(s.as_slice())); eq(var_os(&n), Some(&s));
} }
#[test] #[test]
@@ -799,7 +799,7 @@ mod tests {
let n = make_rand_name(); let n = make_rand_name();
let s = repeat("x").take(10000).collect::<String>(); let s = repeat("x").take(10000).collect::<String>();
set_var(&n, &s); set_var(&n, &s);
eq(var_os(&n), Some(s.as_slice())); eq(var_os(&n), Some(&s));
remove_var(&n); remove_var(&n);
eq(var_os(&n), None); eq(var_os(&n), None);
} }

View File

@@ -828,7 +828,7 @@ mod tests {
macro_rules! error { ($e:expr, $s:expr) => ( macro_rules! error { ($e:expr, $s:expr) => (
match $e { match $e {
Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s), Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
Err(ref err) => assert!(err.to_string().contains($s.as_slice()), Err(ref err) => assert!(err.to_string().contains($s),
format!("`{}` did not contain `{}`", err, $s)) format!("`{}` did not contain `{}`", err, $s))
} }
) } ) }
@@ -880,7 +880,7 @@ mod tests {
-1|0 => panic!("shouldn't happen"), -1|0 => panic!("shouldn't happen"),
n => str::from_utf8(&read_buf[..n]).unwrap().to_string() n => str::from_utf8(&read_buf[..n]).unwrap().to_string()
}; };
assert_eq!(read_str.as_slice(), message); assert_eq!(read_str, message);
} }
check!(fs::remove_file(filename)); check!(fs::remove_file(filename));
} }
@@ -1107,7 +1107,7 @@ mod tests {
check!(check!(File::open(&f)).read(&mut mem)); check!(check!(File::open(&f)).read(&mut mem));
let read_str = str::from_utf8(&mem).unwrap(); let read_str = str::from_utf8(&mem).unwrap();
let expected = format!("{}{}", prefix, n.to_str().unwrap()); let expected = format!("{}{}", prefix, n.to_str().unwrap());
assert_eq!(expected.as_slice(), read_str); assert_eq!(expected, read_str);
} }
check!(fs::remove_file(&f)); check!(fs::remove_file(&f));
} }

View File

@@ -812,7 +812,7 @@ mod tests {
for (ref k, ref v) in env::vars() { for (ref k, ref v) in env::vars() {
// don't check windows magical empty-named variables // don't check windows magical empty-named variables
assert!(k.is_empty() || assert!(k.is_empty() ||
output.contains(format!("{}={}", *k, *v).as_slice()), output.contains(&format!("{}={}", *k, *v)),
"output doesn't contain `{}={}`\n{}", "output doesn't contain `{}={}`\n{}",
k, v, output); k, v, output);
} }
@@ -830,12 +830,12 @@ mod tests {
for &(ref k, ref v) in &r { for &(ref k, ref v) in &r {
// don't check android RANDOM variables // don't check android RANDOM variables
if *k != "RANDOM".to_string() { if *k != "RANDOM".to_string() {
assert!(output.contains(format!("{}={}", assert!(output.contains(&format!("{}={}",
*k, *k,
*v).as_slice()) || *v)) ||
output.contains(format!("{}=\'{}\'", output.contains(&format!("{}=\'{}\'",
*k, *k,
*v).as_slice())); *v)));
} }
} }
} }

View File

@@ -284,7 +284,7 @@ impl Builder {
stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top); stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
} }
match their_thread.name() { match their_thread.name() {
Some(name) => unsafe { imp::set_name(name.as_slice()); }, Some(name) => unsafe { imp::set_name(name); },
None => {} None => {}
} }
thread_info::set( thread_info::set(

View File

@@ -403,11 +403,11 @@ impl<'a> Context<'a> {
for the compiler"); for the compiler");
} else { } else {
self.gate_feature("custom_attribute", attr.span, self.gate_feature("custom_attribute", attr.span,
format!("The attribute `{}` is currently \ &format!("The attribute `{}` is currently \
unknown to the the compiler and \ unknown to the the compiler and \
may have meaning \ may have meaning \
added to it in the future", added to it in the future",
name).as_slice()); name));
} }
} }
} }

View File

@@ -80,7 +80,7 @@ fn main() {
.arg(format!("{} {}", .arg(format!("{} {}",
rustc, rustc,
main_file.as_str() main_file.as_str()
.unwrap()).as_slice()) .unwrap()))
.output().unwrap(); .output().unwrap();
let err = String::from_utf8_lossy(result.error.as_slice()); let err = String::from_utf8_lossy(result.error.as_slice());