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

include_str!(file!()) does not work on godbolt #3086

Open
CohenArthur opened this issue Jul 18, 2024 · 2 comments
Open

include_str!(file!()) does not work on godbolt #3086

CohenArthur opened this issue Jul 18, 2024 · 2 comments

Comments

@CohenArthur
Copy link
Member

as found by @liamnaddell in #1085

#![feature(rustc_attrs)]

#[rustc_builtin_macro]
macro_rules! include_str {
    () => {{}};
}

#[rustc_builtin_macro]
macro_rules! file {
    () => {{}};
}

fn main() {
    let _ = include_str!(file!());
}

I expected to see this happen: no error

Instead, this happened: gccrs complains that it is not able to open the file at /app/<source> even though printing the result of the file!() macro shows /app/example.rs

@liamnaddell
Copy link
Contributor

How do we know this is a gccrs bug instead of a godbolt bug?

@liamnaddell
Copy link
Contributor

liamnaddell commented Jul 20, 2024

I tried this code in godbolt and got the following interesting result: https://godbolt.org/z/hMb9bso3j

<source>:14:4: error: assignment of read-only location '{.data=(unsigned char * const *) "<source>", .len=15}'
   14 |    file!() = "bob";
      |    ^~~~
Compiler returned: 1

However, for gccrs on my laptop, I get

main2.rs:14:4: error: assignment of read-only location ‘{.data=(unsigned char * const *) "main2.rs", .len=8}’
   14 |    file!() = "bob";
      |    ^~~~

If you use rustc, and try the valid version of this code, you get /app/example.rs. I wonder if they handle rustc and gccrs differently in this case?

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

No branches or pull requests

2 participants