Skip to content

Commit eb447f4

Browse files
committed
Fix various useless derefs and slicings
1 parent 79feb94 commit eb447f4

File tree

46 files changed

+120
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+120
-122
lines changed

src/bootstrap/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ fn android_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
586586
.arg(ADB_TEST_DIR));
587587

588588
let target_dir = format!("{}/{}", ADB_TEST_DIR, target);
589-
build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir[..]]));
589+
build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir]));
590590

591591
for f in t!(build.sysroot_libdir(compiler, target).read_dir()) {
592592
let f = t!(f);

src/grammar/verify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
196196
let toknum = &s[content_end + 3 .. toknum_end];
197197

198198
let not_found = format!("didn't find token {:?} in the map", toknum);
199-
let proto_tok = tokens.get(toknum).expect(&not_found[..]);
199+
let proto_tok = tokens.get(toknum).expect(&not_found);
200200

201201
let nm = Symbol::intern(content);
202202

@@ -304,14 +304,14 @@ fn main() {
304304
let mut token_file = File::open(&Path::new(&args.next().unwrap())).unwrap();
305305
let mut token_list = String::new();
306306
token_file.read_to_string(&mut token_list).unwrap();
307-
let token_map = parse_token_list(&token_list[..]);
307+
let token_map = parse_token_list(&token_list);
308308

309309
let stdin = std::io::stdin();
310310
let lock = stdin.lock();
311311
let lines = lock.lines();
312312
let antlr_tokens = lines.map(|l| parse_antlr_token(l.unwrap().trim(),
313313
&token_map,
314-
&surrogate_pairs_pos[..],
314+
&surrogate_pairs_pos,
315315
has_bom));
316316

317317
for antlr_tok in antlr_tokens {

src/libcollections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ mod tests {
13761376
thread::spawn(move || {
13771377
check_links(&n);
13781378
let a: &[_] = &[&1, &2, &3];
1379-
assert_eq!(a, &n.iter().collect::<Vec<_>>()[..]);
1379+
assert_eq!(a, &*n.iter().collect::<Vec<_>>());
13801380
})
13811381
.join()
13821382
.ok()

src/libgraphviz/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'a> LabelText<'a> {
554554
pub fn to_dot_string(&self) -> String {
555555
match self {
556556
&LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
557-
&EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s[..])),
557+
&EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
558558
&HtmlStr(ref s) => format!("<{}>", s),
559559
}
560560
}
@@ -587,7 +587,7 @@ impl<'a> LabelText<'a> {
587587
let mut prefix = self.pre_escaped_content().into_owned();
588588
let suffix = suffix.pre_escaped_content();
589589
prefix.push_str(r"\n\n");
590-
prefix.push_str(&suffix[..]);
590+
prefix.push_str(&suffix);
591591
EscStr(prefix.into_cow())
592592
}
593593
}
@@ -878,7 +878,7 @@ mod tests {
878878
type Node = Node;
879879
type Edge = &'a Edge;
880880
fn graph_id(&'a self) -> Id<'a> {
881-
Id::new(&self.name[..]).unwrap()
881+
Id::new(self.name).unwrap()
882882
}
883883
fn node_id(&'a self, n: &Node) -> Id<'a> {
884884
id_name(n)

src/librustc/ich/fingerprint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Fingerprint {
5555
impl Encodable for Fingerprint {
5656
#[inline]
5757
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
58-
for &byte in &self.0[..] {
58+
for &byte in &self.0 {
5959
s.emit_u8(byte)?;
6060
}
6161
Ok(())
@@ -66,7 +66,7 @@ impl Decodable for Fingerprint {
6666
#[inline]
6767
fn decode<D: Decoder>(d: &mut D) -> Result<Fingerprint, D::Error> {
6868
let mut result = Fingerprint([0u8; FINGERPRINT_LENGTH]);
69-
for byte in &mut result.0[..] {
69+
for byte in &mut result.0 {
7070
*byte = d.read_u8()?;
7171
}
7272
Ok(result)

src/librustc/lint/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use std::cmp;
4040
use std::default::Default as StdDefault;
4141
use std::mem;
4242
use std::fmt;
43-
use std::ops::Deref;
4443
use syntax::attr;
4544
use syntax::ast;
4645
use syntax::symbol::Symbol;
@@ -485,7 +484,7 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
485484
Allow => bug!("earlier conditional return should handle Allow case")
486485
};
487486
let hyphen_case_lint_name = name.replace("_", "-");
488-
if lint_flag_val.as_str().deref() == name {
487+
if lint_flag_val.as_str() == name {
489488
err.note(&format!("requested on the command line with `{} {}`",
490489
flag, hyphen_case_lint_name));
491490
} else {
@@ -496,7 +495,7 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
496495
},
497496
Node(lint_attr_name, src) => {
498497
def = Some(src);
499-
if lint_attr_name.as_str().deref() != name {
498+
if lint_attr_name.as_str() != name {
500499
let level_str = level.as_str();
501500
err.note(&format!("#[{}({})] implied by #[{}({})]",
502501
level_str, name, level_str, lint_attr_name));

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
536536
if !self.stability.borrow().active_features.contains(feature) {
537537
let msg = match *reason {
538538
Some(ref r) => format!("use of unstable library feature '{}': {}",
539-
&feature.as_str(), &r),
539+
feature.as_str(), &r),
540540
None => format!("use of unstable library feature '{}'", &feature)
541541
};
542542
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,

src/librustc_borrowck/borrowck/fragments.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx
267267
// First, filter out duplicates
268268
moved.sort();
269269
moved.dedup();
270-
debug!("fragments 1 moved: {:?}", path_lps(&moved[..]));
270+
debug!("fragments 1 moved: {:?}", path_lps(&moved));
271271

272272
assigned.sort();
273273
assigned.dedup();
274-
debug!("fragments 1 assigned: {:?}", path_lps(&assigned[..]));
274+
debug!("fragments 1 assigned: {:?}", path_lps(&assigned));
275275

276276
// Second, build parents from the moved and assigned.
277277
for m in &moved {
@@ -291,14 +291,14 @@ pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx
291291

292292
parents.sort();
293293
parents.dedup();
294-
debug!("fragments 2 parents: {:?}", path_lps(&parents[..]));
294+
debug!("fragments 2 parents: {:?}", path_lps(&parents));
295295

296296
// Third, filter the moved and assigned fragments down to just the non-parents
297-
moved.retain(|f| non_member(*f, &parents[..]));
298-
debug!("fragments 3 moved: {:?}", path_lps(&moved[..]));
297+
moved.retain(|f| non_member(*f, &parents));
298+
debug!("fragments 3 moved: {:?}", path_lps(&moved));
299299

300-
assigned.retain(|f| non_member(*f, &parents[..]));
301-
debug!("fragments 3 assigned: {:?}", path_lps(&assigned[..]));
300+
assigned.retain(|f| non_member(*f, &parents));
301+
debug!("fragments 3 assigned: {:?}", path_lps(&assigned));
302302

303303
// Fourth, build the leftover from the moved, assigned, and parents.
304304
for m in &moved {
@@ -316,16 +316,16 @@ pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx
316316

317317
unmoved.sort();
318318
unmoved.dedup();
319-
debug!("fragments 4 unmoved: {:?}", frag_lps(&unmoved[..]));
319+
debug!("fragments 4 unmoved: {:?}", frag_lps(&unmoved));
320320

321321
// Fifth, filter the leftover fragments down to its core.
322322
unmoved.retain(|f| match *f {
323323
AllButOneFrom(_) => true,
324-
Just(mpi) => non_member(mpi, &parents[..]) &&
325-
non_member(mpi, &moved[..]) &&
326-
non_member(mpi, &assigned[..])
324+
Just(mpi) => non_member(mpi, &parents) &&
325+
non_member(mpi, &moved) &&
326+
non_member(mpi, &assigned)
327327
});
328-
debug!("fragments 5 unmoved: {:?}", frag_lps(&unmoved[..]));
328+
debug!("fragments 5 unmoved: {:?}", frag_lps(&unmoved));
329329

330330
// Swap contents back in.
331331
fragments.unmoved_fragments = unmoved;

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) {
112112
&flowed_moves.move_data,
113113
owner_id);
114114

115-
check_loans::check_loans(bccx, &loan_dfcx, &flowed_moves, &all_loans[..], body);
115+
check_loans::check_loans(bccx, &loan_dfcx, &flowed_moves, &all_loans, body);
116116
}
117117

118118
fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,

src/librustc_borrowck/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> {
8888
set.push_str(", ");
8989
}
9090
let loan_str = self.borrowck_ctxt.loan_path_to_string(&lp);
91-
set.push_str(&loan_str[..]);
91+
set.push_str(&loan_str);
9292
saw_some = true;
9393
true
9494
});

0 commit comments

Comments
 (0)