Skip to content

Code behaves differently when inside macro when using nightly #77532

Closed
@pac85

Description

@pac85

I had a problem while using vulkano-shaders, I narrowed the problem down to this example.
https://gitlab.com/pac85/shaderc-test
I couldn't pin point the exact problem.

If you run the test with the stable compiler everything is fine, if you use nightly the macro panics.
If you take the code inside the macro and run it normally it runs just fine.

Activity

added
requires-nightlyThis issue requires a nightly compiler in some way.
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
on Oct 4, 2020
pietroalbini

pietroalbini commented on Oct 4, 2020

@pietroalbini
Member

@Mark-Simulacrum the reporter says this works on stable but not on beta. cc @rust-lang/release

pietroalbini

pietroalbini commented on Oct 4, 2020

@pietroalbini
Member

Hmm, wait, I can't reproduce on stable, beta nor nightly. @pac85 does it still return an error if you remove the target directory first?

Mark-Simulacrum

Mark-Simulacrum commented on Oct 4, 2020

@Mark-Simulacrum
Member

Do we have the panic message? There were several macro-related breaking changes this cycle, I think.

I won't have a chance to try to reproduce locally or minimize for a bit, @rustbot ping cleanup - could we get a bisection and/or mcve?

rustbot

rustbot commented on Oct 4, 2020

@rustbot
Collaborator

Error: Parsing ping command in comment failed: ...'ng cleanup' | error: expected end of command at >| ' - could w'...

Please let @rust-lang/release know if you're having trouble with this bot.

changed the title [-]Code behaves differently when inside macro when ausing nightly[/-] [+]Code behaves differently when inside macro when using nightly[/+] on Oct 4, 2020
pac85

pac85 commented on Oct 4, 2020

@pac85
Author

@pietroalbini

Error message
~/cose/shaderc-test on  master ⌚ 21:04:51
$ cargo clean

~/cose/shaderc-test on  master ⌚ 21:04:57
$ rustup default stable
info: using existing install for 'stable-x86_64-unknown-linux-gnu'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.46.0 (04488afe3 2020-08-24)


~/cose/shaderc-test on  master ⌚ 21:05:14
$ cargo test
 ...

    Finished test [unoptimized + debuginfo] target(s) in 4.85s
     Running target/debug/deps/shaderc_test-e9f5c945c9e7bde8

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/inside_macro-a78288748d256321

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/out_of_macro-cdd0143a6165bf97

running 1 test
test out_of_macro ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests shaderc-test

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out


~/cose/shaderc-test on  master ⌚ 21:05:21
$ rustup default nightly
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: default toolchain set to 'nightly-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.49.0-nightly (25c8c53dd 2020-10-03)


~/cose/shaderc-test on  master ⌚ 21:05:42
$ cargo clean

~/cose/shaderc-test on  master ⌚ 21:05:46
$ cargo test 
   Compiling cc v1.0.60
   Compiling libc v0.2.78
   Compiling cmake v0.1.44
   Compiling shaderc-sys v0.6.2
   Compiling shaderc v0.6.2
   Compiling shaderc-test v0.1.0 (/mnt/void/home/archdata/cose/shaderc-test)
warning: unused import: `shaderc_test`
 --> tests/out_of_macro.rs:1:5
  |
1 | use shaderc_test;
  |     ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: proc macro panicked
 --> tests/inside_macro.rs:3:1
  |
3 | test!();
  | ^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: CompilationError(2, "shader.glsl:3: error: \'#line\' : must by followed by an integral literal\nshader.glsl: error: shader.glsl:-1: \'#line\' : unexpected tokens following directive\n")

error: aborting due to previous error

error: could not compile `shaderc-test`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
warning: 1 warning emitted

error: build failed
ehuss

ehuss commented on Oct 4, 2020

@ehuss
Contributor

I think this is the same as #76980. For some reason, shaderc-sys is experiencing some corruption when running within rustc as a proc-macro. In particular, this line is a C++ ostringstream that on stable computes correctly (this particular instance evalutes to the string "#line 1 \"std/foo", but on nightly it is corrupted (it evaluates to "#line ").

pietroalbini

pietroalbini commented on Oct 4, 2020

@pietroalbini
Member

Ok, I was running cargo build, not cargo test. Can confirm it's broken on beta and nightly, and it works on stable.

pietroalbini

pietroalbini commented on Oct 4, 2020

@pietroalbini
Member

@rustbot ping cleanup

8 remaining items

Loading
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

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.ICEBreaker-Cleanup-CrewHelping to "clean up" bugs with minimal examples and bisectionsregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@pietroalbini@Mark-Simulacrum@pac85@camelid

        Issue actions

          Code behaves differently when inside macro when using nightly · Issue #77532 · rust-lang/rust