0

When using the sha2 crate, importing its Digest trait allows the use of new to create a new hasher,

use sha2::{Digest, Sha256};

fn main() {
    let hasher = Sha256::new();
}

However, there are no type hints or autocompletion for new. Specifically in VS Code, there is no intellisense when hovering over new and the type of hasher is {unknown}. There are also no autocomplete suggestions when using hasher.

I was expecting the type of hasher to be known, and intellisense/autocompletion to work.

Why are they not showing? Are the types not inferrable due to how Digest::new is defined and how Rust works? Is it a tooling issue with rust-analyzer or VS Code?

aryzing
  • 4,982
  • 7
  • 39
  • 42
  • 1
    The type annotations you see in VS Code likely come from rust-analyzer (though you didn't say what language server you are using). It's possible that rust-analyzer is unable to figure out that `Sha256` implements `Digest`, but if that's indeed the case, I'd consider it a bug in rust-analyzer. – Sven Marnach May 16 '23 at 11:25
  • 2
    I think it's this issue: https://github.com/rust-lang/rust-analyzer/issues/14423 Seems to be an issue in chalk, the constraint solver that rust-analyzer uses to determine trait implementations. – Sven Marnach May 16 '23 at 11:50
  • @SvenMarnach, want to the comment into an answer? – aryzing May 17 '23 at 20:00

0 Answers0