Skip to content
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

Clippy3: error message from clippy not inline with the intent #2201

Open
sugab opened this issue Jan 21, 2025 · 1 comment · May be fixed by #2202
Open

Clippy3: error message from clippy not inline with the intent #2201

sugab opened this issue Jan 21, 2025 · 1 comment · May be fixed by #2202

Comments

@sugab
Copy link

sugab commented Jan 21, 2025

In this part of code clippy error message not inline with the intent.

let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
println!("This Vec is empty, see? {my_empty_vec:?}");

Image

Because the solution stated that this is about using clear instead of resize.

let mut my_empty_vec = vec![1, 2, 3, 4, 5];
// `resize` mutates a vector instead of returning a new one.
// `resize(0, …)` clears a vector, so it is better to use `clear`.
my_empty_vec.clear();

@sugab sugab linked a pull request Jan 21, 2025 that will close this issue
@eduardotenholder
Copy link

eduardotenholder commented Jan 27, 2025

Additionally

if my_option.is_none() {
  println!("{:?}", my_option.unwrap());
}

triggers in clippy:

help: remove the `None` and `unwrap()`

triggers in me:

if my_option.is_none() {
  println!("{:?}", my_option);
}

and it passes the test and I feel I got the point, but the solution tells me otherwise ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants