Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,14 @@ new_ret_no_self = "allow"

## Following lints should be tackled at some point
borrowed_box = "allow"
borrow_deref_ref = "allow"
derivable_impls = "allow"
derived_hash_with_manual_eq = "allow"
field_reassign_with_default = "allow"
forget_non_drop = "allow"
format_collect = "allow"
large_enum_variant = "allow"
needless_doctest_main = "allow"
new_without_default = "allow"
non_canonical_clone_impl = "allow"
non_canonical_partial_ord_impl = "allow"
self_named_constructors = "allow"
skip_while_next = "allow"
too_many_arguments = "allow"
toplevel_ref_arg = "allow"
type_complexity = "allow"
unnecessary_cast = "allow"
unnecessary_filter_map = "allow"
unnecessary_lazy_evaluations = "allow"
unnecessary_mut_passed = "allow"
useless_conversion = "allow"
useless_format = "allow"
wildcard_in_or_patterns = "allow"
wrong_self_convention = "allow"

## warn at following lints
Expand Down
6 changes: 4 additions & 2 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ impl CargoActor {
// Skip certain kinds of messages to only spend time on what's useful
JsonMessage::Cargo(message) => match message {
cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => {
self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap();
self.sender
.send(CargoMessage::CompilerArtifact(Box::new(artifact)))
.unwrap();
}
cargo_metadata::Message::CompilerMessage(msg) => {
self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap();
Expand Down Expand Up @@ -538,7 +540,7 @@ impl CargoActor {
}

enum CargoMessage {
CompilerArtifact(cargo_metadata::Artifact),
CompilerArtifact(Box<cargo_metadata::Artifact>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came up a couple of times before and I think bjorn3 pointed put that most of the time we're going to have this variant, so making this change will cause a lot of allocations.

I don't know if the cost of moving the large struct around is lower or higher than that of the allocations, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with any choice. I was just going with the clippy recommendation here.

I'd propose that we go with it and if someone takes the time to compare the two options we potentially revert it and disable the clippy lint for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should revert this and allow the lint, there is little reason for this change. But I'll do that in a follow up PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diagnostic(Diagnostic),
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
}
)
}),
DefWithBodyId::InTypeConstId(_) => format!("In type const = "),
DefWithBodyId::InTypeConstId(_) => "In type const = ".to_string(),
DefWithBodyId::VariantId(it) => {
let loc = it.lookup(db);
let enum_loc = loc.parent.lookup(db);
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/body/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl SsrError {
"##,
);

assert_eq!(db.body_with_source_map(def.into()).1.diagnostics(), &[]);
assert_eq!(db.body_with_source_map(def).1.diagnostics(), &[]);
expect![[r#"
fn main() {
_ = $crate::error::SsrError::new(
Expand Down Expand Up @@ -309,7 +309,7 @@ fn f() {
"#,
);

let (_, source_map) = db.body_with_source_map(def.into());
let (_, source_map) = db.body_with_source_map(def);
assert_eq!(source_map.diagnostics(), &[]);

for (_, def_map) in body.blocks(&db) {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ impl<'a> AssocItemCollector<'a> {
self.diagnostics.push(DefDiagnostic::macro_expansion_parse_error(
self.module_id.local_id,
error_call_kind(),
errors.into(),
errors,
));
}

Expand Down
9 changes: 5 additions & 4 deletions crates/hir-def/src/hir/format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ enum PositionUsedAs {
}
use PositionUsedAs::*;

#[allow(clippy::unnecessary_lazy_evaluations)]
pub(crate) fn parse(
s: &ast::String,
fmt_snippet: Option<String>,
Expand All @@ -177,9 +178,9 @@ pub(crate) fn parse(
let text = s.text_without_quotes();
let str_style = match s.quote_offsets() {
Some(offsets) => {
let raw = u32::from(offsets.quotes.0.len()) - 1;
let raw = usize::from(offsets.quotes.0.len()) - 1;
// subtract 1 for the `r` prefix
(raw != 0).then(|| raw as usize - 1)
(raw != 0).then(|| raw - 1)
}
None => None,
};
Expand Down Expand Up @@ -432,7 +433,7 @@ pub(crate) fn parse(
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct FormatArgumentsCollector {
arguments: Vec<FormatArgument>,
num_unnamed_args: usize,
Expand All @@ -451,7 +452,7 @@ impl FormatArgumentsCollector {
}

pub fn new() -> Self {
Self { arguments: vec![], names: vec![], num_unnamed_args: 0, num_explicit_args: 0 }
Default::default()
}

pub fn add(&mut self, arg: FormatArgument) -> usize {
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl SearchMode {
SearchMode::Exact => candidate.eq_ignore_ascii_case(query),
SearchMode::Prefix => {
query.len() <= candidate.len() && {
let prefix = &candidate[..query.len() as usize];
let prefix = &candidate[..query.len()];
if case_sensitive {
prefix == query
} else {
Expand Down Expand Up @@ -396,7 +396,7 @@ impl Query {
pub fn search_dependencies(
db: &dyn DefDatabase,
krate: CrateId,
ref query: Query,
query: &Query,
) -> FxHashSet<ItemInNs> {
let _p = tracing::span!(tracing::Level::INFO, "search_dependencies", ?query).entered();

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

let iter = importables
.iter()
Expand Down Expand Up @@ -516,7 +516,7 @@ mod tests {
})
.expect("could not find crate");

let actual = search_dependencies(db.upcast(), krate, query)
let actual = search_dependencies(db.upcast(), krate, &query)
.into_iter()
.filter_map(|dependency| {
let dependency_krate = dependency.krate(db.upcast())?;
Expand Down
5 changes: 2 additions & 3 deletions crates/hir-def/src/macro_expansion_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use hir_expand::{
InFile, MacroFileId, MacroFileIdExt,
};
use span::Span;
use stdx::format_to;
use stdx::{format_to, format_to_acc};
use syntax::{
ast::{self, edit::IndentLevel},
AstNode,
Expand Down Expand Up @@ -149,8 +149,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
if tree {
let tree = format!("{:#?}", parse.syntax_node())
.split_inclusive('\n')
.map(|line| format!("// {line}"))
.collect::<String>();
.fold(String::new(), |mut acc, line| format_to_acc!(acc, "// {line}"));
format_to!(expn_text, "\n{}", tree)
}
let range = call.syntax().text_range();
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ impl ModCollector<'_, '_> {
item_tree: self.item_tree,
mod_dir,
}
.collect_in_top_module(&*items);
.collect_in_top_module(items);
if is_macro_use {
self.import_all_legacy_macros(module_id);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres/path_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl DefMap {
let macro_use_prelude = || {
self.macro_use_prelude.get(name).map_or(PerNs::none(), |&(it, _extern_crate)| {
PerNs::macros(
it.into(),
it,
Visibility::Public,
// FIXME?
None, // extern_crate.map(ImportOrExternCrate::ExternCrate),
Expand Down
14 changes: 3 additions & 11 deletions crates/hir-def/src/per_ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ pub enum Namespace {
Macros,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct PerNs {
pub types: Option<(ModuleDefId, Visibility, Option<ImportOrExternCrate>)>,
pub values: Option<(ModuleDefId, Visibility, Option<ImportId>)>,
pub macros: Option<(MacroId, Visibility, Option<ImportId>)>,
}

impl Default for PerNs {
fn default() -> Self {
PerNs { types: None, values: None, macros: None }
}
}

impl PerNs {
pub fn none() -> PerNs {
PerNs { types: None, values: None, macros: None }
Expand Down Expand Up @@ -131,13 +125,11 @@ impl PerNs {
.into_iter()
.chain(
self.values
.map(|it| (ItemInNs::Values(it.0), it.2.map(ImportOrExternCrate::Import)))
.into_iter(),
.map(|it| (ItemInNs::Values(it.0), it.2.map(ImportOrExternCrate::Import))),
)
.chain(
self.macros
.map(|it| (ItemInNs::Macros(it.0), it.2.map(ImportOrExternCrate::Import)))
.into_iter(),
.map(|it| (ItemInNs::Macros(it.0), it.2.map(ImportOrExternCrate::Import))),
)
}
}
4 changes: 2 additions & 2 deletions crates/hir-def/src/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ impl Default for TestDB {

impl Upcast<dyn ExpandDatabase> for TestDB {
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
&*self
self
}
}

impl Upcast<dyn DefDatabase> for TestDB {
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
&*self
self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Attr {
)
)
})
.unwrap_or_else(|| tt.len());
.unwrap_or(tt.len());

let (path, input) = tt.split_at(path_end);
let path = Interned::new(ModPath::from_tt(db, path)?);
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-ty/src/inhabitedness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ impl TypeVisitor<Interner> for UninhabitedFrom<'_> {
Some(0) | None => CONTINUE_OPAQUELY_INHABITED,
Some(1..) => item_ty.super_visit_with(self, outer_binder),
},

TyKind::Ref(..) | _ => CONTINUE_OPAQUELY_INHABITED,
_ => CONTINUE_OPAQUELY_INHABITED,
};
self.recursive_ty.remove(ty);
self.max_depth += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/mir/lower/pattern_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl MirLowerCtx<'_> {
index: i as u32,
}))
}),
&mut cond_place,
&cond_place,
mode,
)?
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ pub(crate) fn detect_variant_from_bytes<'a>(
(db.enum_data(e).variants[index.0].0, layout)
}
hir_def::layout::Variants::Multiple { tag, tag_encoding, variants, .. } => {
let size = tag.size(&*target_data_layout).bytes_usize();
let size = tag.size(target_data_layout).bytes_usize();
let offset = layout.fields.offset(0).bytes_usize(); // The only field on enum variants is the tag field
let tag = i128::from_le_bytes(pad16(&b[offset..offset + size], false));
match tag_encoding {
Expand Down
9 changes: 4 additions & 5 deletions crates/hir/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ fn resolve_impl_trait_item(
) -> Option<DocLinkDef> {
let canonical = ty.canonical();
let krate = ty.krate(db);
let environment = resolver.generic_def().map_or_else(
|| crate::TraitEnvironment::empty(krate.id).into(),
|d| db.trait_environment(d),
);
let environment = resolver
.generic_def()
.map_or_else(|| crate::TraitEnvironment::empty(krate.id), |d| db.trait_environment(d));
let traits_in_scope = resolver.traits_in_scope(db.upcast());

let mut result = None;
Expand Down Expand Up @@ -297,7 +296,7 @@ fn as_module_def_if_namespace_matches(
AssocItem::TypeAlias(it) => (ModuleDef::TypeAlias(it), Namespace::Types),
};

(ns.unwrap_or(expected_ns) == expected_ns).then(|| DocLinkDef::ModuleDef(def))
(ns.unwrap_or(expected_ns) == expected_ns).then_some(DocLinkDef::ModuleDef(def))
}

fn modpath_from_str(link: &str) -> Option<ModPath> {
Expand Down
6 changes: 3 additions & 3 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Crate {
query: import_map::Query,
) -> impl Iterator<Item = Either<ModuleDef, Macro>> {
let _p = tracing::span!(tracing::Level::INFO, "query_external_importables");
import_map::search_dependencies(db, self.into(), query).into_iter().map(|item| {
import_map::search_dependencies(db, self.into(), &query).into_iter().map(|item| {
match ItemInNs::from(item) {
ItemInNs::Types(mod_id) | ItemInNs::Values(mod_id) => Either::Left(mod_id),
ItemInNs::Macros(mac_id) => Either::Right(mac_id),
Expand Down Expand Up @@ -903,7 +903,7 @@ fn emit_def_diagnostic_(
}
DefDiagnosticKind::InvalidDeriveTarget { ast, id } => {
let node = ast.to_node(db.upcast());
let derive = node.attrs().nth(*id as usize);
let derive = node.attrs().nth(*id);
match derive {
Some(derive) => {
acc.push(
Expand All @@ -918,7 +918,7 @@ fn emit_def_diagnostic_(
}
DefDiagnosticKind::MalformedDerive { ast, id } => {
let node = ast.to_node(db.upcast());
let derive = node.attrs().nth(*id as usize);
let derive = node.attrs().nth(*id);
match derive {
Some(derive) => {
acc.push(
Expand Down
7 changes: 3 additions & 4 deletions crates/ide-assists/src/tests/sourcegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{fmt, fs, path::Path};

use stdx::format_to_acc;
use test_utils::project_root;

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

fn reveal_hash_comments(text: &str) -> String {
Expand All @@ -187,6 +187,5 @@ fn reveal_hash_comments(text: &str) -> String {
it
}
})
.map(|it| format!("{it}\n"))
.collect()
.fold(String::new(), |mut acc, it| format_to_acc!(acc, "{it}\n"))
}
3 changes: 1 addition & 2 deletions crates/ide-completion/src/context/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,7 @@ fn pattern_context_for(
pat
.syntax()
.ancestors()
.skip_while(|it| ast::Pat::can_cast(it.kind()))
.next()
.find(|it| !ast::Pat::can_cast(it.kind()))
.map_or((PatternRefutability::Irrefutable, false), |node| {
let refutability = match_ast! {
match node {
Expand Down
Loading