Open tustvold opened 2 years ago
I've stumbled accross the following error today, and I suppose it's maybe related?
use snafu::{ensure, Snafu};
#[derive(Debug, Snafu)]
enum Error {
A { int: u64 },
}
fn f(ok: bool) -> Result<(), Error> {
ensure!(ok, ASnafu { int: 0 }); // << Error [E0277] the trait bound `u64: std::convert::From<i32>` is not satisfied.
Ok(())
}
.. or should I open a new issue about this?
The solution/workaround is to use 0u64
instead in my situation. So maybe in your situation @tustvold, using (0..1i32)
instead of just (0..1)
could help?
I'm not sure if this is a bug or not, but I thought I'd document it as I ran into it and it caused me some confusion.
175 added an
Into
conversion to the ensure macro, unfortunately this means that ensure no longer helps deduce the type of a closure.In particular this doesn't compile
It requires you to explicitly indicate the type
This is perhaps a little surprising.
The circumstance I encountered this in was actually a little bit more confusing, where adding a contextless variant caused the error to manifest in code I hadn't touched.
For example, this fails to compile
But does without the contextless variant
I don't really know what the solution here is, ensure is behaving a lot like
?
operator and so I'm not sure the current behavior is wrong per-se, but thought I'd document this