Skip to content

Commit b83b26b

Browse files
committed
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.
2 parents 638832e + 7981aa6 commit b83b26b

File tree

26 files changed

+63
-63
lines changed

26 files changed

+63
-63
lines changed

src/doc/style/errors/ergonomics.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fn write_info(info: &Info) -> Result<(), IoError> {
2222
let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
2323
Open, Write);
2424
// Early return on error
25-
try!(file.write_line(format!("name: {}", info.name).as_slice()));
26-
try!(file.write_line(format!("age: {}", info.age).as_slice()));
27-
try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
25+
try!(file.write_line(&format!("name: {}", info.name)));
26+
try!(file.write_line(&format!("age: {}", info.age)));
27+
try!(file.write_line(&format!("rating: {}", info.rating)));
2828
return Ok(());
2929
}
3030
```
@@ -44,15 +44,15 @@ fn write_info(info: &Info) -> Result<(), IoError> {
4444
let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
4545
Open, Write);
4646
// Early return on error
47-
match file.write_line(format!("name: {}", info.name).as_slice()) {
47+
match file.write_line(&format!("name: {}", info.name)) {
4848
Ok(_) => (),
4949
Err(e) => return Err(e)
5050
}
51-
match file.write_line(format!("age: {}", info.age).as_slice()) {
51+
match file.write_line(&format!("age: {}", info.age)) {
5252
Ok(_) => (),
5353
Err(e) => return Err(e)
5454
}
55-
return file.write_line(format!("rating: {}", info.rating).as_slice());
55+
return file.write_line(&format!("rating: {}", info.rating));
5656
}
5757
```
5858

src/libcollections/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
//! // for details, and the function `pad` can be used to pad strings.
199199
//! let decimals = f.precision().unwrap_or(3);
200200
//! let string = f64::to_str_exact(magnitude, decimals);
201-
//! f.pad_integral(true, "", string.as_slice())
201+
//! f.pad_integral(true, "", &string)
202202
//! }
203203
//! }
204204
//!

