From 061d84399e66dc3d47c567370b71e047202ba60f Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Sat, 7 Mar 2015 18:08:48 -0800 Subject: [PATCH 1/2] remove uses of as_slice where deref coercions can be used --- src/librustc/metadata/creader.rs | 2 +- src/librustc/middle/check_match.rs | 2 +- src/librustc/middle/const_eval.rs | 6 +++--- src/librustc/middle/ty.rs | 2 +- src/librustc/util/ppaux.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 4 ++-- src/librustc_lint/builtin.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/dropck.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/regionck.rs | 6 +++--- src/librustc_typeck/check/wf.rs | 6 +++--- src/librustc_typeck/collect.rs | 4 ++-- src/libstd/env.rs | 6 +++--- src/libstd/fs/mod.rs | 6 +++--- src/libstd/process.rs | 14 +++++++------- src/libstd/thread.rs | 2 +- src/libsyntax/feature_gate.rs | 4 ++-- src/test/run-make/unicode-input/span_length.rs | 2 +- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 515e85410d9fd..00a47ce17dae0 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -493,7 +493,7 @@ impl<'a> CrateReader<'a> { }; 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, PathKind::Crate).is_none(); let metadata = if register { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 1088535998506..40bba6fb0ac7c 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -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; cx.tcx.sess.span_err(err.span, &format!("constant evaluation error: {}", - err.description().as_slice())); + err.description())); if !subspan { cx.tcx.sess.span_note(p.span, "in pattern here") diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 896a0010e7e7f..f215b59a6cd0e 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -204,7 +204,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val { match eval_const_expr_partial(tcx, e, None) { 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) { Ok(a) => a, Err(e) => { - tcx.sess.span_err(a.span, e.description().as_slice()); + tcx.sess.span_err(a.span, &e.description()); return None; } }; let b = match eval_const_expr_partial(tcx, b, ty_hint) { Ok(b) => b, Err(e) => { - tcx.sess.span_err(b.span, e.description().as_slice()); + tcx.sess.span_err(b.span, &e.description()); return None; } }; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index add829074c4f0..014da6983b5b4 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -5485,7 +5485,7 @@ pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId) Err(err) => { span_err!(cx.sess, err.span, E0305, "constant evaluation error: {}", - err.description().as_slice()); + err.description()); } } } else { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 09a1225441477..f41d969c1a271 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -115,7 +115,7 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region) region::CodeExtent::Misc(_) => tag, region::CodeExtent::DestructionScope(_) => { new_string = format!("destruction scope surrounding {}", tag); - new_string.as_slice() + &*new_string } region::CodeExtent::Remainder(r) => { new_string = format!("block suffix following statement {}", diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 42b3555b54ede..b176d8d4118a3 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -704,9 +704,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.tcx .sess .span_err(span, - (format!("partial reinitialization of uninitialized \ + &format!("partial reinitialization of uninitialized \ structure `{}`", - self.loan_path_to_string(lp))).as_slice()); + self.loan_path_to_string(lp))); } pub fn report_reassigned_immutable_variable(&self, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 1eea52fe1bb20..c24f170a381c6 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -2080,7 +2080,7 @@ impl LintPass for InvalidNoMangleItems { !cx.exported_items.contains(&it.id) { let msg = format!("static {} is marked #[no_mangle], but not exported", 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(..) => { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 00e9e76d81903..2c7a9bf8020c3 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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; span_err!(tcx.sess, r.span, E0250, "array length constant evaluation error: {}", - r.description().as_slice()); + r.description()); if !subspan { span_note!(tcx.sess, ast_ty.span, "for array length here") } diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index cffd74ccd7218..9c48ac43ee468 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -298,8 +298,8 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>( match rcx.tcx().region_maps.opt_encl_scope(scope) { Some(parent_scope) => ty::ReScope(parent_scope), None => rcx.tcx().sess.span_bug( - span, format!("no enclosing scope found for scope: {:?}", - scope).as_slice()), + span, &format!("no enclosing scope found for scope: {:?}", + scope)), }; regionck::type_must_outlive(rcx, origin(), typ, parent_region); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 595a2295674a1..44500ce0bbb7f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4620,7 +4620,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, Err(ref err) => { span_err!(ccx.tcx.sess, err.span, E0080, "constant evaluation error: {}", - err.description().as_slice()); + err.description()); } } }, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index a3e98b0c4c658..e1bcad2af37d6 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -963,9 +963,9 @@ fn check_safety_of_rvalue_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 't rcx.tcx() .sess .span_bug(span, - format!("unexpected rvalue region in rvalue \ - destructor safety checking: `{}`", - region.repr(rcx.tcx())).as_slice()); + &format!("unexpected rvalue region in rvalue \ + destructor safety checking: `{}`", + region.repr(rcx.tcx()))); } } } diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 8185f48cb8c70..32bd40ebda2de 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -411,9 +411,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { Some(def_id) => { self.tcx().sess.fileline_help( span, - format!("consider removing `{}` or using a marker such as `{}`", - param_name.user_string(self.tcx()), - ty::item_path_str(self.tcx(), def_id)).as_slice()); + &format!("consider removing `{}` or using a marker such as `{}`", + param_name.user_string(self.tcx()), + ty::item_path_str(self.tcx(), def_id))); } None => { // no lang items, no help! diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 77e3b6ee64bb8..460af67001989 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1590,8 +1590,8 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, ast::ItemMac(..) => { tcx.sess.span_bug( it.span, - format!("compute_type_scheme_of_item: unexpected item type: {:?}", - it.node).as_slice()); + &format!("compute_type_scheme_of_item: unexpected item type: {:?}", + it.node)); } } } diff --git a/src/libstd/env.rs b/src/libstd/env.rs index c052a69bc343a..b2ef04a5d632c 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -780,8 +780,8 @@ mod tests { i += 1; } let n = make_rand_name(); - set_var(&n, s.as_slice()); - eq(var_os(&n), Some(s.as_slice())); + set_var(&n, &s); + eq(var_os(&n), Some(&s)); } #[test] @@ -799,7 +799,7 @@ mod tests { let n = make_rand_name(); let s = repeat("x").take(10000).collect::(); set_var(&n, &s); - eq(var_os(&n), Some(s.as_slice())); + eq(var_os(&n), Some(&s)); remove_var(&n); eq(var_os(&n), None); } diff --git a/src/libstd/fs/mod.rs b/src/libstd/fs/mod.rs index 80ec9909824bb..9f9163eb9e69f 100644 --- a/src/libstd/fs/mod.rs +++ b/src/libstd/fs/mod.rs @@ -828,7 +828,7 @@ mod tests { macro_rules! error { ($e:expr, $s:expr) => ( match $e { 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)) } ) } @@ -880,7 +880,7 @@ mod tests { -1|0 => panic!("shouldn't happen"), 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)); } @@ -1107,7 +1107,7 @@ mod tests { check!(check!(File::open(&f)).read(&mut mem)); let read_str = str::from_utf8(&mem).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)); } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d4392a0740a90..ec4fcec555622 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -812,7 +812,7 @@ mod tests { for (ref k, ref v) in env::vars() { // don't check windows magical empty-named variables assert!(k.is_empty() || - output.contains(format!("{}={}", *k, *v).as_slice()), + output.contains(&format!("{}={}", *k, *v)), "output doesn't contain `{}={}`\n{}", k, v, output); } @@ -830,12 +830,12 @@ mod tests { for &(ref k, ref v) in &r { // don't check android RANDOM variables if *k != "RANDOM".to_string() { - assert!(output.contains(format!("{}={}", - *k, - *v).as_slice()) || - output.contains(format!("{}=\'{}\'", - *k, - *v).as_slice())); + assert!(output.contains(&format!("{}={}", + *k, + *v)) || + output.contains(&format!("{}=\'{}\'", + *k, + *v))); } } } diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 0ce3ca1f97ac8..7d0df67959107 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -284,7 +284,7 @@ impl Builder { stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top); } match their_thread.name() { - Some(name) => unsafe { imp::set_name(name.as_slice()); }, + Some(name) => unsafe { imp::set_name(name); }, None => {} } thread_info::set( diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 425c517cb29fd..c3bac0cf57c75 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -403,11 +403,11 @@ impl<'a> Context<'a> { for the compiler"); } else { self.gate_feature("custom_attribute", attr.span, - format!("The attribute `{}` is currently \ + &format!("The attribute `{}` is currently \ unknown to the the compiler and \ may have meaning \ added to it in the future", - name).as_slice()); + name)); } } } diff --git a/src/test/run-make/unicode-input/span_length.rs b/src/test/run-make/unicode-input/span_length.rs index ef6c799336bd4..a6cb9fe0324d7 100644 --- a/src/test/run-make/unicode-input/span_length.rs +++ b/src/test/run-make/unicode-input/span_length.rs @@ -80,7 +80,7 @@ fn main() { .arg(format!("{} {}", rustc, main_file.as_str() - .unwrap()).as_slice()) + .unwrap())) .output().unwrap(); let err = String::from_utf8_lossy(result.error.as_slice()); From 7981aa6ac9165b0bb1a5f624b8802192b8ebc9ee Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Sat, 7 Mar 2015 22:30:12 -0800 Subject: [PATCH 2/2] doc: Fix extraneous as_slice()'s in docstrings --- src/doc/style/errors/ergonomics.md | 12 ++++++------ src/libcollections/fmt.rs | 2 +- src/libcollections/string.rs | 10 +++++----- src/libcore/result.rs | 12 ++++++------ src/libgetopts/lib.rs | 8 ++++---- src/librustc_bitflags/lib.rs | 2 +- src/libserialize/json.rs | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/doc/style/errors/ergonomics.md b/src/doc/style/errors/ergonomics.md index 33f1e82b187e7..d2fcf27e93cdf 100644 --- a/src/doc/style/errors/ergonomics.md +++ b/src/doc/style/errors/ergonomics.md @@ -22,9 +22,9 @@ fn write_info(info: &Info) -> Result<(), IoError> { let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); // Early return on error - try!(file.write_line(format!("name: {}", info.name).as_slice())); - try!(file.write_line(format!("age: {}", info.age).as_slice())); - try!(file.write_line(format!("rating: {}", info.rating).as_slice())); + try!(file.write_line(&format!("name: {}", info.name))); + try!(file.write_line(&format!("age: {}", info.age))); + try!(file.write_line(&format!("rating: {}", info.rating))); 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"), Open, Write); // Early return on error - match file.write_line(format!("name: {}", info.name).as_slice()) { + match file.write_line(&format!("name: {}", info.name)) { Ok(_) => (), Err(e) => return Err(e) } - match file.write_line(format!("age: {}", info.age).as_slice()) { + match file.write_line(&format!("age: {}", info.age)) { Ok(_) => (), Err(e) => return Err(e) } - return file.write_line(format!("rating: {}", info.rating).as_slice()); + return file.write_line(&format!("rating: {}", info.rating)); } ``` diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index c88be80679da4..15a66bd80d02b 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -198,7 +198,7 @@ //! // for details, and the function `pad` can be used to pad strings. //! let decimals = f.precision().unwrap_or(3); //! let string = f64::to_str_exact(magnitude, decimals); -//! f.pad_integral(true, "", string.as_slice()) +//! f.pad_integral(true, "", &string) //! } //! } //! diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d6ec8f0d979e0..051fa1a8612f3 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -139,7 +139,7 @@ impl String { /// ```rust /// let input = b"Hello \xF0\x90\x80World"; /// 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")] 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"); /// s.push_str("bar"); - /// assert_eq!(s.as_slice(), "foobar"); + /// assert_eq!(s, "foobar"); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -450,7 +450,7 @@ impl String { /// s.push('1'); /// s.push('2'); /// s.push('3'); - /// assert_eq!(s.as_slice(), "abc123"); + /// assert_eq!(s, "abc123"); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -503,7 +503,7 @@ impl String { /// ``` /// let mut s = String::from_str("hello"); /// s.truncate(2); - /// assert_eq!(s.as_slice(), "he"); + /// assert_eq!(s, "he"); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -622,7 +622,7 @@ impl String { /// assert!(vec == &[104, 101, 108, 108, 111]); /// vec.reverse(); /// } - /// assert_eq!(s.as_slice(), "olleh"); + /// assert_eq!(s, "olleh"); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/result.rs b/src/libcore/result.rs index b8271562d2e67..6c3afdf884953 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -178,13 +178,13 @@ //! fn write_info(info: &Info) -> Result<(), IoError> { //! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); //! // 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) //! } -//! 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 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> { //! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write); //! // Early return on error -//! try!(file.write_line(format!("name: {}", info.name).as_slice())); -//! try!(file.write_line(format!("age: {}", info.age).as_slice())); -//! try!(file.write_line(format!("rating: {}", info.rating).as_slice())); +//! try!(file.write_line(&format!("name: {}", info.name))); +//! try!(file.write_line(&format!("age: {}", info.age))); +//! try!(file.write_line(&format!("rating: {}", info.rating))); //! return Ok(()); //! } //! ``` diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 617edb4bea60c..38abf3881bdf6 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -46,7 +46,7 @@ //! //! fn print_usage(program: &str, opts: &[OptGroup]) { //! let brief = format!("Usage: {} [options]", program); -//! print!("{}", usage(brief.as_slice(), opts)); +//! print!("{}", usage(brief, opts)); //! } //! //! fn main() { @@ -63,17 +63,17 @@ //! Err(f) => { panic!(f.to_string()) } //! }; //! if matches.opt_present("h") { -//! print_usage(program.as_slice(), opts); +//! print_usage(program, opts); //! return; //! } //! let output = matches.opt_str("o"); //! let input = if !matches.free.is_empty() { //! matches.free[0].clone() //! } else { -//! print_usage(program.as_slice(), opts); +//! print_usage(program, opts); //! return; //! }; -//! do_work(input.as_slice(), output); +//! do_work(input, output); //! } //! ``` diff --git a/src/librustc_bitflags/lib.rs b/src/librustc_bitflags/lib.rs index c15ddf3ae779f..0367130c1320f 100644 --- a/src/librustc_bitflags/lib.rs +++ b/src/librustc_bitflags/lib.rs @@ -86,7 +86,7 @@ /// let mut flags = FLAG_A | FLAG_B; /// flags.clear(); /// assert!(flags.is_empty()); -/// assert_eq!(format!("{:?}", flags).as_slice(), "hi!"); +/// assert_eq!(format!("{:?}", flags), "hi!"); /// } /// ``` /// diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 0d445739b397f..6fc56522c6af1 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -188,7 +188,7 @@ //! let json_str: String = json_obj.to_string(); //! //! // Deserialize like before -//! let decoded: TestStruct = json::decode(json_str.as_slice()).unwrap(); +//! let decoded: TestStruct = json::decode(json_str)).unwrap(); //! } //! ```