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

rustc panics when compiling code that uses tokio's LocalSet #68109

Open
Alovchin91 opened this issue Jan 11, 2020 · 5 comments
Open

rustc panics when compiling code that uses tokio's LocalSet #68109

Alovchin91 opened this issue Jan 11, 2020 · 5 comments

Comments

@Alovchin91
Copy link

@Alovchin91 Alovchin91 commented Jan 11, 2020

Compiler panics when compiling the following code that uses tokio's LocalSet:

#[tokio::main]
async fn main() {
    tokio::spawn(async move {
        let local = tokio::task::LocalSet::new();
        local.run_until(async { })
    }).await
}

--- or ---

#[tokio::main]
async fn main() {
    tokio::spawn({
        let local = tokio::task::LocalSet::new();
        local.run_until(async {})
    }).await
}

Panic message is as follows:

➜ RUST_BACKTRACE=full cargo build --verbose
       ...
       Fresh tokio v0.2.9
   Compiling rust-bug v0.1.0 (/tmp/rust-bug)
     Running `rustc --edition=2018 --crate-name rust_bug src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=b5f969b2f9a6a1a5 -C extra-filename=-b5f969b2f9a6a1a5 --out-dir /tmp/rust-bug/target/debug/deps -C incremental=/tmp/rust-bug/target/debug/incremental -L dependency=/tmp/rust-bug/target/debug/deps --extern tokio=/tmp/rust-bug/target/debug/deps/libtokio-e472db2be190b401.rlib`
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0:        0x104e46b75 - <unknown>
   1:        0x104e7dcc0 - <unknown>
             ...
 101:        0x104e59a6e - <unknown>
 102:     0x7fff6bb56e65 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.40.0 (73528e339 2019-12-16) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck_tables_of] processing `tokio::task::local::LocalSet::run_until`
#1 [typeck_tables_of] processing `tokio::task::local::LocalSet::run_until::{{closure}}#0`
#2 [typeck_tables_of] processing `main`
#3 [typeck_tables_of] processing `main::{{closure}}#0`
#4 [type_of] processing `main::{{closure}}#0`
#5 [collect_mod_item_types] collecting item types in top-level module
#6 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `rust-bug`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rust_bug src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=b5f969b2f9a6a1a5 -C extra-filename=-b5f969b2f9a6a1a5 --out-dir /tmp/rust-bug/target/debug/deps -C incremental=/tmp/rust-bug/target/debug/incremental -L dependency=/tmp/rust-bug/target/debug/deps --extern tokio=/tmp/rust-bug/target/debug/deps/libtokio-e472db2be190b401.rlib` (exit code: 101)

Dependencies:

[dependencies]
tokio = { version = "0.2.9", features = ["full"] }

Sample:

rust-bug.zip

@hellow554

This comment has been minimized.

Copy link
Contributor

@hellow554 hellow554 commented Jan 13, 2020

Does not occur on beta or nightly, although the error message could be improved:

error[E0277]: `std::rc::Rc<tokio::task::local::Scheduler>` cannot be sent between threads safely
   --> src/main.rs:3:5
    |
3   |     tokio::spawn(async move {
    |     ^^^^^^^^^^^^ `std::rc::Rc<tokio::task::local::Scheduler>` cannot be sent between threads safely
    | 
   ::: /home/op/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.9/src/task/spawn.rs:124:20
    |
124 |         T::Output: Send + 'static,
    |                    ---- required by this bound in `tokio::task::spawn::spawn`
    |
    = help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<tokio::task::local::Scheduler>`
    = note: required because it appears within the type `for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}`
    = note: required because it appears within the type `[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]`
    = note: required because it appears within the type `std::future::GenFuture<[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]>`
    = note: required because it appears within the type `impl std::future::Future`
    = note: required because it appears within the type `impl std::future::Future`

error[E0277]: `std::rc::Rc<tokio::task::local::Scheduler>` cannot be shared between threads safely
   --> src/main.rs:3:5
    |
3   |     tokio::spawn(async move {
    |     ^^^^^^^^^^^^ `std::rc::Rc<tokio::task::local::Scheduler>` cannot be shared between threads safely
    | 
   ::: /home/op/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.9/src/task/spawn.rs:124:20
    |
124 |         T::Output: Send + 'static,
    |                    ---- required by this bound in `tokio::task::spawn::spawn`
    |
    = help: within `tokio::task::local::LocalSet`, the trait `std::marker::Sync` is not implemented for `std::rc::Rc<tokio::task::local::Scheduler>`
    = note: required because it appears within the type `tokio::task::local::LocalSet`
    = note: required because of the requirements on the impl of `std::marker::Send` for `&tokio::task::local::LocalSet`
    = note: required because it appears within the type `[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]`
    = note: required because it appears within the type `std::future::GenFuture<[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]>`
    = note: required because it appears within the type `impl std::future::Future`
    = note: required because it appears within the type `impl std::future::Future`

error[E0308]: mismatched types
 --> src/main.rs:1:1
  |
1 | #[tokio::main]
  | ^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
  | |
  | expected `()`, found enum `std::result::Result`
  |
  = note: expected unit type `()`
                  found enum `std::result::Result<impl std::future::Future, tokio::task::error::JoinError>`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rust-bug`.
@hellow554

This comment has been minimized.

Copy link
Contributor

@hellow554 hellow554 commented Jan 13, 2020

Has been fixed in 41601a8 (maybe this was fixed by #67071?)

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis commented Jan 14, 2020

This could use a regression test, but it's hard because we'd have to isolate it out from the tokio dependency.

@gilescope

This comment has been minimized.

Copy link
Contributor

@gilescope gilescope commented Jan 14, 2020

@rustbot claim

@pnkfelix

This comment has been minimized.

Copy link
Member

@pnkfelix pnkfelix commented Jan 16, 2020

T-compiler triage: P-high, removing nomination label.

@pnkfelix pnkfelix added P-high and removed I-nominated labels Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.