1
Fork 0

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
This commit is contained in:
Matthias Krüger 2021-02-16 00:30:06 +01:00
parent d1206f950f
commit 4390a61b64
19 changed files with 33 additions and 40 deletions

View file

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

View file

@ -2374,7 +2374,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
crate::collect::placeholder_type_error(
tcx,
ident_span.map(|sp| sp.shrink_to_hi()),
&generics.params[..],
generics.params,
visitor.0,
true,
hir_ty,

View file

@ -897,7 +897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return (
path.res,
opt_qself.as_ref().map(|qself| self.to_ty(qself)),
&path.segments[..],
path.segments,
);
}
QPath::TypeRelative(ref qself, ref segment) => (self.to_ty(qself), qself, segment),

View file

@ -600,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
if let Some(hir::Node::Item(hir::Item { kind, .. })) = node {
if let Some(g) = kind.generics() {
let key = match &g.where_clause.predicates[..] {
let key = match g.where_clause.predicates {
[.., pred] => (pred.span().shrink_to_hi(), false),
[] => (
g.where_clause

View file

@ -229,14 +229,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_item(item);
placeholder_type_error(
tcx,
Some(generics.span),
&generics.params[..],
visitor.0,
suggest,
None,
);
placeholder_type_error(tcx, Some(generics.span), generics.params, visitor.0, suggest, None);
}
impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
@ -417,7 +410,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
| hir::ItemKind::Struct(_, generics)
| hir::ItemKind::Union(_, generics) => {
let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics);
let (lt_sp, sugg) = match &generics.params[..] {
let (lt_sp, sugg) = match generics.params {
[] => (generics.span, format!("<{}>", lt_name)),
[bound, ..] => {
(bound.span.shrink_to_lo(), format!("{}, ", lt_name))