Git Product home page Git Product logo

int-enum-rs's People

Contributors

igorrafael avatar juici avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

int-enum-rs's Issues

Why is't it a derive macro?

Why it is not #[derive(int_enum::int_enum)] instead of #[int_enum::int_enum]? Does it require feature inaccessible to derive macros?

Allow constant arithmetic expressions?

I have an enum that looks like:

#[repr(u16)]
#[derive(Clone, Copy, int_enum::IntEnum)]
enum Controls {
    DpadUp     = 1<<0,
    DpadDown   = 1<<1,
    DpadLeft   = 1<<2,
    DpadRight  = 1<<3,
    FaceA      = 1<<4,
    FaceB      = 1<<5,
    ...[snip]
}

1 entry for each bit of a u16. IntEnum chokes:

error: expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`, found `<<`
  --> src/main.rs:35:19
   |
35 |     DpadUp     = 1<<0,
   |                   ^^ expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`

error: proc-macro derive produced unparsable tokens
  --> src/main.rs:33:23
   |
33 | #[derive(Clone, Copy, int_enum::IntEnum)]
   |           

The normal enum syntax does support the bitshift expressions here. Would it be possible for int_enum to support simple arithmetic in the assignment position?

SpanExt name collision with proc_macro2

SpanExt defines a method:

fn end(&self) -> Span;

And implements it on Span. However, proc-marco2 with feature span-locations also defines a method on Span:

    #[cfg(span_locations)]
    #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))]
    pub fn end(&self) -> LineColumn {
        self.inner.end()
    }

When calling end on a Span object with that feature enabled the above method takes precedence. This breaks code in an ast module where it defines:

diag = diag.span_error(v.span().end(), "missing discriminant");

Since the SpanExt is in scope the intention was for .end() to return a Span object which works since it implements MultiSpan required by span_error. With span-locations enabled It returns a LineColumn which does not implement MultiSpan:

   --> int-enum-1.0.0/src/ast.rs:120:36
    |
120 |             diag = diag.span_error(v.span().end(), "missing discriminant");
    |                         ---------- ^^^^^^^^^^^^^^ the trait `proc_macro2_diagnostics::diagnostic::MultiSpan` is not implemented for `LineColumn`
    |                         |
    |                         required by a bound introduced by this call
    |
    = help: the following other types implement trait `proc_macro2_diagnostics::diagnostic::MultiSpan`:
              proc_macro2::Span
              Vec<proc_macro2::Span>
              &'a [proc_macro2::Span]
note: required by a bound in `proc_macro2_diagnostics::Diagnostic::span_error`

The solution would be to refer to the trait explicitly:

diag = diag.span_error(<Span as SpanExt>::end(&v.span()), "missing discriminant");

Nightly diagnostic panic

The macro is panicking when emitting diagnostics on nightly.

error: proc-macro derive panicked
 --> tests/ui/missing_discriminant.rs:4:23
  |
4 | #[derive(Clone, Copy, IntEnum)]
  |                       ^^^^^^^
  |
  = help: message: assertion failed: child.level.can_be_top_or_sub().1

This is caused by a compiler change here https://github.com/rust-lang/rust/blob/59e0bc2de7134a2d88e9c14db32884e631e90373/compiler/rustc_errors/src/emitter.rs#L2119.

The only levels that can be used for sub-diagnostics emitted by proc-macros are now Warning, Note, and Help.

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.