Skip to content

$crate cannot come from SyntaxContextId::ROOT on hover

Open

Description

rust-analyzer version: master

code snippet to reproduce:

macro_rules! foo {
    ($name:ident) => {
        pub static $name = Foo::new(|| {
            $crate;
        });
    };
}

foo!(BAR_);

Hovering on BAR_ causes a panic:

thread 'Worker' panicked at crates/hir-expand/src/prettify_macro_expansion_.rs:28:41:
`$crate` cannot come from `SyntaxContextId::ROOT`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panicking.rs:662:5
   1: core::panicking::panic_fmt
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/panicking.rs:74:14
   2: core::panicking::panic_display
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/panicking.rs:264:5
   3: core::option::expect_failed
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/option.rs:2027:5
   4: core::option::Option<T>::expect
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/option.rs:930:21
   5: hir_expand::prettify_macro_expansion_::prettify_macro_expansion::{{closure}}::{{closure}}
             at /test/rust-analyzer/crates/hir-expand/src/prettify_macro_expansion_.rs:28:21
   6: std::collections::hash::map::Entry<K,V>::or_insert_with
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/collections/hash/map.rs:2664:43
   7: hir_expand::prettify_macro_expansion_::prettify_macro_expansion::{{closure}}
             at /test/rust-analyzer/crates/hir-expand/src/prettify_macro_expansion_.rs:25:13
   8: syntax_bridge::prettify_macro_expansion::prettify_macro_expansion
             at /test/rust-analyzer/crates/syntax-bridge/src/prettify_macro_expansion.rs:62:60
   9: hir_expand::prettify_macro_expansion_::prettify_macro_expansion
             at /test/rust-analyzer/crates/hir-expand/src/prettify_macro_expansion_.rs:21:5
  10: ide::hover::render::definition::{{closure}}
             at /test/rust-analyzer/crates/ide/src/hover/render.rs:492:24
  11: ide::hover::render::definition
             at /test/rust-analyzer/crates/ide/src/hover/render.rs:459:17
  12: ide::hover::hover_for_definition
             at /test/rust-analyzer/crates/ide/src/hover.rs:408:18
  13: ide::hover::hover_offset::{{closure}}::{{closure}}
             at /test/rust-analyzer/crates/ide/src/hover.rs:263:21
  14: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/ops/function.rs:305:13
  15: core::option::Option<T>::map
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/option.rs:1107:29
  16: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/iter/adapters/map.rs:107:26
  17: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/alloc/src/vec/spec_from_iter_nested.rs:24:32
  18: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/alloc/src/vec/spec_from_iter.rs:33:9
  19: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/alloc/src/vec/mod.rs:2986:9
  20: core::iter::traits::iterator::Iterator::collect
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/core/src/iter/traits/iterator.rs:2000:9
  21: ide::hover::hover_offset::{{closure}}
             at /test/rust-analyzer/crates/ide/src/hover.rs:217:17
  22: ide::hover::hover_offset
             at /test/rust-analyzer/crates/ide/src/hover.rs:215:27
  23: ide::hover::hover
             at /test/rust-analyzer/crates/ide/src/hover.rs:122:9
  24: ide::Analysis::hover::{{closure}}
             at /test/rust-analyzer/crates/ide/src/lib.rs:527:27
  25: ide::Analysis::with_db::{{closure}}
             at /test/rust-analyzer/crates/ide/src/lib.rs:834:29
  26: std::panicking::try::do_call
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panicking.rs:554:40
  27: std::panicking::try
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panicking.rs:518:19
  28: std::panic::catch_unwind
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panic.rs:345:14
  29: salsa::Cancelled::catch
             at /test/rust-analyzer/crates/salsa/src/lib.rs:633:15
  30: ide::Analysis::with_db
             at /test/rust-analyzer/crates/ide/src/lib.rs:834:9
  31: ide::Analysis::hover
             at /test/rust-analyzer/crates/ide/src/lib.rs:527:9
  32: rust_analyzer::handlers::request::handle_hover
             at /test/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs:1169:22
  33: rust_analyzer::handlers::dispatch::RequestDispatcher::on_with_thread_intent::{{closure}}::{{closure}}
             at /test/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs:219:17
  34: std::panicking::try::do_call
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panicking.rs:554:40
  35: std::panicking::try
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panicking.rs:518:19
  36: std::panic::catch_unwind
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/std/src/panic.rs:345:14
  37: core::ops::function::FnOnce::call_once{{vtable.shim}}
  38: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/41dd149fd6a6a06795fc6b9f54cb49af2f61775f/library/alloc/src/boxed.rs:2150:9
  39: stdx::thread::pool::Pool::new::{{closure}}
             at /test/rust-analyzer/crates/stdx/src/thread/pool.rs:61:29
  40: stdx::thread::Builder::spawn::{{closure}}
             at /test/rust-analyzer/crates/stdx/src/thread.rs:66:13

I doubt that snippet is as minimal as possible, but weirdly enough, the Foo::new(|| {}) is necessary, and so is the underscore in BAR_. Renaming it to BAR doesn't repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

C-bugCategory: bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions