Skip to content

let_underscore_drop should not suggest drop() ing types that do not impl drop() bounds #10412

Open

Description

@matthiaskrgr

Summary

.

Lint Name

let-underscore-drop

Reproducer

I tried this code:

fn bar<T> (it: Box<[T]>)
 where
     [T] : std::ops::Index<usize>,
 {
     let _ = it[0];
 }

 fn main(){}

I saw this happen:
cargo clippy --fix --allow-dirty -- -Aclippy::all -Wclippy::let-underscore-drop
clippy suggests

fn bar<T> (it: Box<[T]>)
 where
     [T] : std::ops::Index<usize>,
 {
     drop(it[0]); // drop here
 }

 fn main(){}

But this does not compile

error[E0277]: the size for values of type `<[T] as Index<usize>>::Output` cannot be known at compilation time
   --> src/main.rs:5:11
    |
5   |      drop(it[0]);
    |      ---- ^^^^^ doesn't have a size known at compile-time
    |      |
    |      required by a bound introduced by this call
    |
    = help: the trait `Sized` is not implemented for `<[T] as Index<usize>>::Output`
note: required by a bound in `std::mem::drop`
   --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/mem/mod.rs:979:13
    |
979 | pub fn drop<T>(_x: T) {}
    |             ^ required by this bound in `drop`

For more information about this error, try `rustc --explain E0277`.

Version

rustc 1.69.0-nightly (49b9cc513 2023-02-27)
binary: rustc
commit-hash: 49b9cc5139dd4d11ef78dc08c1f9170de5b1ca39
commit-date: 2023-02-27
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    on Feb 27, 2023
  2. changed the title [-]let_underscore_drop should not suggesr `drop()` ing types that do impl drop() bounds[/-] [+]let_underscore_drop should not suggest `drop()` ing types that do not impl drop() bounds[/+] on Feb 27, 2023
  3. J-ZhengLi commented on Apr 7, 2023

    @J-ZhengLi
    Contributor

    that repro code doesn't seem trigger the lint you mentioned anymore, maybe it's already fixed.

    However, it does trigger boxed_local and it's really confusing 😂, because if I remove the Box there will be compiler errors.

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

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions