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

Uplift the let_underscore lints from clippy into rustc. #97739

Merged
merged 25 commits into from
Sep 2, 2022

Commits on May 29, 2022

  1. Add let_underscore_drop lint.

    This lint checks for statements similar to `let _ = foo`, where `foo` is
    a type that implements `Drop`. These types of let statements cause the
    expression in them to be dropped immediately, instead of at the end of
    the scope. Such behavior can be surprizing, especially if you are
    relying on the value to be dropped at the end of the scope. Instead, the
    binding should be an underscore prefixed name (like `_unused`) or the
    value should explicitly be passed to `std::mem::drop()` if the value
    really should be dropped immediately.
    a2aaron committed May 29, 2022
    Configuration menu
    Copy the full SHA
    821b32b View commit details
    Browse the repository at this point in the history

Commits on Jun 4, 2022

  1. Add let_underscore_lock lint.

    Similar to `let_underscore_drop`, this lint checks for statements similar
    to `let _ = foo`, where `foo` is a lock guard. These types of let
    statements are especially problematic because the lock gets released
    immediately, instead of at the end of the scope. This behavior is almost
    always the wrong thing.
    a2aaron committed Jun 4, 2022
    Configuration menu
    Copy the full SHA
    ad7587f View commit details
    Browse the repository at this point in the history
  2. Add let_underscore_must_use lint.

    Similar to `let_underscore_drop`, this lint checks for statements similar
    to `let _ = foo`, where `foo` is an expression marked `must_use`.
    a2aaron committed Jun 4, 2022
    Configuration menu
    Copy the full SHA
    758a9fd View commit details
    Browse the repository at this point in the history
  3. Move let_underscore tests to their own subfolder.

    This was done to pass `tidy`.
    a2aaron committed Jun 4, 2022
    Configuration menu
    Copy the full SHA
    36b6309 View commit details
    Browse the repository at this point in the history
  4. Allow let_underscore_drop and let_underscore_must_use by default.

    These lints are very noisy and are allow-by-default in clippy anyways.
    Hence, setting them to allow-by-default here makes more sense than
    warning constantly on these cases.
    a2aaron committed Jun 4, 2022
    Configuration menu
    Copy the full SHA
    ae2ac3b View commit details
    Browse the repository at this point in the history
  5. Show code suggestions in let_undescore lint messages.

    This commit uses `span_suggestion_verbose` to add what specific code
    changes can be done as suggested by the lint--in this case, either binding
    the expression to an unused variable or using `std::mem::drop` to drop
    the value explicitly.
    a2aaron committed Jun 4, 2022
    Configuration menu
    Copy the full SHA
    eba6c78 View commit details
    Browse the repository at this point in the history
  6. Set let_underscore_lock to Deny by default.

    Clippy sets this lint to Deny by default, and it having the lint be Deny
    is useful for when we test the lint against a Crater run.
    a2aaron committed Jun 4, 2022
    Configuration menu
    Copy the full SHA
    6b179e3 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    a7e2b3e View commit details
    Browse the repository at this point in the history

Commits on Jun 5, 2022

  1. Configuration menu
    Copy the full SHA
    7e485bf View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1421cff View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    30e8adb View commit details
    Browse the repository at this point in the history
  4. Bail out early if the type does not has a trivial Drop implementation.

    If the type has a trivial Drop implementation, then it is probably irrelevant
    that the type was dropped immediately, since nothing important
    happens on drop. Hence, we can bail out early instead of doing some
    expensive checks.
    a2aaron committed Jun 5, 2022
    Configuration menu
    Copy the full SHA
    e6b6678 View commit details
    Browse the repository at this point in the history
  5. Use diagnostic items instead of hard coded paths for `let_underscore_…

    …lock`
    
    Using diagnostic items avoids having to update the paths if the guard
    types ever get moved around for some reason. Additionally, it also greatly
    simplifies the `is_sync_lock` check.
    a2aaron committed Jun 5, 2022
    Configuration menu
    Copy the full SHA
    6342b58 View commit details
    Browse the repository at this point in the history
  6. Use check-pass instead of run-pass

    We don't actually care about running these programs, only checking the
    warnings they generate.
    a2aaron committed Jun 5, 2022
    Configuration menu
    Copy the full SHA
    11663b1 View commit details
    Browse the repository at this point in the history
  7. Remove let_underscore_must_use

    The `let_underscore_must_use` lint was really only added because clippy
    included it, but it doesn't actually seem very useful.
    a2aaron committed Jun 5, 2022
    Configuration menu
    Copy the full SHA
    b5b5b54 View commit details
    Browse the repository at this point in the history
  8. Add diagnostic items to MutexGuard and RwLock Guards

    I forgot to add the diagnostic to the actual types in `std` earlier.
    a2aaron committed Jun 5, 2022
    Configuration menu
    Copy the full SHA
    321a598 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    211feb1 View commit details
    Browse the repository at this point in the history

Commits on Jun 9, 2022

  1. Use multipart_suggestion to create an applicable suggestion.

    The "consider explicitly droping" can now suggest a machine applicable
    suggestion now.
    a2aaron committed Jun 9, 2022
    Configuration menu
    Copy the full SHA
    cdf6606 View commit details
    Browse the repository at this point in the history

Commits on Jun 11, 2022

  1. Reword suggestion messages.

    a2aaron committed Jun 11, 2022
    Configuration menu
    Copy the full SHA
    7237e86 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b040666 View commit details
    Browse the repository at this point in the history
  3. Make let_underscore_drop Deny by default.

    This is done so that we can check the noisiness of this lint in a Crater
    run. Note that when I built the compiler, I actually encountered lots of
    places where this lint will trigger and fail compilation, so I had to
    also set `RUSTFLAGS_NOT_BOOSTRAP` to `-A let_underscore_drop` when
    compiling to prevent that.
    a2aaron committed Jun 11, 2022
    Configuration menu
    Copy the full SHA
    8807c2d View commit details
    Browse the repository at this point in the history

Commits on Jun 17, 2022

  1. Re-allow let_underscore_drop by default.

    This lint is way way too noisy to have it be `Deny` by default.
    a2aaron committed Jun 17, 2022
    Configuration menu
    Copy the full SHA
    a9095ff View commit details
    Browse the repository at this point in the history

Commits on Aug 4, 2022

  1. Explain why let-underscoring a lock guard is incorrect.

    Currently, the let_underscore_lock lint simply tells what is wrong, but
    not why it is wrong. We fix this by using a `MultiSpan` to explain
    specifically that doing `let _ = ` immediately drops the lock guard
    because it does not assign the lock guard to a binding.
    a2aaron committed Aug 4, 2022
    Configuration menu
    Copy the full SHA
    a9f1b7b View commit details
    Browse the repository at this point in the history
  2. Fix imports.

    I'm not really sure why this is nessecary to do, but the checks on the
    PR do not seem to work if do not do this.
    a2aaron committed Aug 4, 2022
    Configuration menu
    Copy the full SHA
    d355ec9 View commit details
    Browse the repository at this point in the history

Commits on Aug 5, 2022

  1. Configuration menu
    Copy the full SHA
    76c90c3 View commit details
    Browse the repository at this point in the history