AI Updates #5: #[default_impl] fix, a span audit, and a new guides section#253
Merged
Conversation
#[default_impl] fix, a span audit, and a new guides section
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.
AI Overview
This PR does two loosely-coupled things. It hardens the CGP macros' error behavior — fixing one real bug in namespace default registration and pinning a set of span, coherence, and orphan-rule behaviors with compile-fail regression tests — and it restructures the knowledge base by adding a fourth top-level guides section that absorbs the old modern-idioms content and grows new namespace and debugging guides. There is one source-code change; everything else is tests and documentation. The branch is five commits ahead of
main, touching 38 files (+1441 / −343), with no source behavior removed and nothing that requires a version edit.The code change:
#[default_impl]drops the provider'swhereclauseThe one behavioral fix corrects how
#[default_impl]builds its namespace-registration impl. That attribute registers a provider as a namespace's per-component default by emittingimpl Namespace<..> for PathKey { type Delegate = Provider; }, and it builds that impl from the provider impl's generics. The problem is that by the time it runs, those generics already carry the impl-side bounds that#[use_type],#[uses],#[implicit], and#[use_provider]push ontoSelf— a provider using#[use_type(HasErrorType.Error)], for example, arrives carryingwhere Self: HasErrorType. On the registration impl,Selfis the path keyPathCons<..>, not the context, so a leakedSelf: HasErrorTypebecomes the demandPathCons<..>: HasErrorType, which never resolves. The result was that any provider with an impl-side dependency silently failed to route through the namespace, breaking every context that joined it. The fix clears thewhereclause before splitting the generics, keeping only the parameters that name the key and the provider plus the__Components__table. This is the sole change in attribute.rs, guarded by a new regression test that exercises a#[default_impl]provider carrying both a#[use_type]abstract-type dependency and an#[implicit]field read.The compile-fail audit: four new fixtures pinning spans and coherence
The PR adds four
trybuildfixtures undercgp-compile-fail-tests, all in theacceptable/tree — meaning each is a failure CGP deliberately defers to the Rust compiler rather than a case the macro should reject, so the fixture guards the caret position and message, not a new rejection. Two are span-regression tests:duplicate_component_namepins that a name clash on a derived component marker reports itsE0428note on the provider name the user wrote inside#[cgp_component(..)]rather than on the whole attribute, andmissing_dependencypins thatcheck_components!lands itsE0277caret on the failing component inside the block rather than on the shared context token. The other two document coherence and orphan-rule limits of namespaces:override_registered_pathpins that a context cannot re-wire a path its joined namespace already registers (anE0119overlap), anddefault_impl_foreign_prefix_pathpins that a downstream crate cannot register a default for a prefixed upstream component, because the path key is entirely foreign (anE0210orphan violation). Supporting these,cgp-compile-fail-testsgains a dependency oncgp-test-crate-a, and one unrelated stderr snapshot (option_slice.stderr) is refreshed to match a newer compiler's more detailed diagnostics.The cross-crate tests: a fourth namespace ability
The cross-crate coherence suite grows from three demonstrated abilities to four.
cgp-test-crate-anow declares a sharedAppNamespaceinheritingDefaultNamespace, andcgp-test-crate-bregisters a local component and provider into that upstream namespace with#[default_impl], then joins the namespace and resolves the capability through it with no direct wiring. This is orphan-safe precisely because the downstream crate owns the component key even though it does not own the namespace — the complement of thedefault_impl_foreign_prefix_pathfixture, which shows the case that is not orphan-safe.The documentation restructuring: a new guides section
The largest structural change is a new fourth top-level documentation section,
docs/guides/, sitting alongside reference, concepts, and examples. The four sections now answer four distinct questions: reference says what a construct is, concepts explain an idea, examples show a construct solving a problem, and a guide is prescriptive — it recommends a default form, names the trade-offs of the alternatives, and usually walks a concrete before/after refactoring. The olddocs/concepts/modern-idioms.mdmigration guide (215 lines) is removed, and its content is redistributed across granular new guides: writing providers, declaring dependencies, reading context fields, importing abstract types, capability supertraits, and dispatching per type. Two entirely new guides join them: a large namespaces-and-prefixes guide that works keeping a growing wiring table short as a real refactoring, and a debugging guide for tracing a lazy-wiring failure back to its cause. The section indexes and authoring rules are updated to match —docs/README.md(three to four sections),docs/AGENTS.md(a new guides-directory rule), and the concepts and examples READMEs.The example and reference updates
The money-transfer-api example is substantially rewritten to carry the new material end to end. It gains a status-coded errors section and reorganizes its context wiring around a namespace (a renamed and expanded "Organizing the wiring with a namespace" section), so the example now demonstrates the constructs the new guides recommend. In parallel, the implementation and reference documents that describe the fixed and pinned behaviors are updated in the same change, per the knowledge base's synchronization rule: the
#[default_impl]where-clause behavior is documented in the attributes implementation doc, thedefault_namespacereference, and the namespaces sub-skill; new Failure modes sections are added to thecgp_componentandcheck_componentsimplementation docs; and a Known issues note on namespace override overlap is added to thecgp_namespacereference.Impacts
The following are the concrete effects a reviewer or user should expect from merging this PR.
#[default_impl]now works with dependency-carrying providers. A provider that uses#[use_type],#[uses],#[implicit], or#[use_provider]can be registered as a namespace default and will resolve correctly; previously it compiled but silently failed to route, breaking every context that joined the namespace.#[cgp_component]and the unsatisfied-dependency caret ofcheck_components!are pinned by.stderrsnapshots, so a future regression toSpan::call_site()changes a snapshot instead of silently degrading compiler and IDE navigation.cgp-compile-fail-testsdepends oncgp-test-crate-a(reflected inCargo.lock), and thenamespacestest module gainsdefault_impl_use_type, so the full workspace suite must be run to confirm the fixtures and snapshots pass.