Skip to content

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

@sugab

Description

@sugab

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();

Activity

eduardotenholder

eduardotenholder commented on Jan 27, 2025

@eduardotenholder

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 ...

securesvet

securesvet commented on Jun 1, 2025

@securesvet

I feel like this exercise is intended to show the common mistakes when writing in Rust
Mostly the common mistake is using resize and expecting the mutated vec as a return result
Shouldn't this be left as it is?
I guess, that the fixed error you've got in pull request should be discovered by the learner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sugab@securesvet@eduardotenholder

      Issue actions

        Clippy3: error message from clippy not inline with the intent · Issue #2201 · rust-lang/rustlings