Skip to content

Commit d126ff2

Browse files
authored
Merge pull request #43 from Dzejkop/master
Add clippy lints talk
2 parents a4c46eb + 7b4083a commit d126ff2

File tree

83 files changed

+1200
-0
lines changed

Some content is hidden

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

83 files changed

+1200
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

talk-archive/2022-07-can-you-trigger-all-clippy-lints-and-live-to-tell-the-tale/Cargo.lock

Lines changed: 248 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "clippy-lints"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
anyhow = "1.0.58"
10+
rand = "0.8.5"
11+
regex = "1.6.0"
12+
serde = { version = "1.0.139", features = ["derive"] }
13+
serde_json = "1.0.82"
14+
test-case = "2.1.0"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
There are 348 lints in total.
2+
3+
Meaning that in 40-ish minutes time I have I would have to allot for each lint roughly 6 seconds.
4+
That's hardly a presentation and more of a fire-and-forget slide reading session.
5+
6+
So instead I'm going to focus on a subset of available lints - specifically on so called "correctness" lints, of which there are 72.
7+
Which gives me a comfortable 30 seconds per lint.
8+
9+
If time permits I also prepared a few slides regarding the "suspicious" group of lints.
10+
11+
But before we get to that - a small foreword about clippy itself and how the lints are organized.
12+
13+
# What is Clippy & stuff
14+
15+
Clippy is the standard linter for the Rust programming language.
16+
For those who don't know a linter is a tool to catch a certain kind of errors, issues and code smells in one's code.
17+
18+
Rust's compiler can already catch and notify you about quite a range of issues, such as an unused variable, an unused function/method, etc.
19+
20+
But there are many more issues that it simply cannot or should not catch.
21+
22+
That's instead the job of the linter (or the formatter, but that's another matter).
23+
24+
The linter will analyze your code and try to find certain predefined patterns.
25+
26+
In Clippy the lints are organized in groups, which are listed as follows:
27+
1. Correctness - the lints which catch code that is quote "outright wrong or useless"
28+
2. Suspicious - "code that is most likely wrong or useless"
29+
3. Style - "code that should be written in a more idiomatic way"
30+
4. Complexity - "code that does something simple but in a complex way"
31+
5. Perf - "code that can be written to run faster"
32+
6. Pedantic - "lints which are rather strict or have occasional false positives"
33+
34+
and finally there are
35+
7. Nursery - lints which are under development
36+
8. Cargo - lints for the cargo manifest
37+
38+
Each group has an assigned "level" - allow, warn or deny. Which will result in respectively - passing, giving a lint-time warning or a lint-time error.
39+
40+
Only the "Correctness" lints are "deny" by default.
41+
42+
All other groups apart from "Pedantic", "Nursery" or "Cargo" are "warn" by default.
43+
44+
The last set of groups are set to "Allow".
45+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
max_width = 80
2+
imports_granularity = "Module"
3+
group_imports = "StdExternalCrate"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod fn_address_comparisons;
2+
pub mod if_let_mutex;
3+
pub mod infinite_iter;
4+
pub mod invalid_null_ptr_usage;
5+
pub mod serde_api_misuse;
6+
pub mod vtable_address_comparisons;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pub type F = fn(i32) -> i32;
2+
3+
pub fn my_fn(x: i32) -> i32 {
4+
x * 2
5+
}
6+
7+
pub fn other_fn(x: i32) -> i32 {
8+
x * 2
9+
}
10+
11+
pub fn run_callback(f: F, x: i32) -> i32 {
12+
if f == my_fn {
13+
f(x) + 1
14+
} else {
15+
f(x)
16+
}
17+
}
18+
19+
#[test]
20+
fn what_is_the_result() {
21+
let a: F = my_fn;
22+
let b: F = other_fn;
23+
24+
assert_eq!(a, b);
25+
}

0 commit comments

Comments
 (0)