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

Diff for: src/bootstrap/check.rs

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

Diff for: src/grammar/verify.rs

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

Diff for: src/libcollections/linked_list.rs

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

Diff for: src/libgraphviz/lib.rs

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

Diff for: src/librustc/ich/fingerprint.rs

+2-2
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)

Diff for: src/librustc/lint/context.rs

+2-3
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));

Diff for: src/librustc/middle/stability.rs

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

Diff for: src/librustc_borrowck/borrowck/fragments.rs

+12-12
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;

Diff for: src/librustc_borrowck/borrowck/mod.rs

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

Diff for: src/librustc_borrowck/graphviz.rs

+1-1
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
});

Diff for: src/librustc_const_eval/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,10 @@ fn is_useful_specialized<'p, 'a:'p, 'tcx: 'a>(
680680
}).collect();
681681
let wild_patterns: Vec<_> = wild_patterns_owned.iter().collect();
682682
let matrix = Matrix(m.iter().flat_map(|r| {
683-
specialize(cx, &r[..], &ctor, &wild_patterns)
683+
specialize(cx, &r, &ctor, &wild_patterns)
684684
}).collect());
685685
match specialize(cx, v, &ctor, &wild_patterns) {
686-
Some(v) => match is_useful(cx, &matrix, &v[..], witness) {
686+
Some(v) => match is_useful(cx, &matrix, &v, witness) {
687687
UsefulWithWitness(witnesses) => UsefulWithWitness(
688688
witnesses.into_iter()
689689
.map(|witness| witness.apply_constructor(cx, &ctor, lty))

Diff for: src/librustc_const_eval/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
311311
for &(pat, hir_pat) in pats {
312312
let v = vec![pat];
313313

314-
match is_useful(cx, &seen, &v[..], LeaveOutWitness) {
314+
match is_useful(cx, &seen, &v, LeaveOutWitness) {
315315
NotUseful => {
316316
match source {
317317
hir::MatchSource::IfLetDesugar { .. } => {

Diff for: src/librustc_data_structures/accumulate_vec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ impl<A: Array> Deref for AccumulateVec<A> {
9191
type Target = [A::Element];
9292
fn deref(&self) -> &Self::Target {
9393
match *self {
94-
AccumulateVec::Array(ref v) => &v[..],
95-
AccumulateVec::Heap(ref v) => &v[..],
94+
AccumulateVec::Array(ref v) => v,
95+
AccumulateVec::Heap(ref v) => v,
9696
}
9797
}
9898
}
9999

100100
impl<A: Array> DerefMut for AccumulateVec<A> {
101101
fn deref_mut(&mut self) -> &mut [A::Element] {
102102
match *self {
103-
AccumulateVec::Array(ref mut v) => &mut v[..],
104-
AccumulateVec::Heap(ref mut v) => &mut v[..],
103+
AccumulateVec::Array(ref mut v) => v,
104+
AccumulateVec::Heap(ref mut v) => v,
105105
}
106106
}
107107
}

Diff for: src/librustc_data_structures/base_n.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn encode(n: u64, base: u64) -> String {
4848
#[test]
4949
fn test_encode() {
5050
fn test(n: u64, base: u64) {
51-
assert_eq!(Ok(n), u64::from_str_radix(&encode(n, base)[..], base as u32));
51+
assert_eq!(Ok(n), u64::from_str_radix(&encode(n, base), base as u32));
5252
}
5353

5454
for base in 2..37 {

Diff for: src/librustc_data_structures/blake2b.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Blake2bCtx {
3535
impl ::std::fmt::Debug for Blake2bCtx {
3636
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
3737
try!(write!(fmt, "hash: "));
38-
for v in &self.h[..] {
38+
for v in &self.h {
3939
try!(write!(fmt, "{:x}", v));
4040
}
4141
Ok(())

Diff for: src/librustc_data_structures/indexed_set.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ impl<T: Idx> IdxSet<T> {
9191
impl<T: Idx> Deref for IdxSetBuf<T> {
9292
type Target = IdxSet<T>;
9393
fn deref(&self) -> &IdxSet<T> {
94-
unsafe { IdxSet::from_slice(&self.bits[..]) }
94+
unsafe { IdxSet::from_slice(&self.bits) }
9595
}
9696
}
9797

9898
impl<T: Idx> DerefMut for IdxSetBuf<T> {
9999
fn deref_mut(&mut self) -> &mut IdxSet<T> {
100-
unsafe { IdxSet::from_slice_mut(&mut self.bits[..]) }
100+
unsafe { IdxSet::from_slice_mut(&mut self.bits) }
101101
}
102102
}
103103

@@ -135,11 +135,11 @@ impl<T: Idx> IdxSet<T> {
135135
}
136136

137137
pub fn words(&self) -> &[Word] {
138-
&self.bits[..]
138+
&self.bits
139139
}
140140

141141
pub fn words_mut(&mut self) -> &mut [Word] {
142-
&mut self.bits[..]
142+
&mut self.bits
143143
}
144144

145145
pub fn clone_from(&mut self, other: &IdxSet<T>) {

Diff for: src/librustc_driver/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
233233
// Extract input (string or file and optional path) from matches.
234234
fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>)> {
235235
if free_matches.len() == 1 {
236-
let ifile = &free_matches[0][..];
236+
let ifile = &free_matches[0];
237237
if ifile == "-" {
238238
let mut src = String::new();
239239
io::stdin().read_to_string(&mut src).unwrap();
@@ -800,7 +800,7 @@ Available lint options:
800800
for lint in lints {
801801
let name = lint.name_lower().replace("_", "-");
802802
println!(" {} {:7.7} {}",
803-
padded(&name[..]),
803+
padded(&name),
804804
lint.default_level.as_str(),
805805
lint.desc);
806806
}
@@ -838,7 +838,7 @@ Available lint options:
838838
.map(|x| x.to_string().replace("_", "-"))
839839
.collect::<Vec<String>>()
840840
.join(", ");
841-
println!(" {} {}", padded(&name[..]), desc);
841+
println!(" {} {}", padded(&name), desc);
842842
}
843843
println!("\n");
844844
};
@@ -945,7 +945,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
945945
.into_iter()
946946
.map(|x| x.opt_group)
947947
.collect();
948-
let matches = match getopts::getopts(&args[..], &all_groups) {
948+
let matches = match getopts::getopts(&args, &all_groups) {
949949
Ok(m) => m,
950950
Err(f) => early_error(ErrorOutputType::default(), &f.to_string()),
951951
};
@@ -1084,7 +1084,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
10841084
format!("we would appreciate a bug report: {}", BUG_REPORT_URL)];
10851085
for note in &xs {
10861086
handler.emit(&MultiSpan::new(),
1087-
&note[..],
1087+
&note,
10881088
errors::Level::Note);
10891089
}
10901090
if match env::var_os("RUST_BACKTRACE") {

Diff for: src/librustc_driver/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl UserIdentifiedItem {
589589
-> NodesMatchingUII<'a, 'hir> {
590590
match *self {
591591
ItemViaNode(node_id) => NodesMatchingDirect(Some(node_id).into_iter()),
592-
ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts[..])),
592+
ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts)),
593593
}
594594
}
595595

@@ -600,7 +600,7 @@ impl UserIdentifiedItem {
600600
user_option,
601601
self.reconstructed_input(),
602602
is_wrong_because);
603-
sess.fatal(&message[..])
603+
sess.fatal(&message)
604604
};
605605

606606
let mut saw_node = ast::DUMMY_NODE_ID;
@@ -771,7 +771,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
771771
fn expand_err_details(r: io::Result<()>) -> io::Result<()> {
772772
r.map_err(|ioerr| {
773773
io::Error::new(io::ErrorKind::Other,
774-
&format!("graphviz::render failed: {}", ioerr)[..])
774+
format!("graphviz::render failed: {}", ioerr))
775775
})
776776
}
777777
}

Diff for: src/librustc_driver/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
289289

290290
pub fn t_param(&self, index: u32) -> Ty<'tcx> {
291291
let name = format!("T{}", index);
292-
self.infcx.tcx.mk_param(index, Symbol::intern(&name[..]))
292+
self.infcx.tcx.mk_param(index, Symbol::intern(&name))
293293
}
294294

295295
pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region {

Diff for: src/librustc_incremental/persist/file_format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ pub fn read_file(sess: &Session, path: &Path) -> io::Result<Option<Vec<u8>>> {
9999
let rustc_version_str_len = rustc_version_str_len[0] as usize;
100100
let mut buffer = Vec::with_capacity(rustc_version_str_len);
101101
buffer.resize(rustc_version_str_len, 0);
102-
file.read_exact(&mut buffer[..])?;
102+
file.read_exact(&mut buffer)?;
103103

104-
if &buffer[..] != rustc_version().as_bytes() {
104+
if buffer != rustc_version().as_bytes() {
105105
report_format_mismatch(sess, path, "Different compiler version");
106106
return Ok(None);
107107
}

Diff for: src/librustc_lint/bad_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl NonCamelCaseTypes {
8888
} else {
8989
format!("{} `{}` should have a camel case name such as `{}`", sort, name, c)
9090
};
91-
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m[..]);
91+
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m);
9292
}
9393
}
9494
}

0 commit comments

Comments
 (0)