Skip to content

Commit 698dbf8

Browse files
committed
Auto merge of #16451 - Urhengulas:satisfy-clippy, r=Veykril
internal: Work through temporarily allowed clippy lints, part 2 Another follow-up to #16401.
2 parents 355c944 + d1d9cde commit 698dbf8

File tree

38 files changed

+133
-148
lines changed

38 files changed

+133
-148
lines changed

Cargo.toml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,14 @@ new_ret_no_self = "allow"
167167

168168
## Following lints should be tackled at some point
169169
borrowed_box = "allow"
170-
borrow_deref_ref = "allow"
171-
derivable_impls = "allow"
172170
derived_hash_with_manual_eq = "allow"
173-
field_reassign_with_default = "allow"
174171
forget_non_drop = "allow"
175-
format_collect = "allow"
176-
large_enum_variant = "allow"
177172
needless_doctest_main = "allow"
178-
new_without_default = "allow"
179173
non_canonical_clone_impl = "allow"
180174
non_canonical_partial_ord_impl = "allow"
181175
self_named_constructors = "allow"
182-
skip_while_next = "allow"
183176
too_many_arguments = "allow"
184-
toplevel_ref_arg = "allow"
185177
type_complexity = "allow"
186-
unnecessary_cast = "allow"
187-
unnecessary_filter_map = "allow"
188-
unnecessary_lazy_evaluations = "allow"
189-
unnecessary_mut_passed = "allow"
190-
useless_conversion = "allow"
191-
useless_format = "allow"
192-
wildcard_in_or_patterns = "allow"
193178
wrong_self_convention = "allow"
194179

195180
## warn at following lints

