-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Constructing a simple HashSet<char> requires RandomState type annotation #101319
Comments
When just pub fn is_pangram(sentence: &str) -> bool {
let mut letters = std::collections::HashSet::<_>::from_iter("abcdefghijklmnopqrstuvwxyz".chars());
sentence.to_lowercase().chars().any(|c| {
letters.remove(&c);
letters.is_empty()
})
} That said, it would be nice if default generic types played some role in type inference since most of the time they are the correct answer. As to why |
@SkiFire13, thanks for the explanation and for the workaround; Apparently by doing |
Not exactly, to break code you also need to change the existing |
Removing the bug label since it's not a compiler bug but rather a limitation of type parameter defaults, as @SkiFire13 mentioned. We could probably do something to improve the diagnostics, though. Like if the type parameter that the user needs to annotate is known to have a default, we could make the diagnostic give a better hint about that. @rustbot label -C-bug +D-confusing +A-diagnostics |
Current output:
|
I tried this code:
I expected to see this code to compile, just like this code does:
Instead, this happened:
I can fix it by including a type annotation for the RandomState:
But since
I do not think I should need to do this.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: