-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Trait bounds were not satisfied #69169
Comments
This demands a different lifetime than what you provided: |
Yep, but that doesn't solve the issue. Updated. |
This code is extremely hard to make sense and I think the confusion comes entirely from the fact that the lifetimes used in gluon and in this code have matching names – which is why the compiler notes appear to be wrong – while they actually aren't. For instance even if you rewrite the code as such: use futures_util::compat::Future01CompatExt;
use gluon::{
vm::api::{FunctionRef, Getable, Pushable, VmType},
};
pub type Error = gluon::Error;
pub struct Script<'banana, 'peach, In, Out>
where
In: VmType + Pushable<'banana>,
Out: VmType + Getable<'banana, 'peach> + Send + Sync,
{
vm: gluon::RootedThread,
}
impl<'banana, 'peach, In, Out> Script<'banana, 'peach, In, Out>
where
In: VmType + Pushable<'banana>,
Out: VmType + Getable<'banana, 'peach> + Send + Sync,
{
pub async fn run(&mut self, input: &In) -> Result<Out, Error> {
let func: FunctionRef<fn(In) -> Out> = self.vm.get_global("main")?;
return func.call_async(input).compat().await;
}
} you will get exactly the same error as before:
making it easier to see that this is at best a diagnostics bug. |
(FWIW the code is extremely difficult to make sense of, I suspect that it was arrived to from the other end – that is, by looking at a compiler diagnostics and then adding lifetime bounds everywhere possible) The following is something that at least compiles and makes some sense to at least me. pub struct Script {
vm: gluon::RootedThread,
}
impl Script
{
pub async fn run<In, Out>(&mut self, input: In) -> Result<Out, Box<dyn std::error::Error>>
where
In: VmType + for<'banana> Pushable<'banana>,
Out: VmType + for<'peach, 'mango> Getable<'peach, 'mango> + Send + Sync + 'static,
{
let mut func = self.vm.get_global::<FunctionRef<fn(In) -> Out>>("main")?;
return Ok(func.call_async(input).compat().await?);
}
} |
I'm curious whom to blame in this patricular case:
BTW, your fix doesn't reflect my original intentions. I would like to make the script parametrised. |
Some fault definitely lies in the compiler for being confusing about the lifetime names it puts in the diagnostic hints. Hence the A-diagnostics label. Whether HRTBs would make sense in any particular scenario is not for the compiler to decide – it affects the public API after all and is something that you’d need to arrive to yourself. |
I'm not sure if this is a compiler bug, but since I didn't get any answers on StackOverflow I'd try to add an issue here.
I tried this code:
As you can see I explicitly bound
In
andOut
with the needed traits, but still get "trait bounds were not satisfied" error.rustc --version --verbose
:The text was updated successfully, but these errors were encountered: