Skip to content

Commit cae7fc7

Browse files
committed
hmm
1 parent 01c2a9b commit cae7fc7

File tree

9 files changed

+19
-20
lines changed

9 files changed

+19
-20
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, InherentImplLintScope, MacroMatcher, MatchLintBehaviour,
@@ -966,10 +967,10 @@ fn deserialize(file: &SourceFile) -> TryConf {
966967
// info for the user instead.
967968

968969
let names = conf.conf.module_item_order_groupings.grouping_names();
969-
let suggestion = suggest_candidate(grouping, names.iter().map(String::as_str))
970+
let suggestion = suggest_candidate(grouping, names.clone())
970971
.map(|s| format!(" perhaps you meant `{s}`?"))
971972
.unwrap_or_default();
972-
let names = names.iter().map(|s| format!("`{s}`")).join(", ");
973+
let names = names.map(|s| format!("`{s}`")).join(", ");
973974
let message = format!(
974975
"unknown ordering group: `{grouping}` was not specified in `module-items-ordered-within-groupings`,{suggestion} expected one of: {names}"
975976
);

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) -> bool {
3232
false
3333
}
3434
}
35-
35+
#[expect(clippy::unnecessary_collect)]
3636
fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
3737
attrs
3838
.iter()

clippy_lints/src/lifetimes.rs

Lines changed: 6 additions & 10 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
}
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ declare_clippy_lint! {
4444
#[clippy::version = "1.92.0"]
4545
pub UNNECESSARY_COLLECT,
4646
nursery,
47-
"default lint description"
47+
"checks for functions returning vecs produced from vec::from_iter"
4848
}
4949

5050
pub struct UnnecessaryCollect {

clippy_utils/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2777,12 +2777,13 @@ pub fn span_extract_comment(sm: &SourceMap, span: Span) -> String {
27772777
/// Returns all the comments a given span contains.
27782778
///
27792779
/// Comments are returned wrapped with their relevant delimiters.
2780+
#[allow(clippy::unnecessary_collect)]
27802781
pub fn span_extract_comments(sm: &SourceMap, span: Span) -> Vec<String> {
27812782
let snippet = sm.span_to_snippet(span).unwrap_or_default();
27822783
tokenize_with_text(&snippet)
27832784
.filter(|(t, ..)| matches!(t, TokenKind::BlockComment { .. } | TokenKind::LineComment { .. }))
27842785
.map(|(_, s, _)| s.to_string())
2785-
.collect::<Vec<_>>()
2786+
.collect()
27862787
}
27872788

27882789
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)