-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc fails to infer types, provides confusing error message #37528
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
Comments
impl<T> Extend<T> for Vec<T>
impl<'a, T> Extend<&'a T> for Vec<T> where T: Copy + 'a etc, so you can type it in two ways, resulting in inference error: let _a: (Vec<&i32>, Vec<&i32>) = one.iter().partition(|_v| true); let _a: (Vec<i32>, Vec<i32>) = one.iter().partition(|_v| true);
You can use |
Thank you very much for the explanation. How did you find those two implementations? |
You can find them in https://doc.rust-lang.org/std/iter/trait.Extend.html . |
I meant, how did you figure out that those two implementations were the cause of the problem? I'd like to be able to sort out problems like this without asking for help in the future. |
fn partition<B, F>(self, f: F) -> (B, B) where B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool Looking at |
Took me a while to figure out what Rust meant by It's not always easy to navigate around and found the This is my case https://play.rust-lang.org/?gist=9a32f20e9c272e256f93ca772b1f527e&version=stable |
@StefanoChiodino That would be issue #45164. |
Rust is unable to infer the element type in the results of a call to
Iterator::partition
if the item type is a reference, but not if it's an integer. The error message says nothing about lifetimes, or any other characteristic specific to references.In nightly Rust, compiling the following code:
produces the following error:
It's not clear to me at all why making the iterator clone the items, or using an iterator that doesn't produce references in the first place, should make the type inference work; it seems like
partition
should be as happy to build a vector of references as a vector of integers.This is using:
rustc 1.14.0-nightly (3f4408347 2016-10-27)
The text was updated successfully, but these errors were encountered: