Skip to content

Commit 7e74066

Browse files
committed
Fix clippy lints
1 parent d26853a commit 7e74066

File tree

156 files changed

+728
-839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+728
-839
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ type_complexity = "allow"
112112
question_mark = "allow"
113113
# We have macros that rely on this currently
114114
enum_variant_names = "allow"
115+
# Builder pattern disagrees
116+
new_ret_no_self = "allow"

crates/base-db/src/fixture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl ChangeFixture {
116116
let toolchain = toolchain
117117
.map(|it| {
118118
ReleaseChannel::from_str(&it)
119-
.unwrap_or_else(|| panic!("unknown release channel found: {it}"))
119+
.unwrap_or_else(|()| panic!("unknown release channel found: {it}"))
120120
})
121121
.unwrap_or(ReleaseChannel::Stable);
122122
let mut change = Change::new();

crates/base-db/src/input.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,17 @@ impl ReleaseChannel {
282282
ReleaseChannel::Nightly => "nightly",
283283
}
284284
}
285+
}
286+
287+
impl FromStr for ReleaseChannel {
288+
type Err = ();
285289

286-
pub fn from_str(str: &str) -> Option<Self> {
287-
Some(match str {
290+
fn from_str(str: &str) -> Result<Self, Self::Err> {
291+
Ok(match str {
288292
"" => ReleaseChannel::Stable,
289293
"nightly" => ReleaseChannel::Nightly,
290294
_ if str.starts_with("beta") => ReleaseChannel::Beta,
291-
_ => return None,
295+
_ => return Err(()),
292296
})
293297
}
294298
}

crates/flycheck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ impl CargoActor {
513513
}
514514
}
515515

516+
#[allow(clippy::large_enum_variant)]
516517
enum CargoMessage {
517518
CompilerArtifact(cargo_metadata::Artifact),
518519
Diagnostic(Diagnostic),

crates/hir-def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn parse_comma_sep<S>(subtree: &tt::Subtree<S>) -> Vec<SmolStr> {
379379
}
380380

381381
impl AttrsWithOwner {
382-
pub(crate) fn attrs_with_owner(db: &dyn DefDatabase, owner: AttrDefId) -> Self {
382+
pub(crate) fn attrs_with_owner_query(db: &dyn DefDatabase, owner: AttrDefId) -> Self {
383383
Self { attrs: db.attrs(owner), owner }
384384
}
385385

crates/hir-def/src/body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ impl Body {
242242
}
243243
}
244244
Pat::Or(args) | Pat::Tuple { args, .. } | Pat::TupleStruct { args, .. } => {
245-
args.iter().copied().for_each(|p| f(p));
245+
args.iter().copied().for_each(&mut f);
246246
}
247247
Pat::Ref { pat, .. } => f(*pat),
248248
Pat::Slice { prefix, slice, suffix } => {
249249
let total_iter = prefix.iter().chain(slice.iter()).chain(suffix.iter());
250-
total_iter.copied().for_each(|p| f(p));
250+
total_iter.copied().for_each(&mut f);
251251
}
252252
Pat::Record { args, .. } => {
253253
args.iter().for_each(|RecordFieldPat { pat, .. }| f(*pat));

crates/hir-def/src/body/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ impl ExprCollector<'_> {
811811
expr: iterator,
812812
arms: Box::new([MatchArm { pat: iter_pat, guard: None, expr: loop_outer }]),
813813
},
814-
syntax_ptr.clone(),
814+
syntax_ptr,
815815
)
816816
}
817817

crates/hir-def/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl<'a> AssocItemCollector<'a> {
739739
self.diagnostics.push(DefDiagnostic::macro_expansion_parse_error(
740740
self.module_id.local_id,
741741
error_call_kind(),
742-
errors.into(),
742+
errors,
743743
));
744744
}
745745

crates/hir-def/src/data/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn lower_struct(
473473
trace: &mut Trace<FieldData, Either<ast::TupleField, ast::RecordField>>,
474474
ast: &InFile<ast::StructKind>,
475475
) -> StructKind {
476-
let ctx = LowerCtx::new(db, &expander.hygiene(), ast.file_id);
476+
let ctx = LowerCtx::new(db, expander.hygiene(), ast.file_id);
477477

478478
match &ast.value {
479479
ast::StructKind::Tuple(fl) => {

crates/hir-def/src/db.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
193193
fn attrs(&self, def: AttrDefId) -> Attrs;
194194

195195
#[salsa::transparent]
196-
#[salsa::invoke(AttrsWithOwner::attrs_with_owner)]
196+
#[salsa::invoke(AttrsWithOwner::attrs_with_owner_query)]
197197
fn attrs_with_owner(&self, def: AttrDefId) -> AttrsWithOwner;
198198

199199
// endregion:attrs
@@ -271,10 +271,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
271271
None => continue,
272272
};
273273

274-
let segments = tt.split(|tt| match tt {
275-
tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => true,
276-
_ => false,
277-
});
274+
let segments =
275+
tt.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ','));
278276
for output in segments.skip(1) {
279277
match output {
280278
[tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "no_std" => {

crates/hir-def/src/find_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn find_path_for_module(
206206
}
207207

208208
if let value @ Some(_) =
209-
find_in_prelude(db, &root_def_map, &def_map, ItemInNs::Types(module_id.into()), from)
209+
find_in_prelude(db, &root_def_map, def_map, ItemInNs::Types(module_id.into()), from)
210210
{
211211
return value;
212212
}

crates/hir-def/src/generics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ impl GenericParams {
300300
}
301301
}
302302

303+
#[allow(clippy::borrowed_box)]
303304
fn add_where_predicate_from_bound(
304305
&mut self,
305306
lower_ctx: &LowerCtx<'_>,

crates/hir-def/src/lang_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ macro_rules! language_item_table {
219219
}
220220
}
221221

222+
#[allow(clippy::should_implement_trait)]
222223
/// Opposite of [`LangItem::name`]
223224
pub fn from_str(name: &str) -> Option<Self> {
224225
match name {

crates/hir-def/src/nameres/collector.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,14 +1388,14 @@ impl DefCollector<'_> {
13881388
always!(krate == loc.def.krate);
13891389
DefDiagnostic::unresolved_proc_macro(module_id, loc.kind.clone(), loc.def.krate)
13901390
}
1391-
_ => DefDiagnostic::macro_error(module_id, loc.kind.clone(), err.to_string()),
1391+
_ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()),
13921392
};
13931393

13941394
self.def_map.diagnostics.push(diag);
13951395
}
13961396
if let errors @ [_, ..] = &*value {
13971397
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(macro_call_id);
1398-
let diag = DefDiagnostic::macro_expansion_parse_error(module_id, loc.kind, &errors);
1398+
let diag = DefDiagnostic::macro_expansion_parse_error(module_id, loc.kind, errors);
13991399
self.def_map.diagnostics.push(diag);
14001400
}
14011401

@@ -1847,7 +1847,7 @@ impl ModCollector<'_, '_> {
18471847
item_tree: self.item_tree,
18481848
mod_dir,
18491849
}
1850-
.collect_in_top_module(&*items);
1850+
.collect_in_top_module(items);
18511851
if is_macro_use {
18521852
self.import_all_legacy_macros(module_id);
18531853
}
@@ -2238,9 +2238,9 @@ impl ModCollector<'_, '_> {
22382238
fn import_all_legacy_macros(&mut self, module_id: LocalModuleId) {
22392239
let macros = self.def_collector.def_map[module_id].scope.collect_legacy_macros();
22402240
for (name, macs) in macros {
2241-
macs.last().map(|&mac| {
2242-
self.def_collector.define_legacy_macro(self.module_id, name.clone(), mac)
2243-
});
2241+
if let Some(&mac) = macs.last() {
2242+
self.def_collector.define_legacy_macro(self.module_id, name.clone(), mac);
2243+
}
22442244
}
22452245
}
22462246

crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl DefMap {
454454
let macro_use_prelude = || {
455455
self.macro_use_prelude
456456
.get(name)
457-
.map_or(PerNs::none(), |&it| PerNs::macros(it.into(), Visibility::Public))
457+
.map_or(PerNs::none(), |&it| PerNs::macros(it, Visibility::Public))
458458
};
459459
let prelude = || self.resolve_in_prelude(db, name);
460460

crates/hir-def/src/nameres/tests/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,8 @@ fn proc_attr(a: TokenStream, b: TokenStream) -> TokenStream { a }
12941294

12951295
let actual = def_map
12961296
.macro_use_prelude
1297-
.iter()
1298-
.map(|(name, _)| name.display(&db).to_string())
1297+
.keys()
1298+
.map(|name| name.display(&db).to_string())
12991299
.sorted()
13001300
.join("\n");
13011301

crates/hir-def/src/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Path {
150150

151151
pub fn mod_path(&self) -> Option<&ModPath> {
152152
match self {
153-
Path::Normal { mod_path, .. } => Some(&mod_path),
153+
Path::Normal { mod_path, .. } => Some(mod_path),
154154
Path::LangItem(_) => None,
155155
}
156156
}
@@ -215,13 +215,13 @@ impl<'a> PathSegments<'a> {
215215
}
216216
pub fn skip(&self, len: usize) -> PathSegments<'a> {
217217
PathSegments {
218-
segments: &self.segments.get(len..).unwrap_or(&[]),
218+
segments: self.segments.get(len..).unwrap_or(&[]),
219219
generic_args: self.generic_args.and_then(|it| it.get(len..)),
220220
}
221221
}
222222
pub fn take(&self, len: usize) -> PathSegments<'a> {
223223
PathSegments {
224-
segments: &self.segments.get(..len).unwrap_or(&self.segments),
224+
segments: self.segments.get(..len).unwrap_or(self.segments),
225225
generic_args: self.generic_args.map(|it| it.get(..len).unwrap_or(it)),
226226
}
227227
}

crates/hir-def/src/path/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
4545
)
4646
})
4747
.map(Interned::new);
48-
if let Some(_) = args {
48+
if args.is_some() {
4949
generic_args.resize(segments.len(), None);
5050
generic_args.push(args);
5151
}

crates/hir-def/src/per_ns.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@
55
66
use crate::{item_scope::ItemInNs, visibility::Visibility, MacroId, ModuleDefId};
77

8-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8+
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
99
pub struct PerNs {
1010
pub types: Option<(ModuleDefId, Visibility)>,
1111
pub values: Option<(ModuleDefId, Visibility)>,
1212
pub macros: Option<(MacroId, Visibility)>,
1313
}
1414

15-
impl Default for PerNs {
16-
fn default() -> Self {
17-
PerNs { types: None, values: None, macros: None }
18-
}
19-
}
20-
2115
impl PerNs {
2216
pub fn none() -> PerNs {
2317
PerNs { types: None, values: None, macros: None }

0 commit comments

Comments
 (0)