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

+6-6
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

+1-1
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

+5-5
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

+6-6
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

+4-4
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

+1-1
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

+1-1
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

+3-3
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

+1-1
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

+1-1
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 {}",

src/librustc_bitflags/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
/// let mut flags = FLAG_A | FLAG_B;
8787
/// flags.clear();
8888
/// assert!(flags.is_empty());
89-
/// assert_eq!(format!("{:?}", flags).as_slice(), "hi!");
89+
/// assert_eq!(format!("{:?}", flags), "hi!");
9090
/// }
9191
/// ```
9292
///

src/librustc_borrowck/borrowck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
704704
self.tcx
705705
.sess
706706
.span_err(span,
707-
(format!("partial reinitialization of uninitialized \
707+
&format!("partial reinitialization of uninitialized \
708708
structure `{}`",
709-
self.loan_path_to_string(lp))).as_slice());
709+
self.loan_path_to_string(lp)));
710710
}
711711

712712
pub fn report_reassigned_immutable_variable(&self,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ impl LintPass for InvalidNoMangleItems {
20802080
!cx.exported_items.contains(&it.id) {
20812081
let msg = format!("static {} is marked #[no_mangle], but not exported",
20822082
it.ident);
2083-
cx.span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg.as_slice());
2083+
cx.span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, &msg);
20842084
}
20852085
},
20862086
ast::ItemConst(..) => {

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
14041404
ast_ty.span.lo <= r.span.lo && r.span.hi <= ast_ty.span.hi;
14051405
span_err!(tcx.sess, r.span, E0250,
14061406
"array length constant evaluation error: {}",
1407-
r.description().as_slice());
1407+
r.description());
14081408
if !subspan {
14091409
span_note!(tcx.sess, ast_ty.span, "for array length here")
14101410
}

src/librustc_typeck/check/dropck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>(
298298
match rcx.tcx().region_maps.opt_encl_scope(scope) {
299299
Some(parent_scope) => ty::ReScope(parent_scope),
300300
None => rcx.tcx().sess.span_bug(
301-
span, format!("no enclosing scope found for scope: {:?}",
302-
scope).as_slice()),
301+
span, &format!("no enclosing scope found for scope: {:?}",
302+
scope)),
303303
};
304304

305305
regionck::type_must_outlive(rcx, origin(), typ, parent_region);

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4620,7 +4620,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
46204620
Err(ref err) => {
46214621
span_err!(ccx.tcx.sess, err.span, E0080,
46224622
"constant evaluation error: {}",
4623-
err.description().as_slice());
4623+
err.description());
46244624
}
46254625
}
46264626
},

src/librustc_typeck/check/regionck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,9 @@ fn check_safety_of_rvalue_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 't
963963
rcx.tcx()
964964
.sess
965965
.span_bug(span,
966-
format!("unexpected rvalue region in rvalue \
967-
destructor safety checking: `{}`",
968-
region.repr(rcx.tcx())).as_slice());
966+
&format!("unexpected rvalue region in rvalue \
967+
destructor safety checking: `{}`",
968+
region.repr(rcx.tcx())));
969969
}
970970
}
971971
}

src/librustc_typeck/check/wf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
411411
Some(def_id) => {
412412
self.tcx().sess.fileline_help(
413413
span,
414-
format!("consider removing `{}` or using a marker such as `{}`",
415-
param_name.user_string(self.tcx()),
416-
ty::item_path_str(self.tcx(), def_id)).as_slice());
414+
&format!("consider removing `{}` or using a marker such as `{}`",
415+
param_name.user_string(self.tcx()),
416+
ty::item_path_str(self.tcx(), def_id)));
417417
}
418418
None => {
419419
// no lang items, no help!

src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,8 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
15901590
ast::ItemMac(..) => {
15911591
tcx.sess.span_bug(
15921592
it.span,
1593-
format!("compute_type_scheme_of_item: unexpected item type: {:?}",
1594-
it.node).as_slice());
1593+
&format!("compute_type_scheme_of_item: unexpected item type: {:?}",
1594+
it.node));
15951595
}
15961596
}
15971597
}

src/libserialize/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
//! let json_str: String = json_obj.to_string();
189189
//!
190190
//! // Deserialize like before
191-
//! let decoded: TestStruct = json::decode(json_str.as_slice()).unwrap();
191+
//! let decoded: TestStruct = json::decode(json_str)).unwrap();
192192
//! }
193193
//! ```
194194

src/libstd/env.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ mod tests {
780780
i += 1;
781781
}
782782
let n = make_rand_name();
783-
set_var(&n, s.as_slice());
784-
eq(var_os(&n), Some(s.as_slice()));
783+
set_var(&n, &s);
784+
eq(var_os(&n), Some(&s));
785785
}
786786

787787
#[test]
@@ -799,7 +799,7 @@ mod tests {
799799
let n = make_rand_name();
800800
let s = repeat("x").take(10000).collect::<String>();
801801
set_var(&n, &s);
802-
eq(var_os(&n), Some(s.as_slice()));
802+
eq(var_os(&n), Some(&s));
803803
remove_var(&n);
804804
eq(var_os(&n), None);
805805
}

src/libstd/fs/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ mod tests {
828828
macro_rules! error { ($e:expr, $s:expr) => (
829829
match $e {
830830
Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
831-
Err(ref err) => assert!(err.to_string().contains($s.as_slice()),
831+
Err(ref err) => assert!(err.to_string().contains($s),
832832
format!("`{}` did not contain `{}`", err, $s))
833833
}
834834
) }
@@ -880,7 +880,7 @@ mod tests {
880880
-1|0 => panic!("shouldn't happen"),
881881
n => str::from_utf8(&read_buf[..n]).unwrap().to_string()
882882
};
883-
assert_eq!(read_str.as_slice(), message);
883+
assert_eq!(read_str, message);
884884
}
885885
check!(fs::remove_file(filename));
886886
}
@@ -1107,7 +1107,7 @@ mod tests {
11071107
check!(check!(File::open(&f)).read(&mut mem));
11081108
let read_str = str::from_utf8(&mem).unwrap();
11091109
let expected = format!("{}{}", prefix, n.to_str().unwrap());
1110-
assert_eq!(expected.as_slice(), read_str);
1110+
assert_eq!(expected, read_str);
11111111
}
11121112
check!(fs::remove_file(&f));
11131113
}

src/libstd/process.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ mod tests {
812812
for (ref k, ref v) in env::vars() {
813813
// don't check windows magical empty-named variables
814814
assert!(k.is_empty() ||
815-
output.contains(format!("{}={}", *k, *v).as_slice()),
815+
output.contains(&format!("{}={}", *k, *v)),
816816
"output doesn't contain `{}={}`\n{}",
817817
k, v, output);
818818
}
@@ -830,12 +830,12 @@ mod tests {
830830
for &(ref k, ref v) in &r {
831831
// don't check android RANDOM variables
832832
if *k != "RANDOM".to_string() {
833-
assert!(output.contains(format!("{}={}",
834-
*k,
835-
*v).as_slice()) ||
836-
output.contains(format!("{}=\'{}\'",
837-
*k,
838-
*v).as_slice()));
833+
assert!(output.contains(&format!("{}={}",
834+
*k,
835+
*v)) ||
836+
output.contains(&format!("{}=\'{}\'",
837+
*k,
838+
*v)));
839839
}
840840
}
841841
}

src/libstd/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl Builder {
284284
stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
285285
}
286286
match their_thread.name() {
287-
Some(name) => unsafe { imp::set_name(name.as_slice()); },
287+
Some(name) => unsafe { imp::set_name(name); },
288288
None => {}
289289
}
290290
thread_info::set(

0 commit comments

Comments
 (0)