Skip to content

Unused variables inside for are not detected #17999

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

Closed
huonw opened this issue Oct 13, 2014 · 2 comments
Closed

Unused variables inside for are not detected #17999

huonw opened this issue Oct 13, 2014 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@huonw
Copy link
Member

huonw commented Oct 13, 2014

fn main() {
    for _ in range(1i, 101) {
        let x = ();
        match () {
            a => {}
        }
    }
}

compiles without a peep, even though x and a are unused. Commenting out the for gives the expected output:

<anon>:3:13: 3:14 warning: unused variable: `x`, #[warn(unused_variable)] on by default
<anon>:3         let x = ();
                     ^
<anon>:5:13: 5:14 warning: unused variable: `a`, #[warn(unused_variable)] on by default
<anon>:5             a => {}
                     ^
@huonw huonw added I-wrong A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints labels Oct 13, 2014
hirschenberger added a commit to hirschenberger/rust that referenced this issue Oct 13, 2014
bors added a commit that referenced this issue Oct 14, 2014
Fix issue #17999 (Unused variables inside `for` are not detected)
@hirschenberger
Copy link
Contributor

I think this an be closed

@alexcrichton
Copy link
Member

Thanks @hirschenberger (fixed in #18014)

lnicola pushed a commit to lnicola/rust that referenced this issue Sep 25, 2024
fix: `std::error::Error` is object unsafe

Fixes rust-lang#17998

I tried to get generic predicates of assoc function itself, not inherited from the parent here;

https://github.com/rust-lang/rust-analyzer/blob/0ae42bd42576566540a84c62e118aa823edcf2ec/crates/hir-ty/src/object_safety.rs#L420-L442

But this naive equality check approach doesn't work when the assoc function has one or more generic paramters like;

```rust
trait Foo {}
trait Bar: Foo {
    fn bar(&self);
}
```

because the generic predicates of the parent, `Bar` is `[^1.0 implements Foo]` and the generic predicates of `fn bar` is `[^1.1 implements Foo]`, which are different.

This PR implements a correct logic for filtering out parent generic predicates for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

3 participants