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

Using include_str in an attribute #54775

Open
akatechis opened this issue Oct 3, 2018 · 4 comments
Open

Using include_str in an attribute #54775

akatechis opened this issue Oct 3, 2018 · 4 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@akatechis
Copy link

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.
@Centril
Copy link
Contributor

Centril commented Oct 3, 2018

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.

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Oct 3, 2018
@akatechis
Copy link
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)

@Centril
Copy link
Contributor

Centril commented Oct 3, 2018

cc @nrc, @petrochenkov

@kellda
Copy link

kellda commented Mar 9, 2023

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
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants