Skip to content

Add unstable cargo lint tables and make use of clippy #15017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
45 changes: 45 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,48 @@ serde_json = "1.0.94"
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }

rustc_lexer = { version = "0.1.0", package = "ra-ap-rustc_lexer" }

[workspace.lints.rust]
rust_2018_idioms = "warn"
unused_lifetimes = "warn"
semicolon_in_expressions_from_macros = "warn"

[workspace.lints.clippy]
# complexity lints
complexity = { level = "warn", priority = -1 }
# Should be tackled at some point where relevant
too_many_arguments = "allow"
# Should be tackled at some point
type_complexity = "allow"

# correctness lints
correctness = { level = "deny", priority = -1 }

# perf lints
perf = { level = "deny", priority = -1 }

# style lints
style = { level = "warn", priority = -1 }
# () makes a fine error in most cases
result_unit_err = "allow"
# We don't expose public APIs that matter like this
len_without_is_empty = "allow"
# we currently prefer explicit control flow return over `...?;` statements whose result is unused
question_mark = "allow"
# We have macros that rely on this currently
enum_variant_names = "allow"
# Builder pattern disagrees
new_ret_no_self = "allow"

# suspicious lints
suspicious = { level = "warn", priority = -1 }

# suspicious lints
restriction = { level = "allow", priority = -1 }
# Remove the tidy test once the lint table is stable
dbg_macro = "warn"
todo = "warn"
unimplemented = "warn"
rc_buffer = "warn"
# FIXME enable this, we use this pattern a lot so its annoying work ...
# str_to_string = "warn"
3 changes: 3 additions & 0 deletions crates/base-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ syntax.workspace = true
test-utils.workspace = true
tt.workspace = true
vfs.workspace = true

[lints]
workspace = true
14 changes: 7 additions & 7 deletions crates/base-db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl ChangeFixture {
let toolchain = toolchain
.map(|it| {
ReleaseChannel::from_str(&it)
.unwrap_or_else(|| panic!("unknown release channel found: {it}"))
.unwrap_or_else(|()| panic!("unknown release channel found: {it}"))
})
.unwrap_or(ReleaseChannel::Stable);
let mut change = Change::new();
Expand All @@ -131,7 +131,7 @@ impl ChangeFixture {

let mut file_set = FileSet::default();
let mut current_source_root_kind = SourceRootKind::Local;
let source_root_prefix = "/".to_string();
let source_root_prefix = "/".to_owned();
let mut file_id = FileId(0);
let mut roots = Vec::new();

Expand Down Expand Up @@ -245,7 +245,7 @@ impl ChangeFixture {
file_id.0 += 1;

let mut fs = FileSet::default();
fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_string()));
fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_owned()));
roots.push(SourceRoot::new_library(fs));

change.change_file(core_file, Some(Arc::from(mini_core.source_code())));
Expand All @@ -255,7 +255,7 @@ impl ChangeFixture {
let core_crate = crate_graph.add_crate_root(
core_file,
Edition::Edition2021,
Some(CrateDisplayName::from_canonical_name("core".to_string())),
Some(CrateDisplayName::from_canonical_name("core".to_owned())),
None,
Default::default(),
Default::default(),
Expand Down Expand Up @@ -283,7 +283,7 @@ impl ChangeFixture {
let mut fs = FileSet::default();
fs.insert(
proc_lib_file,
VfsPath::new_virtual_path("/sysroot/proc_macros/lib.rs".to_string()),
VfsPath::new_virtual_path("/sysroot/proc_macros/lib.rs".to_owned()),
);
roots.push(SourceRoot::new_library(fs));

Expand All @@ -294,7 +294,7 @@ impl ChangeFixture {
let proc_macros_crate = crate_graph.add_crate_root(
proc_lib_file,
Edition::Edition2021,
Some(CrateDisplayName::from_canonical_name("proc_macros".to_string())),
Some(CrateDisplayName::from_canonical_name("proc_macros".to_owned())),
None,
Default::default(),
Default::default(),
Expand Down Expand Up @@ -453,7 +453,7 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
},
_ => panic!("Bad string for crate origin: {b}"),
};
(a.to_owned(), origin, Some(version.to_string()))
(a.to_owned(), origin, Some(version.to_owned()))
} else {
let crate_origin = match LangCrateOrigin::from(&*crate_str) {
LangCrateOrigin::Other => CrateOrigin::Local { repo: None, name: None },
Expand Down
10 changes: 7 additions & 3 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,17 @@ impl ReleaseChannel {
ReleaseChannel::Nightly => "nightly",
}
}
}

impl FromStr for ReleaseChannel {
type Err = ();

pub fn from_str(str: &str) -> Option<Self> {
Some(match str {
fn from_str(str: &str) -> Result<Self, Self::Err> {
Ok(match str {
"" => ReleaseChannel::Stable,
"nightly" => ReleaseChannel::Nightly,
_ if str.starts_with("beta") => ReleaseChannel::Beta,
_ => return None,
_ => return Err(()),
})
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/cfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ derive_arbitrary = "1.2.2"
# local deps
mbe.workspace = true
syntax.workspace = true

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/flycheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ command-group = "2.0.1"
paths.workspace = true
stdx.workspace = true
toolchain.workspace = true

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ impl CargoActor {
}
}

#[allow(clippy::large_enum_variant)]
enum CargoMessage {
CompilerArtifact(cargo_metadata::Artifact),
Diagnostic(Diagnostic),
Expand Down
3 changes: 3 additions & 0 deletions crates/hir-def/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ expect-test = "1.4.0"

# local deps
test-utils.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn parse_comma_sep<S>(subtree: &tt::Subtree<S>) -> Vec<SmolStr> {
}

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

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ impl Body {
}
}
Pat::Or(args) | Pat::Tuple { args, .. } | Pat::TupleStruct { args, .. } => {
args.iter().copied().for_each(|p| f(p));
args.iter().copied().for_each(&mut f);
}
Pat::Ref { pat, .. } => f(*pat),
Pat::Slice { prefix, slice, suffix } => {
let total_iter = prefix.iter().chain(slice.iter()).chain(suffix.iter());
total_iter.copied().for_each(|p| f(p));
total_iter.copied().for_each(&mut f);
}
Pat::Record { args, .. } => {
args.iter().for_each(|RecordFieldPat { pat, .. }| f(*pat));
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ impl ExprCollector<'_> {
expr: iterator,
arms: Box::new([MatchArm { pat: iter_pat, guard: None, expr: loop_outer }]),
},
syntax_ptr.clone(),
syntax_ptr,
)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
let item_tree_id = it.lookup(db).id;
let name = match &item_tree_id.item_tree(db)[item_tree_id.value].name {
Some(name) => name.display(db.upcast()).to_string(),
None => "_".to_string(),
None => "_".to_owned(),
};
format!("const {name} = ")
}
Expand All @@ -45,7 +45,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
let variant = &src.value[it.local_id];
match &variant.name() {
Some(name) => name.to_string(),
None => "_".to_string(),
None => "_".to_owned(),
}
}
};
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 @@ -739,7 +739,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
2 changes: 1 addition & 1 deletion crates/hir-def/src/data/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ fn lower_struct(
trace: &mut Trace<FieldData, Either<ast::TupleField, ast::RecordField>>,
ast: &InFile<ast::StructKind>,
) -> StructKind {
let ctx = LowerCtx::new(db, &expander.hygiene(), ast.file_id);
let ctx = LowerCtx::new(db, expander.hygiene(), ast.file_id);

match &ast.value {
ast::StructKind::Tuple(fl) => {
Expand Down
8 changes: 3 additions & 5 deletions crates/hir-def/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
fn attrs(&self, def: AttrDefId) -> Attrs;

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

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

let segments = tt.split(|tt| match tt {
tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => true,
_ => false,
});
let segments =
tt.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ','));
for output in segments.skip(1) {
match output {
[tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "no_std" => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/dyn_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! let mut map = DynMap::new();
//!
//! // To access a specific map, index the `DynMap` by `Key`:
//! map[STRING_TO_U32].insert("hello".to_string(), 92);
//! map[STRING_TO_U32].insert("hello".to_owned(), 92);
//! let value = map[U32_TO_VEC].get(92);
//! assert!(value.is_none());
//! ```
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn find_path_for_module(
}

if let value @ Some(_) =
find_in_prelude(db, &root_def_map, &def_map, ItemInNs::Types(module_id.into()), from)
find_in_prelude(db, &root_def_map, def_map, ItemInNs::Types(module_id.into()), from)
{
return value;
}
Expand Down
1 change: 1 addition & 0 deletions crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ impl GenericParams {
}
}

#[allow(clippy::borrowed_box)]
fn add_where_predicate_from_bound(
&mut self,
lower_ctx: &LowerCtx<'_>,
Expand Down
Loading