Support where clauses on traits and generic impl blocks#24
Conversation
Remove rejections in expand_trait and expand_impl, forwarding the generics and where clauses to the generated inner trait, public marker trait, blanket impl, and impl block. Generic impls are always cold (can't be listed as hot types) but fall back to vtable dispatch correctly via the existing shim. Improve rejection messages for associated types and associated constants to explain *why* they're rejected (type parameterization requirement and dyn-compatibility respectively). Add trybuild tests (attr_where_clause, attr_generic_impl, attr_where_impl) and equivalence tests (attr_where_clause_dispatch, attr_generic_impl_dispatch) covering nested generic impls and where-clause-constrained impls through &dyn, &(dyn + Send), and &(dyn + Send + Sync). https://claude.ai/code/session_01BJen3TbKCFohcjNFeYwBiA
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR extends the devirt macro system to support trait where-clauses and generic trait implementations, adding comprehensive test coverage via equivalence and UI tests to validate the new functionality. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
validate_traitand forward the where clause to the generated inner trait, public marker trait, and blanket implexpand_impland forward the generics viasplit_for_implGeneric impls are always cold (can't appear in the hot list), but fall back to vtable dispatch correctly via the existing shim.
Changes
crates/macros/src/lib.rsvalidate_trait: drop thewhere_clauserejection; leave it foremit_trait_expansionto forwardemit_trait_expansion: extractwhere_clauseand emit it on the inner trait, public trait, and blanket implexpand_impl: drop generic-impl and where-clause-on-impl rejections; usesplit_for_implto forwardimpl_genericsandwhere_clauseto the__TraitImpl for TblockNew trybuild pass tests
attr_where_clause.rs—trait Inspectable where Self: Debugwith a default body usingformat!andDebugattr_generic_impl.rs—Scaled<T: Shape>using(&self.inner as &dyn Shape).area()for devirt dispatchattr_where_impl.rs—impl<T> Shape for Named<T> where T: Shape + DisplayEquivalence test additions
attr_where_clause_dispatch— dispatch through&dyn InspectablewhereSelf: Debugattr_generic_impl_dispatch— coversScaled<GHot>, nestedScaled<Scaled<GHot>>,Pair<A, B>with a where clause, and+ Send/+ Send + SyncflavorsTest plan
cargo test --workspace --exclude devirt-fuzz— all unit, equivalence, UI, and UI-attr tests passcargo clippy --workspace --exclude devirt-fuzz --all-targets -- -D warnings— cleanattr_where_clause,attr_generic_impl,attr_where_impl)attr_where_clause_dispatch,attr_generic_impl_dispatch)