Rust-analyzer works most of the time

Rust Analyzer picks up on most functions, but doesn't catch str::from_utf8(). Would anyone understand why? I can save the code and build just fine.The IDE even gives me some hints as well.

Sample code:
use std::str;

fn try_from(buff: &[u8]) -> Result<Self, Self::Error> {
match str::from_utf8(buff) {
Ok(request) => {},
Err(_) => return Err(ParseError::InvalidEncoding)

from_utf8 is a function in the std::str module, it isn't an associated function on the str primitive type. You must have imported the std::str module, but rust-analyzer is assuming you're referring to the primitive. I would probably just refer to the std::str module by path to avoid confusion.

Here's a playground showing that you can't call from_utf8 on the str primitive. Rust-analyzer could probably merge the suggestions between the module and the primitive when the module is in scope, but that might also be confusing.

I'd say this is a bug that it doesn't complete std::str module's item when it's in scope.

I see. When I type the full path of std::str I begin to see the suggestions.
I'll simply import it as something instead to avoid confusion.

use std::str as stdStr;

Thanks a bunch. I really appreciate this. :smile: