-
Notifications
You must be signed in to change notification settings - Fork 13.3k
"Unable to infer enough type information" when spawning thread and looping. #20454
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
Replacing |
This is largely because the In the case of To use Thread::spawn(|| -> T {
loop { /* ... */ }
}); Here the |
Actually, for diverging type variables (which is what a |
Here's the same issue: use std::thread::Thread;
use std::sync::mpsc::{channel};
fn main() {
let (chs,chr) = channel();
Thread::spawn(move || {
chs.send(1u8); //must specifically annotate
});
} As seen here It took me a bit to realize the issue was actually regarding the channel type, as I thought it was referring to the thread's move fn itself with the error:
|
I'm stuck with the same-looking bug, but the loop is apparently not the cause: for i in range(0, 4) {
let my_numbers = shared_numbers.clone();
let my_frame_counter = shared_frame_counter.clone();
Thread::spawn(move || -> () {
loop {
my_numbers[i] = (my_frame_counter.frame() / i as i32) % 240;
t::delay(16);
}
return ();
});
} When I comment-out the
Unfortunately I don't yet know enough to figure out what's wrong with that line. However, the error message is extremely confusing. |
My mistake was trying to use mutable state across threads. Using AtomicUsize solved the problem. To be clear: the only issue is that the message "unable to infer enough type information" is confusing because it has nothing to do with the real problem. The loop statement without break caused no problems for me. |
I have the same issue event with the program in "A 30-minute Introduction to Rust": use std::thread::Thread;
use std::sync::{Arc,Mutex};
fn main() {
let numbers = Arc::new(Mutex::new(vec![1, 2, 3]));
for i in range(0, 3) {
let number = numbers.clone();
Thread::spawn(|&:| {
let i = 5;
let mut array = number.lock().unwrap();
(*array)[i] += 1;
println!("numbers[{}] is {}", i, (*array)[i]);
});
}
} it has the same error:
|
$ rustc --version
rustc 0.13.0-nightly (39d7402 2015-01-01 15:51:08 +0000)
The text was updated successfully, but these errors were encountered: