Skip to content

Commit 061d843

Browse files
committed
remove uses of as_slice where deref coercions can be used
1 parent 14ce607 commit 061d843

File tree

19 files changed

+39
-39
lines changed

19 files changed

+39
-39
lines changed

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_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/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(

src/libsyntax/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ impl<'a> Context<'a> {
403403
for the compiler");
404404
} else {
405405
self.gate_feature("custom_attribute", attr.span,
406-
format!("The attribute `{}` is currently \
406+
&format!("The attribute `{}` is currently \
407407
unknown to the the compiler and \
408408
may have meaning \
409409
added to it in the future",
410-
name).as_slice());
410+
name));
411411
}
412412
}
413413
}

src/test/run-make/unicode-input/span_length.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn main() {
8080
.arg(format!("{} {}",
8181
rustc,
8282
main_file.as_str()
83-
.unwrap()).as_slice())
83+
.unwrap()))
8484
.output().unwrap();
8585

8686
let err = String::from_utf8_lossy(result.error.as_slice());

0 commit comments

Comments
 (0)