Comments (8)
Both the fact that it doesn't work as written, and that the error message is rendered without a source line of code, are compiler bugs. The error message should be getting placed as:
error: expected expression
--> src/main.rs:5:27
|
5 | #[snafu(display("{}", r#type))]
| ^^^^^^
The root cause for both is rust-lang/rust#43081.
from snafu.
I also would suggest to improve the error message in this case, because I have no clue what's going on under the hood ^^
from snafu.
The problem is that the arguments to #[snafu(display)]
are expected to be a comma-separated list of expressions, but it appears that r#type
isn't considered one...
from snafu.
"Found ini the field" might not be correct @shepmaster. It's more that I know a lot of proc macros stumble across that, e.g. rwf2/Rocket#881.
I bet there are a lot more crates affected.
from snafu.
I've filed dtolnay/syn#628 as I don't think this is my fault. In the meantime, try this workaround:
#[snafu(display = r#"("{}", r#type)"#)]
Oc { r#type: String }
While this form is intended to support versions of Rust before 1.34, it also switches to completely using syn's string-based parsing for this value, which does work.
from snafu.
improve the error message in this case,
This would be difficult as the error message comes directly from syn.
from snafu.
Hey @shepmaster,
rocket solved the issue in rwf2/Rocket@97f6bc5 maybe it is something snafu can adopt?
from snafu.
This may have magically fixed itself in the intermediate time:
% cat examples/raw.rs
use snafu::Snafu;
#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("{}", r#type))]
Oc { r#type: String }
}
fn main() {}
% cargo build --example=raw
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
from snafu.
Related Issues (20)
- Consider adding #[snafu(transparent)] HOT 6
- Support Serde for the built-in types HOT 6
- multiple error types (struct and enum) and generic `IntoError` HOT 2
- Simple context usage, mysterious compile error HOT 2
- Use the same deprecation macros on the no_std Error as the official Error HOT 3
- Add an ensure macro that works with pattern matching HOT 2
- Restore support for yeeting context selectors HOT 1
- Print multi-line errors on their own lines in `Report` HOT 2
- Const generics seem to be giving the derive macro trouble HOT 2
- question: Best practice for automatic error conversion over two module levels?
- Cannot use a generic with a whatever variant
- Incorrect year in changelog
- No apparent way to have an error enum variant documentation generated from a display string HOT 5
- Why isn't Whatever Send + Sync by default? HOT 5
- `Report` print doesn't prefix with "Error: " HOT 1
- Is it possible to avoid manually capturing a backtrace when variant has no `source` error? HOT 2
- Document using `Option<Backtrace>` more prominently in docs
- Comparison to anyhow HOT 2
- Use the alternate formatting macros from `color_print`. HOT 2
- Consider adding simple pattern matching to the ensure macros
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snafu.