-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Unclear "higher-ranked lifetime error" error #115525
Comments
The error now becomes error: implementation of `FnOnce` is not general enough
--> src/main.rs:41:5
|
41 | check_fn(beba);
| ^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
= note: closure with signature `fn(&'0 (i32, i32)) -> String` must implement `FnOnce<(&'1 (i32, i32),)>`, for any two lifetimes `'0` and `'1`...
= note: ...but it actually implements `FnOnce<(&(i32, i32),)>`
error: implementation of `Iterator` is not general enough
--> src/main.rs:41:5
|
41 | check_fn(beba);
| ^^^^^^^^^^^^^^ implementation of `Iterator` is not general enough
|
= note: `Iterator` would have to be implemented for the type `std::slice::Iter<'0, (i32, i32)>`, for any lifetime `'0`...
= note: ...but `Iterator` is actually implemented for the type `std::slice::Iter<'1, (i32, i32)>`, for some specific lifetime `'1` It's still not clear what happened. But I'll mimimize as follows which emits the same errors use std::future::Future;
pub async fn get_by_id<I>(ids: I)
where
I: IntoIterator<Item = String>,
{
for s in ids {
async { s.as_bytes() }.await;
}
}
async fn beba() {
get_by_id([1].iter().map(|_| String::new())).await;
}
trait FnTrait {}
impl<F, Fut> FnTrait for F
where
F: Fn() -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
{
}
fn check_fn<F: FnTrait>(_f: F) {}
fn main() {
check_fn(beba);
} To make the code above compile (in some sense), you can do one of these
For OP in question, by applying the third way, it compiles. |
I have a similar case, where a mysterious error, triggered while the compiler is trying to prove something is This one doesn't have any dependencies. Same behavior in Stable and Nightly.
This one can be solved by refactoring the body of |
...Mine at least is probably a duplicate of #102211. |
Code
main.rs:
Cargo.toml:
Current output
Desired output
I am not sure of the exact wording, but it should explain that the failure is due to the
Future
returned from the function not implementingSend
andSync
Rationale and extra context
Without explanation of why does the passed function not implement the required trait, it is not immediately clear what the issue is.
Other cases
The error output is the same on stable and nightly
Anything else?
Originally minimized from this code using reqwest and teloxide
The text was updated successfully, but these errors were encountered: