-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Hey everyone,
I noticed that when collecting an std::str::Chars
into a std::rc::Rc
using Rc::from(...)
, the compiler tells you to annotate the type on your variable, when you actually need to annotate the type of your std::Iter::collect()
call.
This code produces the bug:
fn main() {
let s = "Hello, Github!!!!".to_string();
let r:Rc<str> = Rc::from(s.chars().collect());
}
The compiler tells me to annotate the type of r
, which already has a type annotation.
error[E0283]: type annotations needed for `std::rc::Rc<str>`
--> src/main.rs:5:21
|
5 | let r:Rc<str> = Rc::from(s.chars().collect());
| - ^^^^^^^^ cannot infer type for struct `std::rc::Rc<str>`
| |
| consider giving `r` a type
|
= note: cannot resolve `std::rc::Rc<str>: std::convert::From<_>`
= note: required by `std::convert::From::from`
In actuality the fix is to annotate the collect()
-call:
fn main() {
let s = "Hello, Github!!!!".to_string();
let r:Rc<str> = Rc::from(s.chars().collect::<String>());
}
Meta
I used the following version:
rustc --version --verbose
:
rustc 1.44.0-nightly (1edd389cc 2020-03-23)
binary: rustc
commit-hash: 1edd389cc4c7b5be7a3dd4fe4b986f6017018e54
commit-date: 2020-03-23
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0
The current beta (1.43.0-beta.5) and stable (1.42.0) on the rust playground produce the same output.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.