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

Rust Analyzer shows wrong warning SHA1 hasher finalize #15242

Open
SamTV12345 opened this issue Jul 9, 2023 · 5 comments
Open

Rust Analyzer shows wrong warning SHA1 hasher finalize #15242

SamTV12345 opened this issue Jul 9, 2023 · 5 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@SamTV12345
Copy link

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rustc version: (eg. output of rustc -V) 1.70

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME): %

In IntelliJ the Rust plugin in version 0.4.197.5401-231 shows a warning when using the SHA-1 crate.

        let mut hasher = Sha1::new();

        hasher.update(non_hashed_string);

        let hashed_auth_key = format!("{:x}", hasher.finalize());

In this part of the code it complains that hasher.finalize() CtOutput<CoreWrapper<Sha1Core>> doesn't implement LowerHex (required by {:x}). The code compiles and it also works in my open source production environment.

@SamTV12345 SamTV12345 added the C-bug Category: bug label Jul 9, 2023
@SamTV12345 SamTV12345 changed the title Rust Analyzer shows wrong warning Rust Analyzer shows wrong warning SHA1 hasher finalize Jul 9, 2023
@lowr
Copy link
Contributor

lowr commented Jul 10, 2023

In IntelliJ the Rust plugin in version 0.4.197.5401-231

This is rust-analyzer's repository, not intellij-rust's. Can you check if you're reporting rust-analyzer's issue or intellij-rust's issue?

@lnicola
Copy link
Member

lnicola commented Jul 10, 2023

We don't show any errors, but we don't resolve Sha1::new, so there's still a bug related to this.

EDIT: <Sha1 as Digest>::new() works, but then we don't resolve update from the same trait.

use sha1::{Digest, Sha1};

fn main() {
    let mut hasher = <Sha1 as Digest>::new();

    hasher.update("afdfs");

    let hashed_auth_key = format!("{:x}", hasher.finalize());
    dbg!(hashed_auth_key);
}

@lnicola lnicola added the A-ty type system / type inference / traits / method resolution label Jul 10, 2023
@SamTV12345
Copy link
Author

Thanks for taking a look at it 😄

@newpavlov
Copy link

Is it possible to bisect this? I think it's a relatively recent regression.

@lnicola
Copy link
Member

lnicola commented Jan 10, 2024

The bug in my comment above is not a recent regression, but it was less noticeable before.

The "no such associated item" in RustCrypto/hashes#529 is a recently-added diagnostic that makes the bug more visible. We've just marked it as experimental so it will go away next week, but that doesn't fix the underlying problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants