Skip to content

Commit

Permalink
Fix new clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Apr 1, 2024
1 parent 8e324e9 commit 2ae3e57
Show file tree
Hide file tree
Showing 33 changed files with 31 additions and 42 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -188,6 +188,8 @@ enum_variant_names = "allow"
new_ret_no_self = "allow"
# Has a bunch of false positives
useless_asref = "allow"
# Has false positives
assigning_clones = "allow"

## Following lints should be tackled at some point
too_many_arguments = "allow"
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/pat.rs
Expand Up @@ -149,7 +149,7 @@ impl InferenceContext<'_> {
expected: &Ty,
default_bm: T::BindingMode,
id: T,
subs: impl Iterator<Item = (Name, T)> + ExactSizeIterator,
subs: impl ExactSizeIterator<Item = (Name, T)>,
) -> Ty {
let (ty, def) = self.resolve_variant(path, false);
if let Some(variant) = def {
Expand Down
4 changes: 2 additions & 2 deletions crates/ide/src/hover/render.rs
Expand Up @@ -101,7 +101,7 @@ pub(super) fn try_expr(
if let Some((inner, body)) = error_type_args {
inner_ty = inner;
body_ty = body;
s = "Try Error".to_owned();
"Try Error".clone_into(&mut s);
}
}
}
Expand Down Expand Up @@ -634,7 +634,7 @@ fn closure_ty(
})
.join("\n");
if captures_rendered.trim().is_empty() {
captures_rendered = "This closure captures nothing".to_owned();
"This closure captures nothing".clone_into(&mut captures_rendered);
}
let mut targets: Vec<hir::ModuleDef> = Vec::new();
let mut push_new_def = |item: hir::ModuleDef| {
Expand Down
4 changes: 2 additions & 2 deletions crates/ide/src/syntax_highlighting/tags.rs
Expand Up @@ -113,7 +113,7 @@ pub enum HlPunct {
Semi,
/// ! (only for macro calls)
MacroBang,
///
/// Other punctutations
Other,
}

Expand All @@ -127,7 +127,7 @@ pub enum HlOperator {
Logical,
/// >, <, ==, >=, <=, !=
Comparison,
///
/// Other operators
Other,
}

Expand Down
1 change: 1 addition & 0 deletions crates/intern/src/lib.rs
Expand Up @@ -174,6 +174,7 @@ pub struct InternStorage<T: ?Sized> {
map: OnceLock<InternMap<T>>,
}

#[allow(clippy::new_without_default)] // this a const fn, so it can't be default
impl<T: ?Sized> InternStorage<T> {
pub const fn new() -> Self {
Self { map: OnceLock::new() }
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/build_scripts.rs
Expand Up @@ -235,7 +235,7 @@ impl WorkspaceBuildScripts {
},
progress,
)?;
res.iter_mut().for_each(|it| it.error = errors.clone());
res.iter_mut().for_each(|it| it.error.clone_from(&errors));
collisions.into_iter().for_each(|(id, workspace, package)| {
if let Some(&(p, w)) = by_id.get(id) {
res[workspace].outputs[package] = res[w].outputs[p].clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/progress_report.rs
Expand Up @@ -92,7 +92,7 @@ impl<'a> ProgressReport<'a> {

let _ = io::stdout().write(output.as_bytes());
let _ = io::stdout().flush();
self.text = text.to_owned();
text.clone_into(&mut self.text);
}

fn set_value(&mut self, value: f32) {
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/handlers/notification.rs
Expand Up @@ -105,7 +105,7 @@ pub(crate) fn handle_did_change_text_document(
)
.into_bytes();
if *data != new_contents {
*data = new_contents.clone();
data.clone_from(&new_contents);
state.vfs.write().0.set_file_contents(path, Some(new_contents));
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/main_loop.rs
Expand Up @@ -412,7 +412,7 @@ impl GlobalState {
// See https://github.com/rust-lang/rust-analyzer/issues/13130
let patch_empty = |message: &mut String| {
if message.is_empty() {
*message = " ".to_owned();
" ".clone_into(message);
}
};

Expand Down
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/reload.rs
Expand Up @@ -725,13 +725,13 @@ pub fn ws_to_crate_graph(
if layouts.len() <= idx {
layouts.resize(idx + 1, e.clone());
}
layouts[idx] = layout.clone();
layouts[idx].clone_from(&layout);
}
if idx >= num_toolchains {
if toolchains.len() <= idx {
toolchains.resize(idx + 1, None);
}
toolchains[idx] = toolchain.clone();
toolchains[idx].clone_from(&toolchain);
}
});
proc_macro_paths.push(crate_proc_macros);
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/tests/slow-tests/tidy.rs
Expand Up @@ -243,7 +243,7 @@ struct TidyDocs {
impl TidyDocs {
fn visit(&mut self, path: &Path, text: &str) {
// Tests and diagnostic fixes don't need module level comments.
if is_exclude_dir(path, &["tests", "test_data", "fixes", "grammar"]) {
if is_exclude_dir(path, &["tests", "test_data", "fixes", "grammar", "salsa"]) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion crates/salsa/salsa-macros/src/database_storage.rs
@@ -1,4 +1,5 @@
//!
//! Implementation for `[salsa::database]` decorator.

use heck::ToSnakeCase;
use proc_macro::TokenStream;
use syn::parse::{Parse, ParseStream};
Expand Down
2 changes: 1 addition & 1 deletion crates/salsa/salsa-macros/src/parenthesized.rs
@@ -1,4 +1,4 @@
//!
//! Parenthesis helper
pub(crate) struct Parenthesized<T>(pub(crate) T);

impl<T> syn::parse::Parse for Parenthesized<T>
Expand Down
2 changes: 1 addition & 1 deletion crates/salsa/salsa-macros/src/query_group.rs
@@ -1,4 +1,4 @@
//!
//! Implementation for `[salsa::query_group]` decorator.

use crate::parenthesized::Parenthesized;
use heck::ToUpperCamelCase;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/derived.rs
@@ -1,4 +1,3 @@
//!
use crate::debug::TableEntry;
use crate::durability::Durability;
use crate::hash::FxIndexMap;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/derived/slot.rs
@@ -1,4 +1,3 @@
//!
use crate::debug::TableEntry;
use crate::derived::MemoizationPolicy;
use crate::durability::Durability;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/durability.rs
@@ -1,4 +1,3 @@
//!
/// Describes how likely a value is to change -- how "durable" it is.
/// By default, inputs have `Durability::LOW` and interned values have
/// `Durability::HIGH`. But inputs can be explicitly set with other
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/hash.rs
@@ -1,4 +1,3 @@
//!
pub(crate) type FxHasher = std::hash::BuildHasherDefault<rustc_hash::FxHasher>;
pub(crate) type FxIndexSet<K> = indexmap::IndexSet<K, FxHasher>;
pub(crate) type FxIndexMap<K, V> = indexmap::IndexMap<K, V, FxHasher>;
1 change: 0 additions & 1 deletion crates/salsa/src/input.rs
@@ -1,4 +1,3 @@
//!
use crate::debug::TableEntry;
use crate::durability::Durability;
use crate::hash::FxIndexMap;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/intern_id.rs
@@ -1,4 +1,3 @@
//!
use std::fmt;
use std::num::NonZeroU32;

Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/interned.rs
@@ -1,4 +1,3 @@
//!
use crate::debug::TableEntry;
use crate::durability::Durability;
use crate::intern_id::InternId;
Expand Down
15 changes: 7 additions & 8 deletions crates/salsa/src/lib.rs
@@ -1,8 +1,7 @@
//!
#![allow(clippy::type_complexity)]
#![allow(clippy::question_mark)]
#![allow(missing_docs)]
#![warn(rust_2018_idioms)]
#![warn(missing_docs)]

//! The salsa crate is a crate for incremental recomputation. It
//! permits you to define a "database" of queries with both inputs and
Expand Down Expand Up @@ -124,9 +123,9 @@ pub struct Event {
impl Event {
/// Returns a type that gives a user-readable debug output.
/// Use like `println!("{:?}", index.debug(db))`.
pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
where
D: plumbing::DatabaseOps,
D: ?Sized + plumbing::DatabaseOps,
{
EventDebug { event: self, db }
}
Expand Down Expand Up @@ -206,9 +205,9 @@ pub enum EventKind {
impl EventKind {
/// Returns a type that gives a user-readable debug output.
/// Use like `println!("{:?}", index.debug(db))`.
pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
where
D: plumbing::DatabaseOps,
D: ?Sized + plumbing::DatabaseOps,
{
EventKindDebug { kind: self, db }
}
Expand Down Expand Up @@ -400,9 +399,9 @@ impl DatabaseKeyIndex {

/// Returns a type that gives a user-readable debug output.
/// Use like `println!("{:?}", index.debug(db))`.
pub fn debug<D: ?Sized>(self, db: &D) -> impl std::fmt::Debug + '_
pub fn debug<D>(self, db: &D) -> impl std::fmt::Debug + '_
where
D: plumbing::DatabaseOps,
D: ?Sized + plumbing::DatabaseOps,
{
DatabaseKeyIndexDebug { index: self, db }
}
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/lru.rs
@@ -1,4 +1,3 @@
//!
use oorandom::Rand64;
use parking_lot::Mutex;
use std::fmt::Debug;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/plumbing.rs
@@ -1,4 +1,3 @@
//!
#![allow(missing_docs)]

use crate::debug::TableEntry;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/revision.rs
@@ -1,4 +1,3 @@
//!
use std::num::NonZeroU32;
use std::sync::atomic::{AtomicU32, Ordering};

Expand Down
3 changes: 1 addition & 2 deletions crates/salsa/src/runtime.rs
@@ -1,4 +1,3 @@
//!
use crate::durability::Durability;
use crate::hash::FxIndexSet;
use crate::plumbing::CycleRecoveryStrategy;
Expand Down Expand Up @@ -605,7 +604,7 @@ impl ActiveQuery {
pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) {
self.changed_at = cycle_query.changed_at;
self.durability = cycle_query.durability;
self.dependencies = cycle_query.dependencies.clone();
self.dependencies.clone_from(&cycle_query.dependencies);
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/runtime/dependency_graph.rs
@@ -1,4 +1,3 @@
//!
use triomphe::Arc;

use crate::{DatabaseKeyIndex, RuntimeId};
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/runtime/local_state.rs
@@ -1,4 +1,3 @@
//!
use tracing::debug;
use triomphe::ThinArc;

Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/storage.rs
@@ -1,4 +1,3 @@
//!
use crate::{plumbing::DatabaseStorageTypes, Runtime};
use triomphe::Arc;

Expand Down
2 changes: 1 addition & 1 deletion crates/sourcegen/src/lib.rs
Expand Up @@ -69,7 +69,7 @@ impl CommentBlock {
panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}");
}

block.id = id.trim().to_owned();
id.trim().clone_into(&mut block.id);
true
});
blocks
Expand Down
2 changes: 1 addition & 1 deletion crates/test-utils/src/fixture.rs
Expand Up @@ -186,7 +186,7 @@ impl FixtureWithProjectMeta {

if let Some(meta) = fixture.strip_prefix("//- target_data_layout:") {
let (meta, remain) = meta.split_once('\n').unwrap();
target_data_layout = meta.trim().to_owned();
meta.trim().clone_into(&mut target_data_layout);
fixture = remain;
}

Expand Down
2 changes: 1 addition & 1 deletion xtask/src/codegen.rs
Expand Up @@ -84,7 +84,7 @@ impl CommentBlock {
panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}");
}

block.id = id.trim().to_owned();
id.trim().clone_into(&mut block.id);
true
});
blocks
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/codegen/lints.rs
Expand Up @@ -280,7 +280,7 @@ fn generate_descriptor_clippy(buf: &mut String, path: &Path) {
let line = &line[..up_to];

let clippy_lint = clippy_lints.last_mut().expect("clippy lint must already exist");
clippy_lint.help = unescape(line).trim().to_owned();
unescape(line).trim().clone_into(&mut clippy_lint.help);
}
}
clippy_lints.sort_by(|lint, lint2| lint.id.cmp(&lint2.id));
Expand Down

0 comments on commit 2ae3e57

Please sign in to comment.