Skip to content

Using include_str in an attribute #54775

Open

Description

@akatechis

Not sure if this should be an RFC or a bug/issue, but I'm trying to add an attribute to a struct where the value of the attribute is a &'static str. It would be nice to have the contents of the string in a separate file so I can have syntax highlighting when editing that file, and then have that be pulled in to the rust module and built. The following should reproduce the issue:

Cargo.toml:

[package]
name = "handmade-rs"
version = "0.1.0"
edition = "2018"

[dependencies]
winit = "0.17"
vulkano = "0.10.0"
vulkano-win = "0.10.0"
vulkano-shader-derive = "0.10.0"

And then in a module, try to compile the following. The src attribute takes a string as its value, that contains the source code of the shader to compile.

#[derive(VulkanoShader)]
#[ty="compute"]
#[src=include_str!("./compute_shader.glsl")]
pub struct Dummy;

When I compile, I get the following output:

$ cargo b
   Compiling handmade-rs v0.1.0 (C:\Users\Alexandros\workspace\handmade-rs)
error: expected `]`, found `!`
 --> src\shaders\compute.rs:4:18
  |
4 | #[src=include_str!("./compute_shader.glsl")]
  |                  ^ expected `]`

error: aborting due to previous error

error: Could not compile `handmade-rs`.

To learn more, run the command again with --verbose.

Activity

  1. Centril commented on Oct 3, 2018

    @Centril
    Contributor

    I believe this is currently expected behavior; but we've discussed this in the past (#53583 (comment)) and I think it would be interesting to see an RFC that discusses and proposes something in this space.

  2. added
    T-langRelevant to the language team
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Oct 3, 2018
  3. akatechis commented on Oct 3, 2018

    @akatechis
    Author

    For the sake of completeness, my rustc and cargo versions are:

    $ cargo --version
    cargo 1.31.0-nightly (de314a8b2 2018-09-21)
    
    $ rustc --version
    rustc 1.31.0-nightly (2bd5993ca 2018-10-02)
    
  4. Centril commented on Oct 3, 2018

    @Centril
    Contributor
  5. kellda commented on Mar 9, 2023

    @kellda
    Contributor

    This is stabilized since Rust 1.54.0: #83366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions