Skip to content

stores: let #[store] methods return impl Trait - #5995

Open
nicoburns wants to merge 1 commit into
mainfrom
devin/1792781790-store-impl-trait-return
Open

nicoburns wants to merge 1 commit into
mainfrom
devin/1792781790-store-impl-trait-return

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Since #5425 every #[store] method carries a visibility witness bound, where Self: __XVisibleIn<Vis><__V>, and stores-macro/src/seal.rs emitted that witness trait private:

trait __FooStoreImplExtVisibleInPrivate<__V> {}

The extension trait it is used in is pub, which is fine for ordinary signatures (#[allow(private_bounds)]), but a method returning impl Trait has the where-bound captured by its opaque type, so rustc rejects it with E0446 "private trait in public interface":

#[store]
impl<Lens> Store<History, Lens> {
    fn current_url(&self) -> impl Readable<Target = Request> { ... } // E0446
}

Fix: emit the witness trait as pub trait. Nothing else changes: the gating relies on the marker struct (#vis struct __XMarker<Vis>;) that is the only type implementing __XVisibleIn<Vis><_> for the store, so calling a private method from another module still fails with "type __XMarkerPrivate is private" (checked with a scratch crate), and the existing visibility compile_fail tests pass.

Adds a compile-time test in packages/stores/tests/macro.rs (store_impl_returning_impl_trait) that fails with E0446 without the fix.

Found while upgrading Blitz's browser app to 0.8.0-alpha.3 (DioxusLabs/blitz#1260), where History::current_url had to be moved out of its #[store] block.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/8451be47ca9a4d89ac073c7243d2a30e
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/8451be47ca9a4d89ac073c7243d2a30e?variant=devin-insiders
Requested by: @nicoburns

The visibility witness trait that gates each #[store] method was emitted
private, so a method returning impl Trait failed with E0446 (private trait in
public interface) because the opaque type captures the where-bound. The witness
trait is now pub; access is still gated by the marker struct's visibility.
@staging-devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants