Skip to content

Avoid ambiguous associated item references#646

Merged
djkoloski merged 4 commits intorkyv:mainfrom
woodruffw-forks:ww/ambiguous-associated-item
Jan 7, 2026
Merged

Avoid ambiguous associated item references#646
djkoloski merged 4 commits intorkyv:mainfrom
woodruffw-forks:ww/ambiguous-associated-item

Conversation

@woodruffw
Copy link
Copy Markdown
Contributor

Hello rkyv folks!

I noticed this while trying to derive rkyv::Archive on an enum that contains an Archived variant:

#[derive(
    Clone, Copy, Debug, Default, Eq, PartialEq, rkyv::Archive, rkyv::Deserialize, rkyv::Serialize,
)]
#[rkyv(derive(Debug))]
pub enum Status {
    #[default]
    Active,
    Archived,
    Quarantined,
    Deprecated,
}

yields the following error:

error: ambiguous associated item
   --> crates/uv-pypi-types/src/project_status.rs:14:49
    |
 14 |     Clone, Copy, Debug, Default, Eq, PartialEq, rkyv::Archive, rkyv::Deseriali...
    |                                                 ^^^^^^^^^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
note: `Archived` could refer to the variant defined here
   --> crates/uv-pypi-types/src/project_status.rs:20:5
    |
 20 |     Archived,
    |     ^^^^^^^^
note: `Archived` could also refer to the associated type defined here
   --> /Users/william/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rkyv-0.8.12/src/traits.rs:229:5
    |
229 |     type Archived: Portable;
    |     ^^^^^^^^^^^^^^^^^^^^^^^
    = note: `#[deny(ambiguous_associated_items)]` (part of `#[deny(future_incompatible)]`) on by default
    = note: this error originates in the derive macro `rkyv::Archive` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `uv-pypi-types` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

This is happening because Archive (the trait) has an associated type Archived, so Self::Archive ambiguously refers to either Archive::Archived or to ProjectStatus::Archived.

The solution to this is for the first-party to disambiguate its access. In this case that's as simple as <Self as Archive>::Archived. This PR contains that change, plus its equivalent in the derive APIs.

Note: I haven't attempted to suss out other ambiguous associated items, this is only one I happened to hit! So there are potentially others lurking.

Rust tracker: rust-lang/rust#57644

Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw
Copy link
Copy Markdown
Contributor Author

(For some background context: this is for some changes to uv that involve a new piece of metadata, which in turn needs to be given the rkyv treatment like the rest of our cacheable/serializable metadata types.)

woodruffw and others added 2 commits January 7, 2026 18:26
Co-authored-by: David Koloski <djkoloski@gmail.com>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw
Copy link
Copy Markdown
Contributor Author

Oops, missed that formatting locally. Will fix.

Signed-off-by: William Woodruff <william@astral.sh>
out: #rkyv_path::Place<Self::Archived>,
resolver: <Self as #rkyv_path::Archive>::Resolver,
out: #rkyv_path::Place<
<Self as #rkyv_path::Archive>::Archived>,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the most ideal formatting 🙂

@djkoloski djkoloski merged commit 19e06e9 into rkyv:main Jan 7, 2026
45 checks passed
@djkoloski
Copy link
Copy Markdown
Collaborator

Thanks for the PR! I try to wait at least a week between releases, so this will be in the next release in about four days.

@woodruffw
Copy link
Copy Markdown
Contributor Author

Thanks for the PR! I try to wait at least a week between releases, so this will be in the next release in about four days.

Wonderful, thanks for the fast merge!

@woodruffw woodruffw deleted the ww/ambiguous-associated-item branch January 7, 2026 23:50
@djkoloski
Copy link
Copy Markdown
Collaborator

A little late, but published now!

@woodruffw
Copy link
Copy Markdown
Contributor Author

Much appreciated!

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