Code Monkey home page Code Monkey logo

Comments (8)

dtolnay avatar dtolnay commented on August 16, 2024 2

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.

hellow554 avatar hellow554 commented on August 16, 2024

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.

shepmaster avatar shepmaster commented on August 16, 2024

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.

hellow554 avatar hellow554 commented on August 16, 2024

"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.

shepmaster avatar shepmaster commented on August 16, 2024

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.

shepmaster avatar shepmaster commented on August 16, 2024

improve the error message in this case,

This would be difficult as the error message comes directly from syn.

from snafu.

hellow554 avatar hellow554 commented on August 16, 2024

Hey @shepmaster,

rocket solved the issue in rwf2/Rocket@97f6bc5 maybe it is something snafu can adopt?

from snafu.

shepmaster avatar shepmaster commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.