rust-analyzer: Proc macro server crashed

I don’t think this is a duplicate of the other macro issues, I haven’t seen this error message in them:

thread 'MacroExpander' panicked at 'assertion failed: `(left != right)`
  left: `0`,
 right: `0`', crates/proc-macro-srv/src/abis/abi_1_63/proc_macro/bridge/handle.rs:22:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::handle::InternedStore<T>::new
   5: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::HandleStore<S>::new
   6: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::run_server
   7: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::<impl proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::Client<(proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream,proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream),proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream>>::run
   8: proc_macro_srv::abis::abi_1_63::Abi::expand
   9: proc_macro_srv::abis::Abi::expand
  10: proc_macro_srv::ProcMacroSrv::expand
  11: proc_macro_srv::cli::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Similarly to the other issues, the entire macro site is marked as an error with failed to write request: Broken pipe (os error 32).

Happens with at least all serde derives, tracing #[instrument], #[async_trait] and tonic’s include_proto!.

rust-analyzer version: 0.0.0 (427061da1 2022-06-19)

rustc version: rustc 1.63.0-nightly (bb8c2f411 2022-06-19) on Arch Linux

relevant settings: rust-analyzer.procMacro.attributes.enable is true, no macros have been ignored.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 19
  • Comments: 28 (15 by maintainers)

Commits related to this issue

Most upvoted comments

The latest known-good pair is today’s nightly of both rustc and rust-analyzer. And from now on, rust nightlies contain a rust-analyzer proc-macro server that is guaranteed to use the same proc-macro bridge version as rustc, which the rust-analyzer extension will check for and use (as of today), so expect no more breakage of this kind 😃

You can read about all the details on fasterthanlime’s blog.

This workaround seems to work for me with VSCode:

  1. Install rust-analyzer via rustup:
    % rustup +nightly component add rust-analyzer-preview
    
  2. Get the path to the rust-analyzer nightly binary:
    % rustup which rust-analyzer
    /Users/dacut/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/rust-analyzer
    
  3. Add this to your VSCode settings.json, in the rust-analyzer.server.path setting:
    {
        "rust-analyzer.server.path": "/Users/dacut/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/rust-analyzer"
    }
    

@Galster-dev downgrading just hides the issue, it doesn’t fix it. To hide it you could also just disable the diagnostic.

This broke between 2022-06-18 and 2022-06-19.

Confirmed, looks like another ABI change. As a workaround you can downgrade to a nightly from around 2022-06-08.

I am pretty sure that rust-analyzer version doesn’t yet include the fix.

There are probably going to be a couple of other abi breakages in the near future. There are several PR’s affecting libproc_macro open at the moment.

Nightly indeed still seems to be broken, but beta is fixed. I think nightly already had some additional changes since beta branched (namely https://github.com/rust-lang/rust/pull/98188).

well 4cbf23c is exactly the commit id of the fix. Is the version number wrong?

I’m using rust toolchain nightly-2022-06-08 (as suggested higher up in this thread) with the latest release version of the rust-analyzer VSCode extension (0.3.1140-standalone (7e2b983fd 2022-07-24)). All VSCode settings for rust-analyzer are the defaults. This error (or a related error) is still occurring with this combination - what is the latest known-good pairing of nightly rust and rust-analyzer version? The atsamd-rs libraries make pretty heavy use of proc macros so I’m willing to use whatever tool versions necessary to have support until the larger issue here can be resolved.

The error message in question:
thread '<unnamed>' panicked at 'range end index 4 out of range for slice of length 0', library/core/src/slice/index.rs:73:5
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::slice::index::slice_end_index_len_fail_rt
   3: core::ops::function::FnOnce::call_once
   4: core::intrinsics::const_eval_select
   5: core::slice::index::slice_end_index_len_fail
   6: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::<impl proc_macro_srv::abis::abi_1_63::proc_macro::bridge::rpc::Decode<proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::HandleStore<proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::MarkedTypes<S>>> for &proc_macro_srv::abis::abi_1_63::proc_macro::bridge::Marked<<S as proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::Types>::TokenStream,proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::TokenStream>>::decode
   7: std::panicking::try
   8: std::panic::catch_unwind
   9: <proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::Dispatcher<proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::MarkedTypes<S>> as proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::DispatcherTrait>::dispatch
  10: <proc_macro_srv::abis::abi_1_63::proc_macro::bridge::closure::Closure<A,R> as core::convert::From<&mut F>>::from::call
  11: proc_macro::bridge::closure::Closure<A,R>::call
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/closure.rs:30:18
  12: proc_macro::bridge::client::TokenStream::new::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:263:27
  13: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:355:47
  14: proc_macro::bridge::client::BridgeState::with::{{closure}}::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:312:17
  15: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/scoped_cell.rs:74:9
  16: proc_macro::bridge::client::BridgeState::with::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:310:13
  17: std::thread::local::LocalKey<T>::try_with
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/thread/local.rs:445:16
  18: std::thread::local::LocalKey<T>::with
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/thread/local.rs:421:9
  19: proc_macro::bridge::client::BridgeState::with
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:309:9
  20: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:348:9
  21: proc_macro::bridge::client::TokenStream::new
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:256:17
  22: proc_macro::TokenStream::new
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/lib.rs:129:21
  23: proc_macro2::imp::TokenStream::new
             at /Users/jmccollum/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.40/src/wrapper.rs:74:60
  24: proc_macro2::TokenStream::new
             at /Users/jmccollum/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.40/src/lib.rs:185:27
  25: modular_bitfield_impl::define_specifiers::generate
             at /Users/jmccollum/.cargo/registry/src/github.com-1ecc6299db9ec823/modular-bitfield-impl-0.11.2/src/define_specifiers.rs:9:5
  26: modular_bitfield_impl::define_specifiers
             at /Users/jmccollum/.cargo/registry/src/github.com-1ecc6299db9ec823/modular-bitfield-impl-0.11.2/src/lib.rs:19:5
  27: core::ops::function::Fn::call
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/core/src/ops/function.rs:77:5
  28: proc_macro::bridge::client::Client<proc_macro::TokenStream,proc_macro::TokenStream>::expand1::{{closure}}::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:438:44
  29: proc_macro::bridge::client::run_client::{{closure}}::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:407:26
  30: proc_macro::bridge::scoped_cell::ScopedCell<T>::set::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/scoped_cell.rs:79:33
  31: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/scoped_cell.rs:74:9
  32: proc_macro::bridge::scoped_cell::ScopedCell<T>::set
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/scoped_cell.rs:79:9
  33: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:344:35
  34: std::thread::local::LocalKey<T>::try_with
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/thread/local.rs:445:16
  35: std::thread::local::LocalKey<T>::with
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/thread/local.rs:421:9
  36: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:344:9
  37: proc_macro::bridge::client::run_client::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:400:9
  38: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/core/src/panic/unwind_safe.rs:271:9
  39: std::panicking::try::do_call
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/panicking.rs:492:40
  40: ___rust_try
  41: std::panicking::try
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/panicking.rs:456:19
  42: std::panic::catch_unwind
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/std/src/panic.rs:137:14
  43: proc_macro::bridge::client::run_client
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:399:5
  44: proc_macro::bridge::client::Client<proc_macro::TokenStream,proc_macro::TokenStream>::expand1::{{closure}}
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/client.rs:438:17
  45: proc_macro::bridge::selfless_reify::reify_to_extern_c_fn_hrt_bridge::wrapper
             at /rustc/5435ed6916a59e8d5acba2149316a841c3905cbd/library/proc_macro/src/bridge/selfless_reify.rs:64:17
  46: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::<impl proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::Client<proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream,proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream>>::run
  47: proc_macro_srv::abis::abi_1_63::Abi::expand
  48: proc_macro_srv::dylib::Expander::expand
  49: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'range end index 8 out of range for slice of length 0', library/core/src/slice/index.rs:73:5
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::slice::index::slice_end_index_len_fail_rt
   3: core::ops::function::FnOnce::call_once
   4: core::intrinsics::const_eval_select
   5: core::slice::index::slice_end_index_len_fail
   6: <&str as proc_macro_srv::abis::abi_1_63::proc_macro::bridge::rpc::DecodeMut<S>>::decode
   7: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::<impl proc_macro_srv::abis::abi_1_63::proc_macro::bridge::rpc::DecodeMut<S> for core::option::Option<T>>::decode
   8: proc_macro_srv::abis::abi_1_63::proc_macro::bridge::server::<impl proc_macro_srv::abis::abi_1_63::proc_macro::bridge::client::Client<proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream,proc_macro_srv::abis::abi_1_63::proc_macro::TokenStream>>::run
   9: proc_macro_srv::abis::abi_1_63::Abi::expand
  10: proc_macro_srv::dylib::Expander::expand
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Hello! I’ve been slowly downgrading using VS marketplace so I can tell this broke in release 0.4.1086 Downgrading to 0.4.1085 seems to fix this issue (there is other error log related to proc macro server which I’m not gonna cover because it’s most likely already fixed)

Ah yeah, the older version in rustup is likely just not showing the error message.

@flodiebold Where did you get the idea that I’m running x86 VSCode? I’m running ARM VSCode (from the Universal binary), ARM rust-analyzer, etc.:

% file /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron
/Applications/Visual Studio Code.app/Contents/MacOS/Electron: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64
- Mach-O 64-bit executable arm64]
/Applications/Visual Studio Code.app/Contents/MacOS/Electron (for architecture x86_64):	Mach-O 64-bit executable x86_64
/Applications/Visual Studio Code.app/Contents/MacOS/Electron (for architecture arm64):	Mach-O 64-bit executable arm64

% file ~/.vscode/extensions/rust-lang.rust-analyzer-0.4.1101-darwin-arm64/server/rust-analyzer
/Users/dacut/.vscode/extensions/rust-lang.rust-analyzer-0.4.1101-darwin-arm64/server/rust-analyzer: Mach-O 64-bit executable arm64

Same issue as here, with the failed to write request: Broken pipe (os error 32) resulting when rustup gets out-of-sync with the rust-analyzer binary.