Open jmrgibson opened 1 year ago
Hmm. I'm honestly not very sure what we could do to improve this case. The ensure
macro basically expands to $selector.fail()
and thus you get the error seen.
It's possible that a combination of two things could help:
If those two things existed, the macro could be changed to expand to TheBuildTrait::fail($selector)
and we could put #[diagnostic::on_unimplemented]
on TheBuildTrait
. That might allow us to have an error like "fail
is only available for context selectors that do not have a source".
If you had seen something along those lines added to the error you already got, do you think it would have helped?
error[E0599]: no method named `fail` found for struct `FooSnafu` in the current scope
--> src/main.rs:12:5
|
3 | #[derive(Debug, Snafu)]
| ----- method `fail` not found for this struct
...
12 | ensure!(1 == 1, FooSnafu{id: 10})
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `FooSnafu<{integer}>`
|
= help: the trait `TheBuildTrait` is not implemented for context selectors that do not have a source
When attempting to use a generated context selector in a macro like
ensure!
that doesn't provide a context, the error message is quite confusing if the context selector has fields like "source".For example
gives the error message