Skip to content

Commit fcbf20b

Browse files
authored
Rollup merge of rust-lang#82163 - matthiaskrgr:slice, r=jyn514
avoid full-slicing slices If we already have a slice, there is no need to get another full-range slice from that, just use the original. clippy::redundant_slicing
2 parents 1f2c806 + 4390a61 commit fcbf20b

File tree

19 files changed

+33
-40
lines changed

19 files changed

+33
-40
lines changed

compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
135135

136136
let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
137137
hir::ItemKind::Impl(hir::Impl { ref generics, .. })
138-
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
138+
| hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params,
139139
_ => &[],
140140
};
141141
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {

compiler/rustc_ast_pretty/src/pprust/state.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ impl<'a> State<'a> {
16821682
self.ibox(INDENT_UNIT);
16831683
self.s.word("[");
16841684
self.print_inner_attributes_inline(attrs);
1685-
self.commasep_exprs(Inconsistent, &exprs[..]);
1685+
self.commasep_exprs(Inconsistent, exprs);
16861686
self.s.word("]");
16871687
self.end();
16881688
}
@@ -1723,7 +1723,7 @@ impl<'a> State<'a> {
17231723
self.print_inner_attributes_inline(attrs);
17241724
self.commasep_cmnt(
17251725
Consistent,
1726-
&fields[..],
1726+
fields,
17271727
|s, field| {
17281728
s.print_outer_attributes(&field.attrs);
17291729
s.ibox(INDENT_UNIT);
@@ -1758,7 +1758,7 @@ impl<'a> State<'a> {
17581758
fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>], attrs: &[ast::Attribute]) {
17591759
self.popen();
17601760
self.print_inner_attributes_inline(attrs);
1761-
self.commasep_exprs(Inconsistent, &exprs[..]);
1761+
self.commasep_exprs(Inconsistent, exprs);
17621762
if exprs.len() == 1 {
17631763
self.s.word(",");
17641764
}

compiler/rustc_builtin_macros/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'a, 'b> Context<'a, 'b> {
270270
parse::ArgumentNamed(s) => Named(s),
271271
};
272272

273-
let ty = Placeholder(match &arg.format.ty[..] {
273+
let ty = Placeholder(match arg.format.ty {
274274
"" => "Display",
275275
"?" => "Debug",
276276
"e" => "LowerExp",

compiler/rustc_builtin_macros/src/format_foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub mod printf {
312312
return Some((Substitution::Escape, &s[start + 2..]));
313313
}
314314

315-
Cur::new_at(&s[..], start)
315+
Cur::new_at(s, start)
316316
};
317317

318318
// This is meant to be a translation of the following regex:
@@ -673,7 +673,7 @@ pub mod shell {
673673
_ => { /* fall-through */ }
674674
}
675675

676-
Cur::new_at(&s[..], start)
676+
Cur::new_at(s, start)
677677
};
678678

679679
let at = at.at_next_cp()?;

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
709709
let (tup, args) = args.split_last().unwrap();
710710
(args, Some(tup))
711711
} else {
712-
(&args[..], None)
712+
(args, None)
713713
};
714714

715715
'make_args: for (i, arg) in first_args.iter().enumerate() {

compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a> State<'a> {
392392
&f.decl,
393393
None,
394394
&f.generic_params,
395-
&f.param_names[..],
395+
f.param_names,
396396
);
397397
}
398398
hir::TyKind::OpaqueDef(..) => self.s.word("/*impl Trait*/"),
@@ -1200,7 +1200,7 @@ impl<'a> State<'a> {
12001200
self.s.word("{");
12011201
self.commasep_cmnt(
12021202
Consistent,
1203-
&fields[..],
1203+
fields,
12041204
|s, field| {
12051205
s.ibox(INDENT_UNIT);
12061206
if !field.is_shorthand {

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
671671
if !impl_candidates.is_empty() && e.span.contains(span) {
672672
if let Some(expr) = exprs.first() {
673673
if let ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind {
674-
if let [path_segment] = &path.segments[..] {
674+
if let [path_segment] = path.segments {
675675
let candidate_len = impl_candidates.len();
676676
let suggestions = impl_candidates.iter().map(|candidate| {
677677
format!(

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl EncodeContext<'a, 'tcx> {
866866

867867
fn encode_variances_of(&mut self, def_id: DefId) {
868868
debug!("EncodeContext::encode_variances_of({:?})", def_id);
869-
record!(self.tables.variances[def_id] <- &self.tcx.variances_of(def_id)[..]);
869+
record!(self.tables.variances[def_id] <- self.tcx.variances_of(def_id));
870870
}
871871

872872
fn encode_item_type(&mut self, def_id: DefId) {

compiler/rustc_middle/src/hir/map/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -854,22 +854,22 @@ impl<'hir> Map<'hir> {
854854
/// corresponding to the node-ID.
855855
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
856856
self.find_entry(id).map_or(&[], |entry| match entry.node {
857-
Node::Param(a) => &a.attrs[..],
857+
Node::Param(a) => a.attrs,
858858
Node::Local(l) => &l.attrs[..],
859-
Node::Item(i) => &i.attrs[..],
860-
Node::ForeignItem(fi) => &fi.attrs[..],
861-
Node::TraitItem(ref ti) => &ti.attrs[..],
862-
Node::ImplItem(ref ii) => &ii.attrs[..],
863-
Node::Variant(ref v) => &v.attrs[..],
864-
Node::Field(ref f) => &f.attrs[..],
859+
Node::Item(i) => i.attrs,
860+
Node::ForeignItem(fi) => fi.attrs,
861+
Node::TraitItem(ref ti) => ti.attrs,
862+
Node::ImplItem(ref ii) => ii.attrs,
863+
Node::Variant(ref v) => v.attrs,
864+
Node::Field(ref f) => f.attrs,
865865
Node::Expr(ref e) => &*e.attrs,
866866
Node::Stmt(ref s) => s.kind.attrs(|id| self.item(id.id)),
867867
Node::Arm(ref a) => &*a.attrs,
868-
Node::GenericParam(param) => &param.attrs[..],
868+
Node::GenericParam(param) => param.attrs,
869869
// Unit/tuple structs/variants take the attributes straight from
870870
// the struct/variant definition.
871871
Node::Ctor(..) => self.attrs(self.get_parent_item(id)),
872-
Node::Crate(item) => &item.attrs[..],
872+
Node::Crate(item) => item.attrs,
873873
Node::MacroDef(def) => def.attrs,
874874
Node::AnonConst(..)
875875
| Node::PathSegment(..)

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'sess> OnDiskCache<'sess> {
427427

428428
fn sorted_cnums_including_local_crate(tcx: TyCtxt<'_>) -> Vec<CrateNum> {
429429
let mut cnums = vec![LOCAL_CRATE];
430-
cnums.extend_from_slice(&tcx.crates()[..]);
430+
cnums.extend_from_slice(tcx.crates());
431431
cnums.sort_unstable();
432432
// Just to be sure...
433433
cnums.dedup();

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
11051105
}
11061106

11071107
if let Some(items) = self.diagnostic_metadata.current_trait_assoc_items {
1108-
for assoc_item in &items[..] {
1108+
for assoc_item in items {
11091109
if assoc_item.ident == ident {
11101110
return Some(match &assoc_item.kind {
11111111
ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst,

compiler/rustc_target/src/spec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ impl Target {
14921492
} );
14931493
($key_name:ident = $json_name:expr, optional) => ( {
14941494
let name = $json_name;
1495-
if let Some(o) = obj.find(&name[..]) {
1495+
if let Some(o) = obj.find(name) {
14961496
base.$key_name = o
14971497
.as_string()
14981498
.map(|s| s.to_string() );

compiler/rustc_typeck/src/astconv/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
237237
}
238238
}
239239
if let ([], [bound]) = (&potential_assoc_types[..], &trait_bounds) {
240-
match &bound.trait_ref.path.segments[..] {
240+
match bound.trait_ref.path.segments {
241241
// FIXME: `trait_ref.path.span` can point to a full path with multiple
242242
// segments, even though `trait_ref.path.segments` is of length `1`. Work
243243
// around that bug here, even though it should be fixed elsewhere.

compiler/rustc_typeck/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
23692369
crate::collect::placeholder_type_error(
23702370
tcx,
23712371
ident_span.map(|sp| sp.shrink_to_hi()),
2372-
&generics.params[..],
2372+
generics.params,
23732373
visitor.0,
23742374
true,
23752375
hir_ty,

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
898898
return (
899899
path.res,
900900
opt_qself.as_ref().map(|qself| self.to_ty(qself)),
901-
&path.segments[..],
901+
path.segments,
902902
);
903903
}
904904
QPath::TypeRelative(ref qself, ref segment) => (self.to_ty(qself), qself, segment),

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
601601
});
602602
if let Some(hir::Node::Item(hir::Item { kind, .. })) = node {
603603
if let Some(g) = kind.generics() {
604-
let key = match &g.where_clause.predicates[..] {
604+
let key = match g.where_clause.predicates {
605605
[.., pred] => (pred.span().shrink_to_hi(), false),
606606
[] => (
607607
g.where_clause

compiler/rustc_typeck/src/collect.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
229229
let mut visitor = PlaceholderHirTyCollector::default();
230230
visitor.visit_item(item);
231231

232-
placeholder_type_error(
233-
tcx,
234-
Some(generics.span),
235-
&generics.params[..],
236-
visitor.0,
237-
suggest,
238-
None,
239-
);
232+
placeholder_type_error(tcx, Some(generics.span), generics.params, visitor.0, suggest, None);
240233
}
241234

242235
impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
@@ -417,7 +410,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
417410
| hir::ItemKind::Struct(_, generics)
418411
| hir::ItemKind::Union(_, generics) => {
419412
let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics);
420-
let (lt_sp, sugg) = match &generics.params[..] {
413+
let (lt_sp, sugg) = match generics.params {
421414
[] => (generics.span, format!("<{}>", lt_name)),
422415
[bound, ..] => {
423416
(bound.span.shrink_to_lo(), format!("{}, ", lt_name))

src/bootstrap/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
347347
};
348348

349349
// Done specifying what options are possible, so do the getopts parsing
350-
let matches = opts.parse(&args[..]).unwrap_or_else(|e| {
350+
let matches = opts.parse(args).unwrap_or_else(|e| {
351351
// Invalid argument/option format
352352
println!("\n{}\n", e);
353353
usage(1, &opts, false, &subcommand_help);

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ where
975975
{
976976
fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
977977
FnDecl {
978-
inputs: (&self.0.inputs[..], self.1).clean(cx),
978+
inputs: (self.0.inputs, self.1).clean(cx),
979979
output: self.0.output.clean(cx),
980980
c_variadic: self.0.c_variadic,
981981
attrs: Attributes::default(),
@@ -1939,7 +1939,7 @@ impl Clean<String> for Symbol {
19391939
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
19401940
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
19411941
let (generic_params, decl) = enter_impl_trait(cx, || {
1942-
(self.generic_params.clean(cx), (&*self.decl, &self.param_names[..]).clean(cx))
1942+
(self.generic_params.clean(cx), (&*self.decl, self.param_names).clean(cx))
19431943
});
19441944
BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
19451945
}

0 commit comments

Comments
 (0)