You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inference failure sometimes results in things being considered functions. #89995
use std::collections::HashSet;use std::rc::Rc;fnintern(cache:&mutHashSet<Rc<str>>,data:&str) -> Rc<str>{match cache.get(data){Some(s) => s.clone(),None => {let d = Rc::from(data);
cache.insert(d.clone());
d
}}}
The current output is:
error[E0282]: type annotations needed
--> src/lib.rs:9:28
|
9 | cache.insert(d.clone());
| ^^^^^ cannot infer type
|
= note: type must be known at this point
error[E0599]: no method named `clone` found for struct `Rc<_>` in the current scope
--> src/lib.rs:9:28
|
9 | cache.insert(d.clone());
| ^^^^^ method not found in `Rc<_>`
|
= note: `d` is a function, perhaps you wish to call it
I'm surprised it can't infer the type of d correctly, considering there are multiple indications it must be Rc<str> (and R-A does so). Maybe it's confused by Rc<&str> being a thing?
The final note is straight up perplexing, however: where on earth is it getting the idea that that's a function from? That should probably be squashed.
I'm surprised it can't infer the type of d correctly, considering there are multiple indications it must be Rc<str> (and R-A does so). Maybe it's confused by Rc<&str> being a thing?
In the smaller reproducer, the return type does solve the inference when you take out the .clone(), but that method call interrupts the link. It works if you write Rc::clone(&...) though.
The final note is straight up perplexing, however: where on earth is it getting the idea that that's a function from? That should probably be squashed.
For a coarse bisect, that note first appeared on stable in Rust 1.33.0. Just looking at the release notes, I'll make a wild guess that it's related to #56805, and I can indeed reproduce the note with Arc and Pin as well.
error[E0282]: type annotations needed for `Rc<T, A>`
--> f71.rs:8:17
|
8 | let d = Rc::from(data);
| ^
9 | cache.insert(d.clone());
| ----- type must be known at this point
|
help: consider giving `d` an explicit type, where the type for type parameter `T` is specified
|
8 | let d: Rc<T, A> = Rc::from(data);
| ++++++++++
Activity
cuviper commentedon Oct 18, 2021
In the smaller reproducer, the return type does solve the inference when you take out the
.clone(), but that method call interrupts the link. It works if you writeRc::clone(&...)though.For a coarse bisect, that note first appeared on stable in Rust 1.33.0. Just looking at the release notes, I'll make a wild guess that it's related to #56805, and I can indeed reproduce the note with
ArcandPinas well.estebank commentedon Aug 14, 2023
Current output: