Skip to content

Commit a7a20c0

Browse files
committed
hmm
1 parent 9157ded commit a7a20c0

File tree

9 files changed

+40
-44
lines changed

9 files changed

+40
-44
lines changed

clippy_config/src/conf.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::unnecessary_collect)]
12
use crate::ClippyConfiguration;
23
use crate::types::{
34
DisallowedPath, DisallowedPathWithoutReplacement, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour,
@@ -959,10 +960,10 @@ fn deserialize(file: &SourceFile) -> TryConf {
959960
// info for the user instead.
960961

961962
let names = conf.conf.module_item_order_groupings.grouping_names();
962-
let suggestion = suggest_candidate(grouping, names.iter().map(String::as_str))
963+
let suggestion = suggest_candidate(grouping, names.clone())
963964
.map(|s| format!(" perhaps you meant `{s}`?"))
964965
.unwrap_or_default();
965-
let names = names.iter().map(|s| format!("`{s}`")).join(", ");
966+
let names = names.map(|s| format!("`{s}`")).join(", ");
966967
let message = format!(
967968
"unknown ordering group: `{grouping}` was not specified in `module-items-ordered-within-groupings`,{suggestion} expected one of: {names}"
968969
);

clippy_config/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ impl SourceItemOrderingModuleItemGroupings {
422422
self.back_lut.get(item)
423423
}
424424

425-
pub fn grouping_names(&self) -> Vec<String> {
426-
self.groups.iter().map(|(name, _)| name.clone()).collect()
425+
pub fn grouping_names(&self) -> impl Iterator<Item = &str> + Clone {
426+
self.groups.iter().map(|(name, _)| &**name)
427427
}
428428

429429
pub fn is_grouping(&self, grouping: &str) -> bool {

clippy_lints/src/doc/suspicious_doc_comments.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Span;
1010
use super::SUSPICIOUS_DOC_COMMENTS;
1111

1212
pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) -> bool {
13-
let replacements: Vec<_> = collect_doc_replacements(attrs);
13+
let replacements = collect_doc_replacements(attrs).collect::<Vec<_>>();
1414

1515
if let Some((&(lo_span, _), &(hi_span, _))) = replacements.first().zip(replacements.last()) {
1616
span_lint_and_then(
@@ -33,26 +33,23 @@ pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) -> bool {
3333
}
3434
}
3535

36-
fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
37-
attrs
38-
.iter()
39-
.filter_map(|attr| {
40-
if let Attribute::Parsed(AttributeKind::DocComment {
41-
style: AttrStyle::Outer,
42-
kind,
43-
comment,
44-
..
45-
}) = attr
46-
&& let Some(com) = comment.as_str().strip_prefix('!')
47-
{
48-
let sugg = match kind {
49-
CommentKind::Line => format!("//!{com}"),
50-
CommentKind::Block => format!("/*!{com}*/"),
51-
};
52-
Some((attr.span(), sugg))
53-
} else {
54-
None
55-
}
56-
})
57-
.collect()
36+
fn collect_doc_replacements(attrs: &[Attribute]) -> impl Iterator<Item = (Span, String)> {
37+
attrs.iter().filter_map(|attr| {
38+
if let Attribute::Parsed(AttributeKind::DocComment {
39+
style: AttrStyle::Outer,
40+
kind,
41+
comment,
42+
..
43+
}) = attr
44+
&& let Some(com) = comment.as_str().strip_prefix('!')
45+
{
46+
let sugg = match kind {
47+
CommentKind::Line => format!("//!{com}"),
48+
CommentKind::Block => format!("/*!{com}*/"),
49+
};
50+
Some((attr.span(), sugg))
51+
} else {
52+
None
53+
}
54+
})
5855
}

clippy_lints/src/lifetimes.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn non_elidable_self_type<'tcx>(cx: &LateContext<'tcx>, func: &FnDecl<'tcx>, ide
394394
let mut visitor = RefVisitor::new(cx);
395395
visitor.visit_ty_unambig(self_ty);
396396

397-
!visitor.all_lts().is_empty()
397+
visitor.all_lts().next().is_some()
398398
} else {
399399
false
400400
}
@@ -404,7 +404,7 @@ fn non_elidable_self_type<'tcx>(cx: &LateContext<'tcx>, func: &FnDecl<'tcx>, ide
404404
/// relative order.
405405
#[must_use]
406406
fn named_lifetime_occurrences(lts: &[Lifetime]) -> Vec<(LocalDefId, usize)> {
407-
let mut occurrences = Vec::new();
407+
let mut occurrences: Vec<(LocalDefId, usize)> = Vec::new();
408408
for lt in lts {
409409
if let Some(curr_def_id) = named_lifetime(lt) {
410410
if let Some(pair) = occurrences
@@ -444,12 +444,8 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> {
444444
}
445445
}
446446

447-
fn all_lts(&self) -> Vec<Lifetime> {
448-
self.lts
449-
.iter()
450-
.chain(self.nested_elision_site_lts.iter())
451-
.copied()
452-
.collect::<Vec<_>>()
447+
fn all_lts(&self) -> impl Iterator<Item = Lifetime> {
448+
self.lts.iter().chain(self.nested_elision_site_lts.iter()).copied()
453449
}
454450

455451
fn abort(&self) -> bool {
@@ -472,7 +468,7 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
472468
{
473469
let mut sub_visitor = RefVisitor::new(self.cx);
474470
sub_visitor.visit_trait_ref(trait_ref);
475-
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
471+
self.nested_elision_site_lts.extend(sub_visitor.all_lts());
476472
} else {
477473
walk_poly_trait_ref(self, poly_tref);
478474
}
@@ -483,7 +479,7 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
483479
TyKind::FnPtr(&FnPtrTy { decl, .. }) => {
484480
let mut sub_visitor = RefVisitor::new(self.cx);
485481
sub_visitor.visit_fn_decl(decl);
486-
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
482+
self.nested_elision_site_lts.extend(sub_visitor.all_lts());
487483
},
488484
TyKind::TraitObject(bounds, lt) => {
489485
if !lt.is_elided() {
@@ -509,7 +505,7 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_
509505
let mut visitor = RefVisitor::new(cx);
510506
// walk the type F, it may not contain LT refs
511507
walk_unambig_ty(&mut visitor, pred.bounded_ty);
512-
if !visitor.all_lts().is_empty() {
508+
if visitor.all_lts().next().is_some() {
513509
return true;
514510
}
515511
// if the bounds define new lifetimes, they are fine to occur

clippy_lints/src/non_send_fields_in_send_ty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
107107
non_send_fields.push(NonSendField {
108108
def: field_def,
109109
ty: field_ty,
110-
generic_params: collect_generic_params(field_ty),
110+
generic_params: collect_generic_params(field_ty).collect(),
111111
});
112112
}
113113
}
@@ -170,14 +170,13 @@ impl NonSendField<'_> {
170170

171171
/// Given a type, collect all of its generic parameters.
172172
/// Example: `MyStruct<P, Box<Q, R>>` => `vec![P, Q, R]`
173-
fn collect_generic_params(ty: Ty<'_>) -> Vec<Ty<'_>> {
173+
fn collect_generic_params(ty: Ty<'_>) -> impl Iterator<Item = Ty<'_>> {
174174
ty.walk()
175175
.filter_map(|inner| match inner.kind() {
176176
GenericArgKind::Type(inner_ty) => Some(inner_ty),
177177
_ => None,
178178
})
179179
.filter(|&inner_ty| is_ty_param(inner_ty))
180-
.collect()
181180
}
182181

183182
/// Be more strict when the heuristic is disabled

clippy_lints/src/unnecessary_collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_lint::LateContext;
99
use rustc_middle::ty::{self};
1010
use rustc_span::Span;
1111

12-
use rustc_hir::*;
12+
use rustc_hir::{Body, ExprKind, FnDecl, Stmt, StmtKind};
1313
use rustc_lint::LateLintPass;
1414
use rustc_session::impl_lint_pass;
1515

@@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryCollect {
103103
&& let ty::Adt(v, args) = vec_ty.kind()
104104
&& cx.tcx.is_diagnostic_item(sym::Vec, v.did())
105105
// make sure we're collecting to just a vec, and not a vec<result> String or other such tomfoolery
106-
&& args.get(0).and_then(|x| x.as_type()) == Some(item)
106+
&& args.first().and_then(|x| x.as_type()) == Some(item)
107107
{
108108
span_lint_and_then(
109109
cx,

clippy_utils/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,12 +2876,13 @@ pub fn span_extract_comment(sm: &SourceMap, span: Span) -> String {
28762876
/// Returns all the comments a given span contains.
28772877
///
28782878
/// Comments are returned wrapped with their relevant delimiters.
2879+
#[allow(clippy::unnecessary_collect)]
28792880
pub fn span_extract_comments(sm: &SourceMap, span: Span) -> Vec<String> {
28802881
let snippet = sm.span_to_snippet(span).unwrap_or_default();
28812882
tokenize_with_text(&snippet)
28822883
.filter(|(t, ..)| matches!(t, TokenKind::BlockComment { .. } | TokenKind::LineComment { .. }))
28832884
.map(|(_, s, _)| s.to_string())
2884-
.collect::<Vec<_>>()
2885+
.collect()
28852886
}
28862887

28872888
pub fn span_find_starting_semi(sm: &SourceMap, span: Span) -> Span {

clippy_utils/src/str_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub fn camel_case_indices(s: &str) -> Vec<StrIndex> {
153153
/// # use clippy_utils::str_utils::{camel_case_split, StrIndex};
154154
/// assert_eq!(camel_case_split("AbcDef"), vec!["Abc", "Def"]);
155155
/// ```
156+
#[allow(clippy::unnecessary_collect)]
156157
pub fn camel_case_split(s: &str) -> Vec<&str> {
157158
let mut offsets = camel_case_indices(s)
158159
.iter()

tests/compile-test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static INTERNAL_TEST_DEPENDENCIES: &[&str] = &["clippy_config", "clippy_lints",
4444
/// dependencies must be added to Cargo.toml at the project root. Test
4545
/// dependencies that are not *directly* used by this test module require an
4646
/// `extern crate` declaration.
47+
#[allow(clippy::unnecessary_collect)]
4748
fn internal_extern_flags() -> Vec<String> {
4849
let current_exe_path = env::current_exe().unwrap();
4950
let deps_path = current_exe_path.parent().unwrap();

0 commit comments

Comments
 (0)