fix(aop): advice/pointcut macros generate valid Rust + uppercase aliases#67
Open
ViewWay wants to merge 1 commit into
Open
fix(aop): advice/pointcut macros generate valid Rust + uppercase aliases#67ViewWay wants to merge 1 commit into
ViewWay wants to merge 1 commit into
Conversation
The published hiver-aop 0.1.0-alpha.6 was unusable from downstream crates (#60, #61): every advice/pointcut macro emitted `impl #func_name { ... }` where `#func_name` is a *function*, not a type. This produced: - inside an `impl` block: error: implementation is not supported in traits or impls - on a free function: error[E0573]: expected type, found function <name> Fix: the macros now emit the annotated `fn` unchanged plus a uniquely-named companion `const _HIVER_<KIND>_<NAME>_META: (&str, &str) = (pointcut, kind)`. A bare `const` (not a nested `impl`) is valid Rust both at module scope and inside an `impl` block, so advice now works in both contexts. Also: - Re-export Spring-familiar uppercase aliases (Aspect/Before/After/Around/ AfterReturning/AfterThrowing/Pointcut) so the README import shape compiles. - Rewrite README + doc examples to the real, compiling API (lowercase macros, JoinPoint/ProceedingJoinPoint in scope, Rust pointcut semantics instead of JVM package patterns). - Add trybuild regression tests covering free-fn advice, impl-block advice (the original failing case), uppercase aliases, and a compile_fail fixture. - Re-enable examples/logging_aspect.rs as a buildable, runnable example. - Add hiver-aop-macros/README.md (Cargo.toml referenced it but it was missing, which blocked `cargo package`/publish). Verified: both #60 reproductions now `cargo check` from a fresh downstream crate; all 56 unit tests, 4 trybuild cases, and 2 compiled doc-tests pass; nightly `cargo fmt --check` and clippy clean for the touched crates. Fixes #60 Fixes #61
📦 Public API ChangesNo public API changes.
|
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.
Summary
Fixes the broken
hiver-aopAPI that made it unusable from downstream crates.hiver-aopREADME/API example does not compile from downstream crates[Bug] https://crates.io/crates/hiver-aop 用不了Root cause
The published
0.1.0-alpha.6was unusable: every advice/pointcut macro emittedimpl #func_name { ... }where#func_nameis a function, not a type. Thisbroke in every context:
impl Aspect { #[before] ... }block →error: implementation is not supported in traits or impls#[before] fn free_advice()→error[E0573]: expected type, found function free_adviceAdditionally, the runtime type re-export was previously gated behind
#[cfg(not(proc_macro))](now removed), sohiver_aop::JoinPointwas notreachable downstream, and the README used uppercase Spring-style macro names
(
Aspect/Before/...) that were never exported.The fix
The macros now emit the annotated
fnunchanged plus a uniquely-namedcompanion
constrecording the pointcut expression and advice kind:A bare
const(not a nestedimpl) is valid Rust both at module scope andinside an
implblock, so advice now works in both contexts.Changes
hiver-aop-macros/src/advice.rsfn+ companionconstvia a sharedexpand_advicehelper; removed invalidimpl #func_namehiver-aop-macros/src/pointcut.rsconstfixhiver-aop/src/lib.rsAspect/Before/After/Around/AfterReturning/AfterThrowing/Pointcut) so the README import shape compileshiver-aop/README.mdadvice.rs/pointcut.rs/aspect.rs/runtime.rs/lib.rsexamples updated to compile-ready shapehiver-aop/tests/examples/logging_aspect.rs.disabled) as a buildable, runnable examplehiver-aop-macros/README.mdCargo.tomlreferenced./README.mdbut it was missing, which blockedcargo package/publishVerification
cargo checkfrom a freshdownstream crate (uppercase aliases inside
implblock, and lowercase free fn).cargo test -p hiver-aop -p hiver-aop-macros: 56 unit tests + 1 trybuildsuite (4 cases) + 2 compiled doc-tests all pass.
cargo run -p hiver-aop --example logging_aspectruns end-to-end.cargo +nightly fmt -p hiver-aop -p hiver-aop-macros -- --check: clean.cargo clippyintroduces no new warnings (pre-existingunwrap_usedwarningsin untouched
runtime.rsregistry code are out of scope).Note on releasing
This PR does not bump the version (per discussion). The fix lives in-repo;
shipping it to crates.io is a separate tag-triggered
release.ymlstep. Notethat
hiver-aop-macrosmust be published beforehiver-aop(the latterdeclares a version dependency on the former).
Out of scope
Dependabot PRs (#64/#65/#66) and the dependency-update issue #16 are unrelated
dependency bumps and are not addressed here.