crates/flycheck/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,9 @@ impl CargoActor {
493493
// Skip certain kinds of messages to only spend time on what's useful
494494
JsonMessage::Cargo(message) => match message {
495495
cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => {
496-
self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap();
496+
self.sender
497+
.send(CargoMessage::CompilerArtifact(Box::new(artifact)))
498+
.unwrap();
497499
}
498500
cargo_metadata::Message::CompilerMessage(msg) => {
499501
self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap();
@@ -538,7 +540,7 @@ impl CargoActor {
538540
}
539541

540542
enum CargoMessage {
541-
CompilerArtifact(cargo_metadata::Artifact),
543+
CompilerArtifact(Box<cargo_metadata::Artifact>),
542544
Diagnostic(Diagnostic),
543545
}
544546

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
3333
}
3434
)
3535
}),
36-
DefWithBodyId::InTypeConstId(_) => format!("In type const = "),
36+
DefWithBodyId::InTypeConstId(_) => "In type const = ".to_string(),
3737
DefWithBodyId::VariantId(it) => {
3838
let loc = it.lookup(db);
3939
let enum_loc = loc.parent.lookup(db);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl SsrError {
256256
"##,
257257
);
258258

259-
assert_eq!(db.body_with_source_map(def.into()).1.diagnostics(), &[]);
259+
assert_eq!(db.body_with_source_map(def).1.diagnostics(), &[]);
260260
expect![[r#"
261261
fn main() {
262262
_ = $crate::error::SsrError::new(
@@ -309,7 +309,7 @@ fn f() {
309309
"#,
310310
);
311311

312-
let (_, source_map) = db.body_with_source_map(def.into());
312+
let (_, source_map) = db.body_with_source_map(def);
313313
assert_eq!(source_map.diagnostics(), &[]);
314314

315315
for (_, def_map) in body.blocks(&db) {

crates/hir-def/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl<'a> AssocItemCollector<'a> {
782782
self.diagnostics.push(DefDiagnostic::macro_expansion_parse_error(
783783
self.module_id.local_id,
784784
error_call_kind(),
785-
errors.into(),
785+
errors,
786786
));
787787
}
788788

crates/hir-def/src/hir/format_args.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ enum PositionUsedAs {
166166
}
167167
use PositionUsedAs::*;
168168

169+
#[allow(clippy::unnecessary_lazy_evaluations)]
169170
pub(crate) fn parse(
170171
s: &ast::String,
171172
fmt_snippet: Option<String>,
@@ -177,9 +178,9 @@ pub(crate) fn parse(
177178
let text = s.text_without_quotes();
178179
let str_style = match s.quote_offsets() {
179180
Some(offsets) => {
180-
let raw = u32::from(offsets.quotes.0.len()) - 1;
181+
let raw = usize::from(offsets.quotes.0.len()) - 1;
181182
// subtract 1 for the `r` prefix
182-
(raw != 0).then(|| raw as usize - 1)
183+
(raw != 0).then(|| raw - 1)
183184
}
184185
None => None,
185186
};
@@ -432,7 +433,7 @@ pub(crate) fn parse(
432433
}
433434
}
434435

435-
#[derive(Debug, Clone, PartialEq, Eq)]
436+
#[derive(Clone, Debug, Default, Eq, PartialEq)]
436437
pub struct FormatArgumentsCollector {
437438
arguments: Vec<FormatArgument>,
438439
num_unnamed_args: usize,
@@ -451,7 +452,7 @@ impl FormatArgumentsCollector {
451452
}
452453

453454
pub fn new() -> Self {
454-
Self { arguments: vec![], names: vec![], num_unnamed_args: 0, num_explicit_args: 0 }
455+
Default::default()
455456
}
456457

457458
pub fn add(&mut self, arg: FormatArgument) -> usize {

crates/hir-def/src/import_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl SearchMode {
297297
SearchMode::Exact => candidate.eq_ignore_ascii_case(query),
298298
SearchMode::Prefix => {
299299
query.len() <= candidate.len() && {
300-
let prefix = &candidate[..query.len() as usize];
300+
let prefix = &candidate[..query.len()];
301301
if case_sensitive {
302302
prefix == query
303303
} else {
@@ -396,7 +396,7 @@ impl Query {
396396
pub fn search_dependencies(
397397
db: &dyn DefDatabase,
398398
krate: CrateId,
399-
ref query: Query,
399+
query: &Query,
400400
) -> FxHashSet<ItemInNs> {
401401
let _p = tracing::span!(tracing::Level::INFO, "search_dependencies", ?query).entered();
402402

@@ -446,7 +446,7 @@ fn search_maps(
446446
let end = (value & 0xFFFF_FFFF) as usize;
447447
let start = (value >> 32) as usize;
448448
let ImportMap { item_to_info_map, importables, .. } = &*import_maps[import_map_idx];
449-
let importables = &importables[start as usize..end];
449+
let importables = &importables[start..end];
450450

451451
let iter = importables
452452
.iter()
@@ -516,7 +516,7 @@ mod tests {
516516
})
517517
.expect("could not find crate");
518518

519-
let actual = search_dependencies(db.upcast(), krate, query)
519+
let actual = search_dependencies(db.upcast(), krate, &query)
520520
.into_iter()
521521
.filter_map(|dependency| {
522522
let dependency_krate = dependency.krate(db.upcast())?;

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use hir_expand::{
2525
InFile, MacroFileId, MacroFileIdExt,
2626
};
2727
use span::Span;
28-
use stdx::format_to;
28+
use stdx::{format_to, format_to_acc};
2929
use syntax::{
3030
ast::{self, edit::IndentLevel},
3131
AstNode,
@@ -149,8 +149,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
149149
if tree {
150150
let tree = format!("{:#?}", parse.syntax_node())
151151
.split_inclusive('\n')
152-
.map(|line| format!("// {line}"))
153-
.collect::<String>();
152+
.fold(String::new(), |mut acc, line| format_to_acc!(acc, "// {line}"));
154153
format_to!(expn_text, "\n{}", tree)
155154
}
156155
let range = call.syntax().text_range();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ impl ModCollector<'_, '_> {
19241924
item_tree: self.item_tree,
19251925
mod_dir,
19261926
}
1927-
.collect_in_top_module(&*items);
1927+
.collect_in_top_module(items);
19281928
if is_macro_use {
19291929
self.import_all_legacy_macros(module_id);
19301930
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl DefMap {
475475
let macro_use_prelude = || {
476476
self.macro_use_prelude.get(name).map_or(PerNs::none(), |&(it, _extern_crate)| {
477477
PerNs::macros(
478-
it.into(),
478+
it,
479479
Visibility::Public,
480480
// FIXME?
481481
None, // extern_crate.map(ImportOrExternCrate::ExternCrate),

crates/hir-def/src/per_ns.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@ pub enum Namespace {
1616
Macros,
1717
}
1818

19-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
19+
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
2020
pub struct PerNs {
2121
pub types: Option<(ModuleDefId, Visibility, Option<ImportOrExternCrate>)>,
2222
pub values: Option<(ModuleDefId, Visibility, Option<ImportId>)>,
2323
pub macros: Option<(MacroId, Visibility, Option<ImportId>)>,
2424
}
2525

26-
impl Default for PerNs {
27-
fn default() -> Self {
28-
PerNs { types: None, values: None, macros: None }
29-
}
30-
}
31-
3226
impl PerNs {
3327
pub fn none() -> PerNs {
3428
PerNs { types: None, values: None, macros: None }
@@ -131,13 +125,11 @@ impl PerNs {
131125
.into_iter()
132126
.chain(
133127
self.values
134-
.map(|it| (ItemInNs::Values(it.0), it.2.map(ImportOrExternCrate::Import)))
135-
.into_iter(),
128+
.map(|it| (ItemInNs::Values(it.0), it.2.map(ImportOrExternCrate::Import))),
136129
)
137130
.chain(
138131
self.macros
139-
.map(|it| (ItemInNs::Macros(it.0), it.2.map(ImportOrExternCrate::Import)))
140-
.into_iter(),
132+
.map(|it| (ItemInNs::Macros(it.0), it.2.map(ImportOrExternCrate::Import))),
141133
)
142134
}
143135
}

crates/hir-def/src/test_db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ impl Default for TestDB {
4141

4242
impl Upcast<dyn ExpandDatabase> for TestDB {
4343
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
44-
&*self
44+
self
4545
}
4646
}
4747

4848
impl Upcast<dyn DefDatabase> for TestDB {
4949
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
50-
&*self
50+
self
5151
}
5252
}
5353

crates/hir-expand/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl Attr {
230230
)
231231
)
232232
})
233-
.unwrap_or_else(|| tt.len());
233+
.unwrap_or(tt.len());
234234

235235
let (path, input) = tt.split_at(path_end);
236236
let path = Interned::new(ModPath::from_tt(db, path)?);

crates/hir-ty/src/inhabitedness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ impl TypeVisitor<Interner> for UninhabitedFrom<'_> {
8484
Some(0) | None => CONTINUE_OPAQUELY_INHABITED,
8585
Some(1..) => item_ty.super_visit_with(self, outer_binder),
8686
},
87-
88-
TyKind::Ref(..) | _ => CONTINUE_OPAQUELY_INHABITED,
87+
_ => CONTINUE_OPAQUELY_INHABITED,
8988
};
9089
self.recursive_ty.remove(ty);
9190
self.max_depth += 1;

crates/hir-ty/src/mir/lower/pattern_matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl MirLowerCtx<'_> {
114114
index: i as u32,
115115
}))
116116
}),
117-
&mut cond_place,
117+
&cond_place,
118118
mode,
119119
)?
120120
}

crates/hir-ty/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub(crate) fn detect_variant_from_bytes<'a>(
440440
(db.enum_data(e).variants[index.0].0, layout)
441441
}
442442
hir_def::layout::Variants::Multiple { tag, tag_encoding, variants, .. } => {
443-
let size = tag.size(&*target_data_layout).bytes_usize();
443+
let size = tag.size(target_data_layout).bytes_usize();
444444
let offset = layout.fields.offset(0).bytes_usize(); // The only field on enum variants is the tag field
445445
let tag = i128::from_le_bytes(pad16(&b[offset..offset + size], false));
446446
match tag_encoding {

crates/hir/src/attrs.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,9 @@ fn resolve_impl_trait_item(
239239
) -> Option<DocLinkDef> {
240240
let canonical = ty.canonical();
241241
let krate = ty.krate(db);
242-
let environment = resolver.generic_def().map_or_else(
243-
|| crate::TraitEnvironment::empty(krate.id).into(),
244-
|d| db.trait_environment(d),
245-
);
242+
let environment = resolver
243+
.generic_def()
244+
.map_or_else(|| crate::TraitEnvironment::empty(krate.id), |d| db.trait_environment(d));
246245
let traits_in_scope = resolver.traits_in_scope(db.upcast());
247246

248247
let mut result = None;
@@ -297,7 +296,7 @@ fn as_module_def_if_namespace_matches(
297296
AssocItem::TypeAlias(it) => (ModuleDef::TypeAlias(it), Namespace::Types),
298297
};
299298

300-
(ns.unwrap_or(expected_ns) == expected_ns).then(|| DocLinkDef::ModuleDef(def))
299+
(ns.unwrap_or(expected_ns) == expected_ns).then_some(DocLinkDef::ModuleDef(def))
301300
}
302301

303302
fn modpath_from_str(link: &str) -> Option<ModPath> {

crates/hir/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl Crate {
236236
query: import_map::Query,
237237
) -> impl Iterator<Item = Either<ModuleDef, Macro>> {
238238
let _p = tracing::span!(tracing::Level::INFO, "query_external_importables");
239-
import_map::search_dependencies(db, self.into(), query).into_iter().map(|item| {
239+
import_map::search_dependencies(db, self.into(), &query).into_iter().map(|item| {
240240
match ItemInNs::from(item) {
241241
ItemInNs::Types(mod_id) | ItemInNs::Values(mod_id) => Either::Left(mod_id),
242242
ItemInNs::Macros(mac_id) => Either::Right(mac_id),
@@ -903,7 +903,7 @@ fn emit_def_diagnostic_(
903903
}
904904
DefDiagnosticKind::InvalidDeriveTarget { ast, id } => {
905905
let node = ast.to_node(db.upcast());
906-
let derive = node.attrs().nth(*id as usize);
906+
let derive = node.attrs().nth(*id);
907907
match derive {
908908
Some(derive) => {
909909
acc.push(
@@ -918,7 +918,7 @@ fn emit_def_diagnostic_(
918918
}
919919
DefDiagnosticKind::MalformedDerive { ast, id } => {
920920
let node = ast.to_node(db.upcast());
921-
let derive = node.attrs().nth(*id as usize);
921+
let derive = node.attrs().nth(*id);
922922
match derive {
923923
Some(derive) => {
924924
acc.push(

crates/ide-assists/src/tests/sourcegen.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::{fmt, fs, path::Path};
44

5+
use stdx::format_to_acc;
56
use test_utils::project_root;
67

78
#[test]
@@ -172,8 +173,7 @@ impl fmt::Display for Assist {
172173
fn hide_hash_comments(text: &str) -> String {
173174
text.split('\n') // want final newline
174175
.filter(|&it| !(it.starts_with("# ") || it == "#"))
175-
.map(|it| format!("{it}\n"))
176-
.collect()
176+
.fold(String::new(), |mut acc, it| format_to_acc!(acc, "{it}\n"))
177177
}
178178

179179
fn reveal_hash_comments(text: &str) -> String {
@@ -187,6 +187,5 @@ fn reveal_hash_comments(text: &str) -> String {
187187
it
188188
}
189189
})
190-
.map(|it| format!("{it}\n"))
191-
.collect()
190+
.fold(String::new(), |mut acc, it| format_to_acc!(acc, "{it}\n"))
192191
}

crates/ide-completion/src/context/analysis.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,8 +1267,7 @@ fn pattern_context_for(
12671267
pat
12681268
.syntax()
12691269
.ancestors()
1270-
.skip_while(|it| ast::Pat::can_cast(it.kind()))
1271-
.next()
1270+
.find(|it| ast::Pat::can_cast(it.kind()))
12721271
.map_or((PatternRefutability::Irrefutable, false), |node| {
12731272
let refutability = match_ast! {
12741273
match node {

0 commit comments

Comments
 (0)