Repository navigation
fix(macros): 带 #[cfg] 的方法只在包含它的构建里检查(#541) - #591
Merged
Merged
Conversation
This was referenced Oct 23, 2026
…hods # Conflicts: # crates/rutis-macros/src/lib.rs # docs/guarantees.en.md # docs/guarantees.md # docs/guide/rust-host.en.md # docs/guide/rust-host.md
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #541(第 2 项)。第 1 项与第 4 项的一部分已由 #555 完成;第 3 项(
build.rs生成器的marked()不按 impl cfg 过滤)、第 4 项的回调形态检查与跨块 camelCase 重名按排期推到 0.16,本 PR 不涉及。问题
#[rutis::service]对所有公开方法做绑定校验,不看方法自己的#[cfg]:#[cfg(windows)] pub fn f(&mut self)在 Linux 上也报 “cannot be called from other languages”,尽管这个方法不在构建里。方法上的 cfg 会原样到达宏,但宏求不了 cfg 的值。修复
宏不再当场报带
#[cfg](含cfg_attr(.., cfg(..)))的方法的错误,而是把错误生成为带同样 cfg(以及 impl 的 cfg)的compile_error!,span 仍在那个方法上。没有这个方法的构建里,错误随方法一起被 cfg 去掉;有这个方法的构建里,照样是指到该方法、提示#[service(skip)]的编译错误(R5)。接收者、绑定不了的参数/返回值、同名方法这几类错误都走这条路径;不带 cfg 的方法不变。测试(修复前都失败)
crates/rutis-bridge/tests/marked_services.rs:Greeter加了#[cfg(any())] pub fn reset(&mut self)和cfg_attr去掉的pub fn make<T: Default>(&self) -> T。修复前这个测试文件编译失败(两个错误),修复后能编译,现有用例全部通过。rutis-macros单元测试a_cfg_methods_error_is_under_its_cfg:错误带方法与 impl 的 cfg、指到方法所在的行。rutis/src/service.rs的文档测试:#[cfg(all())]的&mut self方法仍然编译失败(compile_fail),#[cfg(any())]的能编译。文档(中英)
设计 R5、Rust 宿主指南“对外的方法”、承诺表
bridge/marked-services。本地 macOS:
cargo fmt、clippy-p rutis-macros -p rutis -p rutis-bridge --all-targets --all-features -D warnings、cargo test -p rutis-macros、cargo test -p rutis --doc service、cargo test -p rutis-bridge --all-features --test marked_services。