rust-lang / rust-lang/rust-analyzer
`include!` macro expand failed on Windows
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: 0.4.2234-standalone (d3bb15ecec 2024-12-27)
rustc version: rustc 1.83.0 (90b35a623 2024-11-26)
editor or extension: VSCode
relevant settings: everything is default or doesn't affect the problem
repository link (if public, optional): https://github.com/rust-skia/rust-skia/
relevant issue: https://github.com/rust-skia/rust-skia/issues/1080
description:
The macro expanding failure caused the exception of type recognition.
In my own repo, I call Paint::new(Paint is a type alias of Handle<SkPaint>) while RA recognizes it as Bitmap::new(Bitmap alias to Handle<SkBitmap>), causing this fake error. It is because RA doesn't know what SkPaint and SkBitmap is, due to the include! macro expanding failure in rust-skia repo.
Trying to expand the macro in vscode will give this error, but the file actually exists.
// Recursive expansion of include! macro
// ======================================
Expansion had errors:
failed to load file `D:\FancyFlame\irisia-gui-new\target\debug\build\skia-bindings-641dd10db6a7c918\out\skia\bindings.rs`
I checked the log and found following panic information:
thread 'Worker' panicked at crates\paths\src\lib.rs:210:9:
D:ancyFlamerisia-gui-new argetebuguildkia-bindings-641dd10db6a7c918utkiaindings.rs is not absolute
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:665
1: core::panicking::panic_fmt
at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\panicking.rs:74
2: vfs::vfs_path::VfsPath::join
3: vfs::file_set::FileSet::resolve_path
4: <base_db::FileLoaderDelegate<&T> as base_db::FileLoader>::resolve_path
5: <ide_db::RootDatabase as base_db::FileLoader>::resolve_path
6: hir_expand::builtin::fn_macro::relative_file
7: hir_expand::builtin::fn_macro::include_input_to_file_id
8: hir_expand::builtin::fn_macro::include_expand
9: <hir_expand::db::ParseMacroExpansionQuery as ra_salsa::plumbing::QueryFunction>::execute
10: ra_salsa::Cycle::catch
11: ra_salsa::derived_lru::slot::Slot<Q,MP>::maybe_changed_after
12: <ra_salsa::derived_lru::DerivedStorage<Q,MP> as ra_salsa::plumbing::QueryStorageOps<Q>>::fetch
13: <DB as hir_expand::db::ExpandDatabase>::parse_macro_expansion
14: hir_expand::db::parse_or_expand
15: <hir_expand::db::AstIdMapQuery as ra_salsa::plumbing::QueryFunction>::execute
16: ra_salsa::Cycle::catch
17: ra_salsa::derived::slot::Slot<Q>::read
18: ra_salsa::derived::slot::Slot<Q>::read
19: <ra_salsa::derived::DerivedStorage<Q> as ra_salsa::plumbing::QueryStorageOps<Q>>::fetch
20: <DB as hir_expand::db::ExpandDatabase>::ast_id_map
21: hir_def::item_tree::ItemTree::file_item_tree_with_source_map_query
22: ra_salsa::Cycle::catch
23: ra_salsa::derived::slot::Slot<Q>::read
24: ra_salsa::derived::slot::Slot<Q>::read
25: <ra_salsa::derived::DerivedStorage<Q> as ra_salsa::plumbing::QueryStorageOps<Q>>::fetch
26: <DB as hir_def::db::DefDatabase>::file_item_tree_with_source_map
27: ra_salsa::Cycle::catch
28: ra_salsa::derived::slot::Slot<Q>::read
29: ra_salsa::derived::slot::Slot<Q>::read
30: <ra_salsa::derived::DerivedStorage<Q> as ra_salsa::plumbing::QueryStorageOps<Q>>::fetch
31: <DB as hir_def::db::DefDatabase>::file_item_tree
32: hir_def::nameres::collector::DefCollector::record_resolved_import
33: hir_def::nameres::collector::ModCollector::collect
34: hir_def::nameres::collector::ModCollector::collect
35: hir_def::nameres::collector::collect_defs
36: hir_def::nameres::DefMap::crate_def_map_query
37: ra_salsa::Cycle::catch
38: ra_salsa::derived::slot::Slot<Q>::read
39: ra_salsa::derived::slot::Slot<Q>::read
40: <ra_salsa::derived::DerivedStorage<Q> as ra_salsa::plumbing::QueryStorageOps<Q>>::fetch
41: <DB as hir_def::db::DefDatabase>::crate_def_map
42: hir::semantics::source_to_def::SourceToDefCtx::file_to_def
43: hir::semantics::SemanticsImpl::file_to_module_defs
44: hir::semantics::SemanticsImpl::attach_first_edition
45: ide_diagnostics::syntax_diagnostics
46: ide_diagnostics::full_diagnostics
47: ra_salsa::Cancelled::catch
48: rust_analyzer::handlers::request::handle_code_action
49: core::ops::function::FnOnce::call_once{{vtable.shim}}
On Windows, the file path is delimited by \ instead of / on Unix, which happens to be an escape character. Put the path string between double-quote characters directly may break the path.
All of my code and rust-skia code can pass the compilation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/paths/src/lib.rs at VfsPath::join, then trace the reported path through FileSet::resolve_path and hir_expand::builtin::fn_macro::relative_file and include_input_to_file_id. Reproduce the include! expansion on Windows and verify that the existing generated file is resolved without the reported non-absolute-path panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100