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

include! macro expand failed on Windows #18783

Open
Fancyflame opened this issue Dec 29, 2024 · 1 comment
Open

include! macro expand failed on Windows #18783

Fancyflame opened this issue Dec 29, 2024 · 1 comment
Labels
C-bug Category: bug

Comments

@Fancyflame
Copy link

Fancyflame commented Dec 29, 2024

rust-analyzer version: 0.4.2234-standalone (d3bb15e 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: rust-skia/rust-skia#1080

description:
The macro expanding failure caused the exception of type recognition.

https://github.com/rust-skia/rust-skia/blob/2406042e2d10c4133b0fd075144201e8126ad8a7/skia-bindings/src/lib.rs#L19

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.
Image

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.

@Fancyflame Fancyflame added the C-bug Category: bug label Dec 29, 2024
@Veykril
Copy link
Member

Veykril commented Dec 29, 2024

Sounds like we are losing the escaping of \ somewhere along the way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants