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

Possible regression of the language server resulting in a panic #17986

Closed
vrurg opened this issue Aug 28, 2024 · 3 comments · Fixed by #17994
Closed

Possible regression of the language server resulting in a panic #17986

vrurg opened this issue Aug 28, 2024 · 3 comments · Fixed by #17994
Assignees
Labels
A-proc-macro proc macro C-bug Category: bug I-panic

Comments

@vrurg
Copy link

vrurg commented Aug 28, 2024

rust-analyzer version: rust-analyzer version: 0.3.2089-standalone (0f7f68d 2024-08-27)

rustc version: rustc 1.82.0-nightly (6de928dce 2024-08-18), though the error is there with stable too

editor or extension: VSCode

repository link (if public, optional): vrurg/fieldx

code snippet to reproduce: https://github.com/vrurg/fieldx

Straight to the output of the language server:

thread 'enum_dispatch' panicked at crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs:145:58:
cannot parse string: "lexing error"
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: std::panicking::try::do_call::<core::panic::unwind_safe::AssertUnwindSafe<<proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<proc_macro_srv::server_impl::rust_analyzer_span::RaSpanServer>> as proc_macro::bridge::server::DispatcherTrait>::dispatch::{closure#10}>, proc_macro::bridge::Marked<proc_macro_srv::server_impl::token_stream::TokenStream<span::SpanData<span::hygiene::SyntaxContextId>>, proc_macro::bridge::client::TokenStream>>
   4: <proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<proc_macro_srv::server_impl::rust_analyzer_span::RaSpanServer>> as proc_macro::bridge::server::DispatcherTrait>::dispatch
   5: <proc_macro::bridge::closure::Closure<_, _> as core::convert::From<&mut _>>::from::call::<proc_macro::bridge::buffer::Buffer, proc_macro::bridge::buffer::Buffer, <proc_macro::bridge::server::SameThread as proc_macro::bridge::server::ExecutionStrategy>::run_bridge_and_client<proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<proc_macro_srv::server_impl::rust_analyzer_span::RaSpanServer>>>::{closure#0}>
   6: proc_macro::bridge::closure::Closure<A,R>::call
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/bridge/closure.rs:30:18
   7: proc_macro::bridge::client::TokenStream::from_str::{{closure}}
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/bridge/client.rs:162:43
   8: proc_macro::bridge::client::Bridge::with::{{closure}}
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/bridge/client.rs:240:13
   9: proc_macro::bridge::client::state::with
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/bridge/client.rs:229:9
  10: proc_macro::bridge::client::Bridge::with
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/bridge/client.rs:235:9
  11: proc_macro::bridge::client::TokenStream::from_str
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/bridge/client.rs:155:17
  12: <proc_macro::TokenStream as core::str::traits::FromStr>::from_str
             at /rustc/6de928dce9472b864f4e5d590dd7aa2075cb7551/library/proc_macro/src/lib.rs:183:29
  13: core::str::<impl str>::parse
  14: enum_dispatch::cache::fulfilled_by_enum::{{closure}}::{{closure}}
  15: core::option::Option<T>::map
  16: enum_dispatch::cache::fulfilled_by_enum::{{closure}}
  17: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  18: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::find_map
  19: <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::next
  20: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
  21: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  22: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
  23: core::iter::traits::iterator::Iterator::collect
  24: enum_dispatch::cache::fulfilled_by_enum
  25: enum_dispatch::enum_dispatch2
  26: enum_dispatch::enum_dispatch
  27: core::ops::function::Fn::call
  28: proc_macro::bridge::client::Client<(proc_macro::TokenStream,proc_macro::TokenStream),proc_macro::TokenStream>::expand2::{{closure}}::{{closure}}
  29: proc_macro::bridge::client::run_client::{{closure}}::{{closure}}
  30: proc_macro::bridge::client::state::set
  31: proc_macro::bridge::client::run_client::{{closure}}
  32: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  33: std::panicking::try::do_call
  34: ___rust_try
  35: proc_macro::bridge::client::run_client
  36: proc_macro::bridge::client::Client<(proc_macro::TokenStream,proc_macro::TokenStream),proc_macro::TokenStream>::expand2::{{closure}}
  37: proc_macro::bridge::selfless_reify::reify_to_extern_c_fn_hrt_bridge::wrapper
  38: proc_macro::bridge::server::run_server::<proc_macro_srv::server_impl::rust_analyzer_span::RaSpanServer, (proc_macro::bridge::Marked<proc_macro_srv::server_impl::token_stream::TokenStream<span::SpanData<span::hygiene::SyntaxContextId>>, proc_macro::bridge::client::TokenStream>, proc_macro::bridge::Marked<proc_macro_srv::server_impl::token_stream::TokenStream<span::SpanData<span::hygiene::SyntaxContextId>>, proc_macro::bridge::client::TokenStream>), core::option::Option<proc_macro::bridge::Marked<proc_macro_srv::server_impl::token_stream::TokenStream<span::SpanData<span::hygiene::SyntaxContextId>>, proc_macro::bridge::client::TokenStream>>, proc_macro::bridge::server::SameThread>
  39: <proc_macro_srv::proc_macros::ProcMacros>::expand::<span::SpanData<span::hygiene::SyntaxContextId>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

The problem pops up when the enum_dispatch crate is used in a proc_macro crate. For example, the entire trait is permanently marked as erroneous.

The problem looks like a regression to me as it hadn't been observed until some moment in time a month or two ago.

@vrurg vrurg added the C-bug Category: bug label Aug 28, 2024
@Veykril Veykril self-assigned this Aug 29, 2024
@Veykril
Copy link
Member

Veykril commented Aug 29, 2024

Oh no, this is panicking within the proc-macro server (might be time for us to try backporting a fix to beta for the first time 🎉)

@Veykril
Copy link
Member

Veykril commented Aug 29, 2024

That macro invocation is for some reason creating format ! (Field name is required for generating '{}' helper. , helper_kind . to_string ())) in its output which has an invalid character literal in it (we shouldnt panic either way, but something else is going wrong in there)

@Veykril
Copy link
Member

Veykril commented Aug 29, 2024

We seem to be losing the quotation marks

bors added a commit that referenced this issue Aug 29, 2024
fix: Fix TokenStream::to_string implementation dropping quotation marks

Fixes #17986
We might wanna consider backporting this to beta if that's simple enough to do
@bors bors closed this as completed in 40a1a4e Aug 29, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
…, r=Veykril

fix: Fix TokenStream::to_string implementation dropping quotation marks

Fixes rust-lang/rust-analyzer#17986
We might wanna consider backporting this to beta if that's simple enough to do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-bug Category: bug I-panic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants