This commit is contained in:
TimLai666 2024-06-18 21:30:58 +08:00 committed by GitHub
parent 2e9f8188fe
commit 6855bc578b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 24 deletions

View File

@ -1,10 +1,10 @@
# Clippy
The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code.
Clippy 工具是一組用來分析你程式碼的 lint讓你能夠抓住常見的錯誤並改善你的 Rust 程式碼。
If you used the installation script for Rustlings, Clippy should be already installed.
If not you can install it manually via `rustup component add clippy`.
如果你使用 Rustlings 的安裝腳本,那麼 Clippy 應該已經安裝好了。
如果沒有,你可以通過以下指令手動安裝它:`rustup component add clippy`
## Further information
## 進一步了解
- [GitHub Repository](https://github.com/rust-lang/rust-clippy).
- [Clippy 的 GitHub 儲存庫](https://github.com/rust-lang/rust-clippy).

View File

@ -1,13 +1,10 @@
// clippy1.rs
//
// The Clippy tool is a collection of lints to analyze your code so you can
// catch common mistakes and improve your Rust code.
// Clippy 工具是一組 lint用來分析您的程式碼讓您能夠捕捉常見的錯誤並改進您的 Rust 程式碼。
//
// For these exercises the code will fail to compile when there are Clippy
// warnings. Check Clippy's suggestions from the output to solve the exercise.
// 對於這些練習,當存在 Clippy 警告時,程式碼將無法編譯。請檢查輸出中的 Clippy 建議來解決這些練習。
//
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint clippy1` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
@ -20,7 +17,7 @@ fn main() {
let area = pi * f32::powi(radius, 2);
println!(
"The area of a circle with radius {:.2} is {:.5}!",
"半徑 {:.2} 的圓的面積是 {:.5}!",
radius, area
)
}

View File

@ -1,9 +1,6 @@
// clippy2.rs
//
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
// 執行 `rustlings hint clippy2` 或使用 `hint` 子命令來獲取提示。
fn main() {
let mut res = 42;

View File

@ -1,9 +1,7 @@
// clippy3.rs
//
// Here's a couple more easy Clippy fixes, so you can see its utility.
// No hints.
// I AM NOT DONE
// 這裡有一些簡單的 Clippy 修正,你可以看到它的實用性。
// 沒有提示。
#[allow(unused_variables, unused_assignments)]
fn main() {
@ -16,15 +14,15 @@ fn main() {
-1, -2, -3
-4, -5, -6
];
println!("My array! Here it is: {:?}", my_arr);
println!("我的陣列! 看這裡: {:?}", my_arr);
let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
println!("This Vec is empty, see? {:?}", my_empty_vec);
println!("這個 Vec 是空的,看到嗎? {:?}", my_empty_vec);
let mut value_a = 45;
let mut value_b = 66;
// Let's swap these two!
// 讓我們交換這兩個值!
value_a = value_b;
value_b = value_a;
println!("value a: {}; value b: {}", value_a, value_b);
println!("值 a: {}; 值 b: {}", value_a, value_b);
}