Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[macro_use] on use broken with gfx-rs #52798

Open
nwoeanhinnogaehr opened this issue Jul 28, 2018 · 4 comments
Open

#[macro_use] on use broken with gfx-rs #52798

nwoeanhinnogaehr opened this issue Jul 28, 2018 · 4 comments
Labels
A-edition-2018-lints Area: lints supporting the 2018 edition S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.

Comments

@nwoeanhinnogaehr
Copy link

nwoeanhinnogaehr commented Jul 28, 2018

With rust 2015 we can do this:

#[macro_use] extern crate gfx;

gfx_defines! {
    vertex Vertex {
        pos: [f32; 2] = "a_Pos",
    }
    pipeline rect_pipe {
        vertices: gfx::VertexBuffer<Vertex> = (),
    }
}

fn main() {}

But it's 2018 so we should deal with this warning:

warning: deprecated `#[macro_use]` directive used to import macros should be replaced at use sites with a `use` statement to import the macro instead
 --> src/main.rs:4:1
  |
4 | #[macro_use]
  | ^^^^^^^^^^^^
  |

OK, lets give it a try.

#![feature(rust_2018_preview)]
#![warn(rust_2018_idioms)]

use gfx;
#[macro_use] use gfx::gfx_defines;

gfx_defines! {
    vertex Vertex {
        pos: [f32; 2] = "a_Pos",
    }
    pipeline rect_pipe {
        vertices: gfx::VertexBuffer<Vertex> = (),
    }
}

fn main() {}

Oops!

error: cannot find macro `gfx_vertex_struct_meta!` in this scope
  --> src/main.rs:7:1
   |
7  | / gfx_defines! {
8  | |     vertex Vertex {
9  | |         pos: [f32; 2] = "a_Pos",
10 | |     }
...  |
13 | |     }
14 | | }
   | |_^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: cannot find macro `gfx_pipeline!` in this scope
  --> src/main.rs:7:1
   |
7  | / gfx_defines! {
8  | |     vertex Vertex {
9  | |         pos: [f32; 2] = "a_Pos",
10 | |     }
...  |
13 | |     }
14 | | }
   | |_^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Looks like it wants me to import some macros which are used internally by the one that I called. Surely that's a bug in itself. Lets try and work around it though!

Two iterations later, we have #[macro_use] use gfx::{gfx_defines, gfx_pipeline, gfx_vertex_struct_meta, gfx_impl_struct_meta, gfx_pipeline_inner}; and an odd message.

error[E0282]: type annotations needed
  --> src/gui/render.rs:19:1
   |
19 | / gfx_defines! {
20 | |     vertex Vertex {
21 | |         pos: [f32; 2] = "a_Pos",
22 | |     }
...  |
70 | |     }
71 | | }
   | |_^ cannot infer type for `std::ops::Range<{integer}>`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Cargo suggests running with -Z external-macro-backtrace, but then complains that no such -Z flag exists (yes, this is a nightly build). I guessed that I should really be passing that flag to rustc and not cargo, so I tried RUSTFLAGS="-Z external-macro-backtrace" cargo run and got the info I was looking for.

error[E0282]: type annotations needed
   --> <gfx_pipeline_inner macros>:88:28
    |
