Closed DimiDimit closed 3 years ago
@DimiDimit I don't have this compiler (the most recent nightly with rls seems to be 2020-12-31, which is what I use). The macro that errors out is simply delegating to either async_std::test
or tokio::test
attributes to run the the tests. Could you test the compiler with a sample function and directly using one of these attributes?
Eg.
#[test]
#[tokio::test(flavor = "multi_thread", worker_threads=1)]
fn hello_world() {
eprintln!("Hello world!");
}
I forgot to add this, but expanding the test_fixtures!
macro manually through the wonders of copy-paste works perfectly fine, but using it errors out. I could've also used that as my workaround, now that I think about it.
I found that the #[cfg_attr]
makes no difference for this error.
Also, this is an unexpected compiler panic which means it's apparently a bug with rustc
.
Interesting. In the interest of finding a MWE to take to the rustc team, does the following eg. compile?
#[macro_use]
macro_rules! testing {
($($item:item)*) => {
$(
#[cfg_attr(feature = "use-async-std", test)]
$item
)*
}
}
testing! {
fn hello_world() {
eprintln!("Hello world!")
}
}
You would test this by: cargo test --features use-async-std -- hello_world --nocapture
.
That actually compiles and runs just fine! Oddly enough, commenting out the following tests in src/tests.rs
makes it compile: scope_lifetime
, cancellation_soundness
, backpressure
and test_async_deadlock
.
running 4 tests
test tests::test_scope_and_collect ... ok
test tests::test_scope_and_block ... ok
test tests::test_scope ... ok
test tests::scope_async ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.10s
Oh, I see!! It has to do with doc comments (notice the async_std::test
, just test
works fine):
#[macro_use]
macro_rules! testing {
($($item:item)*) => {
$(
#[cfg_attr(feature = "use-async-std", async_std::test)]
$item
)*
}
}
testing! {
// Normal comments work just fine.
/// Doc comment? Nope, compilation error.
async fn hello_world() {
eprintln!("Hello world!")
}
}
It just so happens that those particular tests had doc comments.
Oh interesting. You mean the above testing
example compiles with test
, but not async_std::test
or tokio::test
whenever there are doc comments? Possibly something to do with the specifics of how the two proc macros are implemented.
Yes. I also tried trace_macros!(true)
and the output was the same both for the old and new nightlies, so it seems it is indeed the proc macros.
Thanks for investigating this; we should either raise this issue in async_std
or rust-lang/rust
. Meanwhile, I'll update this crate with your suggested fix (using #[cfg(test)]
for the mod tests
) so that the crate at least builds with latest nightlies.
I compiled rustc
with debug = true
, then ran with RUST_BACKTRACE=1
and here's the output:
```
Compiling async-scoped v0.6.0 (/tmp/async-scoped)
thread 'rustc' panicked at 'internal error: entered unreachable code', compiler/rustc_expand/src/proc_macro_server.rs:193:20
stack backtrace:
thread 'rustc' panicked at 'internal error: entered unreachable code', compiler/rustc_expand/src/proc_macro_server.rs:193:20
stack backtrace:
0: rust_begin_unwind
at /tmp/rust/library/std/src/panicking.rs:493:5
1: core::panicking::panic_fmt
at /tmp/rust/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /tmp/rust/library/core/src/panicking.rs:50:5
3:
In short, we end up in compiler/rustc_expand/src/proc_macro_server.rs:193
:
Eof => unreachable!(),
I also had a look at async_std::test
, and it's trivial so we can rule async_std
out completely. Judging by everything up until now as well as this:
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
I think we can safely say it's an issue with rustc
and submit it there. I'll do the honors.
rust-lang/rust#81007
Looks like recent nightlies have fixed the ICE (verified on 22ddcd1a1 2021-01-22
).
I can confirm that it is indeed fixed after rust-lang/rust@11b1e37, and evened out my fork with upstream.
Compiling on any nightly version after
2021-01-10
errors out:(This is for
use-tokio
, the error foruse-async-std
is very similar:)After some trial and error I traced the problem to commit rust-lang/rust@6184f23950fb4aa14884ce310d948dc6fca269a3, which merges rust-lang/rust#80830.
I'm not sure whether this is an issue with
rustc
,tokio
/async-std
orasync-scoped
, I couldn't find an existing issue about it, so I decided to submit it here for the time being.For now, I've pushed a workaround to my fork which just adds
#![cfg(test)]
to thetests.rs
file, which means that the tests won't be compiled during normal usage, hence avoiding the error.