Skip to content

Commit 46b93b2

Browse files
Rollup merge of #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 cdab137 + 4390a61 commit 46b93b2

File tree

19 files changed

+33
-40
lines changed

19 files changed

+33
-40
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ impl<'a> State<'a> {
16811681
self.ibox(INDENT_UNIT);
16821682
self.s.word("[");
16831683
self.print_inner_attributes_inline(attrs);
1684-
self.commasep_exprs(Inconsistent, &exprs[..]);
1684+
self.commasep_exprs(Inconsistent, exprs);
16851685
self.s.word("]");
16861686
self.end();
16871687
}
@@ -1722,7 +1722,7 @@ impl<'a> State<'a> {
17221722
self.print_inner_attributes_inline(attrs);
17231723
self.commasep_cmnt(
17241724
Consistent,
1725-
&fields[..],
1725+
fields,
17261726
|s, field| {
17271727
s.print_outer_attributes(&field.attrs);
17281728
s.ibox(INDENT_UNIT);
@@ -1757,7 +1757,7 @@ impl<'a> State<'a> {
17571757
fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>], attrs: &[ast::Attribute]) {
17581758
self.popen();
17591759
self.print_inner_attributes_inline(attrs);
1760-
self.commasep_exprs(Inconsistent, &exprs[..]);
1760+
self.commasep_exprs(Inconsistent, exprs);
17611761
if exprs.len() == 1 {
17621762
self.s.word(",");
17631763
}

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 1 addition & 1 deletion
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();

0 commit comments

Comments
 (0)