1   | /      { $ ( $ field : ident : $ ty : ty , ) * } => {
2   | |      use $ crate :: pso :: {
3   | |      DataLink , DataBind , Descriptor , InitError , RawDataSet , AccessInfo } ; # [
4   | |      derive ( Clone , Debug , PartialEq ) ] pub struct Data < R : $ crate ::
...   |
88  | |      => (  ) , } ) * } for _ in 0 .. 1 {
    | |                                 ------
    | |                                 |
    | |                                 cannot infer type for `std::ops::Range<{integer}>`
    | |                                 in this expansion of `desugaring of `...`` (#7)
    | |                                 in this macro invocation (#7)
...   |
99  | |      $ ( meta . $ field . bind_to ( out , & self . $ field , man , access ) ; ) * }
100 | |      } }
    | |________- in this expansion of `gfx_pipeline_inner!` (#6)
    |
   ::: <gfx_defines macros>:1:1
    |
1   |        (
    |      __-
    |     |__|
    |    ||__|
    |   |||__|
    |  ||||
2   |  ||||  $ ( # [ $ attr : meta ] ) * vertex $ name : ident {
3   |  ||||  $ (
4   |  ||||  $ ( # [ $ field_attr : meta ] ) * $ field : ident : $ ty : ty = $ e : expr , )
...    ||||
17  |  ||||  ) => { gfx_pipeline ! ( $ name { $ ( $ field : $ ty = $ e , ) + } ) ; } ; (
    |  ||||         -------------------------------------------------------------- in this macro invocation (#5)
...    ||||
24  |  ||||  $ ( $ ( # [ $ field_attr ] ) * $ field : $ ty = $ e , ) + } } gfx_defines ! (
    |  ||||________________________________________________________________-
    | |||||________________________________________________________________|
    | |||||
25  | |||||  $ ( $ tail ) + ) ; } ; (
    | |||||                   -
    | |||||___________________|
    | |||||___________________in this macro invocation (#2)
    |  ||||                   in this macro invocation (#4)
...    ||||
37  | |||||  gfx_defines ! { $ keyword $ name { $ ( $ field : $ ty = $ e , ) + } }
38  | |||||  gfx_defines ! ( $ ( $ tail ) + ) ; } ;
    | |||||  ----------------------------------   -
    | |||||__|____________________________________|
    | ||||___|____________________________________in this expansion of `gfx_defines!` (#1)
    | |||____|____________________________________in this expansion of `gfx_defines!` (#2)
    | ||_____|____________________________________in this expansion of `gfx_defines!` (#3)
    | |      |                                    in this expansion of `gfx_defines!` (#4)
    | |      in this macro invocation (#3)
    |
   ::: <gfx_pipeline macros>:1:1
    |
1   |      / ( $ module : ident { $ ( $ field : ident : $ ty : ty = $ value : expr , ) * }
2   |      | ) => {
3   |      | # [ allow ( missing_docs ) ] pub mod $ module {
4   |      | # [ allow ( unused_imports ) ] use super :: * ; # [ allow ( unused_imports ) ]
5   |      | use super :: gfx ; gfx_pipeline_inner ! { $ ( $ field : $ ty , ) * } pub fn
    |      |                    ------------------------------------------------- in this macro invocation (#6)
6   |      | new (  ) -> Init < 'static > { Init { $ ( $ field : $ value , ) * } } } }
    |      |_________________________________________________________________________- in this expansion of `gfx_pipeline!` (#5)
    |
   ::: src/gui/render.rs:19:1
    |
19  | /      gfx_defines! {
20  | |          vertex Vertex {
21  | |              pos: [f32; 2] = "a_Pos",
22  | |          }
...   |
70  | |          }
71  | |      }
    | |______- in this macro invocation (#1)

The ASCII art is beautiful. But I still have no clue what is going on, especially considering that this was working fine when I was doing #[macro_use] extern crate gfx;.

for _ in 0 .. 1 { } appears to be a fully valid construct when it appears anywhere else but here.

version info:

rustc 1.29.0-nightly (6a1c0637c 2018-07-23)
binary: rustc
commit-hash: 6a1c0637ce44aeea6c60527f4c0e7fb33f2bcd0d
commit-date: 2018-07-23
host: x86_64-unknown-linux-gnu
release: 1.29.0-nightly
LLVM version: 7.0

gfx crate is at 0.17.1

@zimond
Copy link

zimond commented Aug 17, 2018

Same, one more vote here

@jonas-schievink jonas-schievink added A-macros-1.2 Area: Declarative macros 1.2 A-edition-2018-lints Area: lints supporting the 2018 edition and removed A-macros-1.2 Area: Declarative macros 1.2 labels Jan 27, 2019
@AregevDev
Copy link

AregevDev commented Apr 27, 2019

Getting a similar issue with gfx 0.18.1 and rust 1.34.1

error[E0432]: unresolved import `super::gfx`
  --> src/main.rs:10:1
   |
10 | / gfx_defines! {
11 | |     vertex Vertex {
12 | |         pos: [f32; 4] = "a_Pos",
13 | |         color: [f32; 3] = "a_Color",
...  |
24 | |     }
25 | | }
   | |_^ no `gfx` in the root
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

@Enselic
Copy link
Member

Enselic commented Nov 20, 2023

Triage: Can this still be reproduced? If yes, can someone please provide a minimal reproducer, including a Cargo.toml? Thanks!

@Enselic Enselic added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Nov 20, 2023
@kpreid
Copy link
Contributor

kpreid commented Dec 25, 2023

@rustbot label +S-needs-repro -E-needs-mcve

@rustbot rustbot added S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: lints supporting the 2018 edition S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress.
Projects
None yet
Development

No branches or pull requests

7 participants