src/libcollections/string.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl String {
139139
/// ```rust
140140
/// let input = b"Hello \xF0\x90\x80World";
141141
/// let output = String::from_utf8_lossy(input);
142-
/// assert_eq!(output.as_slice(), "Hello \u{FFFD}World");
142+
/// assert_eq!(output, "Hello \u{FFFD}World");
143143
/// ```
144144
#[stable(feature = "rust1", since = "1.0.0")]
145145
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
@@ -355,7 +355,7 @@ impl String {
355355
/// ```
356356
/// let mut s = String::from_str("foo");
357357
/// s.push_str("bar");
358-
/// assert_eq!(s.as_slice(), "foobar");
358+
/// assert_eq!(s, "foobar");
359359
/// ```
360360
#[inline]
361361
#[stable(feature = "rust1", since = "1.0.0")]
@@ -450,7 +450,7 @@ impl String {
450450
/// s.push('1');
451451
/// s.push('2');
452452
/// s.push('3');
453-
/// assert_eq!(s.as_slice(), "abc123");
453+
/// assert_eq!(s, "abc123");
454454
/// ```
455455
#[inline]
456456
#[stable(feature = "rust1", since = "1.0.0")]
@@ -503,7 +503,7 @@ impl String {
503503
/// ```
504504
/// let mut s = String::from_str("hello");
505505
/// s.truncate(2);
506-
/// assert_eq!(s.as_slice(), "he");
506+
/// assert_eq!(s, "he");
507507
/// ```
508508
#[inline]
509509
#[stable(feature = "rust1", since = "1.0.0")]
@@ -622,7 +622,7 @@ impl String {
622622
/// assert!(vec == &[104, 101, 108, 108, 111]);
623623
/// vec.reverse();
624624
/// }
625-
/// assert_eq!(s.as_slice(), "olleh");
625+
/// assert_eq!(s, "olleh");
626626
/// ```
627627
#[inline]
628628
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/result.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@
178178
//! fn write_info(info: &Info) -> Result<(), IoError> {
179179
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
180180
//! // Early return on error
181-
//! if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) {
181+
//! if let Err(e) = file.write_line(&format!("name: {}", info.name)) {
182182
//! return Err(e)
183183
//! }
184-
//! if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) {
184+
//! if let Err(e) = file.write_line(&format!("age: {}", info.age)) {
185185
//! return Err(e)
186186
//! }
187-
//! return file.write_line(format!("rating: {}", info.rating).as_slice());
187+
//! return file.write_line(&format!("rating: {}", info.rating));
188188
//! }
189189
//! ```
190190
//!
@@ -202,9 +202,9 @@
202202
//! fn write_info(info: &Info) -> Result<(), IoError> {
203203
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
204204
//! // Early return on error
205-
//! try!(file.write_line(format!("name: {}", info.name).as_slice()));
206-
//! try!(file.write_line(format!("age: {}", info.age).as_slice()));
207-
//! try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
205+
//! try!(file.write_line(&format!("name: {}", info.name)));
206+
//! try!(file.write_line(&format!("age: {}", info.age)));
207+
//! try!(file.write_line(&format!("rating: {}", info.rating)));
208208
//! return Ok(());
209209
//! }
210210
//! ```

src/libgetopts/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//!
4747
//! fn print_usage(program: &str, opts: &[OptGroup]) {
4848
//! let brief = format!("Usage: {} [options]", program);
49-
//! print!("{}", usage(brief.as_slice(), opts));
49+
//! print!("{}", usage(brief, opts));
5050
//! }
5151
//!
5252
//! fn main() {
@@ -63,17 +63,17 @@
6363
//! Err(f) => { panic!(f.to_string()) }
6464
//! };
6565
//! if matches.opt_present("h") {
66-
//! print_usage(program.as_slice(), opts);
66+
//! print_usage(program, opts);
6767
//! return;
6868
//! }
6969
//! let output = matches.opt_str("o");
7070
//! let input = if !matches.free.is_empty() {
7171
//! matches.free[0].clone()
7272
//! } else {
73-
//! print_usage(program.as_slice(), opts);
73+
//! print_usage(program, opts);
7474
//! return;
7575
//! };
76-
//! do_work(input.as_slice(), output);
76+
//! do_work(input, output);
7777
//! }
7878
//! ```
7979

src/librustc/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'a> CrateReader<'a> {
493493
};
494494

495495
let dylib = library.dylib.clone();
496-
let register = should_link && self.existing_match(info.name.as_slice(),
496+
let register = should_link && self.existing_match(&info.name,
497497
None,
498498
PathKind::Crate).is_none();
499499
let metadata = if register {

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
276276
let subspan = p.span.lo <= err.span.lo && err.span.hi <= p.span.hi;
277277
cx.tcx.sess.span_err(err.span,
278278
&format!("constant evaluation error: {}",
279-
err.description().as_slice()));
279+
err.description()));
280280
if !subspan {
281281
cx.tcx.sess.span_note(p.span,
282282
"in pattern here")

src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
204204
pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val {
205205
match eval_const_expr_partial(tcx, e, None) {
206206
Ok(r) => r,
207-
Err(s) => tcx.sess.span_fatal(s.span, s.description().as_slice())
207+
Err(s) => tcx.sess.span_fatal(s.span, &s.description())
208208
}
209209
}
210210

@@ -665,14 +665,14 @@ pub fn compare_lit_exprs<'tcx>(tcx: &ty::ctxt<'tcx>,
665665
let a = match eval_const_expr_partial(tcx, a, ty_hint) {
666666
Ok(a) => a,
667667
Err(e) => {
668-
tcx.sess.span_err(a.span, e.description().as_slice());
668+
tcx.sess.span_err(a.span, &e.description());
669669
return None;
670670
}
671671
};
672672
let b = match eval_const_expr_partial(tcx, b, ty_hint) {
673673
Ok(b) => b,
674674
Err(e) => {
675-
tcx.sess.span_err(b.span, e.description().as_slice());
675+
tcx.sess.span_err(b.span, &e.description());
676676
return None;
677677
}
678678
};

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5485,7 +5485,7 @@ pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
54855485
Err(err) => {
54865486
span_err!(cx.sess, err.span, E0305,
54875487
"constant evaluation error: {}",
5488-
err.description().as_slice());
5488+
err.description());
54895489
}
54905490
}
54915491
} else {

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
115115
region::CodeExtent::Misc(_) => tag,
116116
region::CodeExtent::DestructionScope(_) => {
117117
new_string = format!("destruction scope surrounding {}", tag);
118-
new_string.as_slice()
118+
&*new_string
119119
}
120120
region::CodeExtent::Remainder(r) => {
121121
new_string = format!("block suffix following statement {}",

0 commit comments

Comments
 (0)