trait implementation conflicts depending on source crate with generic_const_exprs
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
crate foo
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
pub trait KnownSize: Sized {
const N: usize = core::mem::size_of::<Self>();
}
impl<T: Sized> KnownSize for T {}
pub trait SizeIs<const N: usize> {}
impl<T: KnownSize> SizeIs<{ T::N }> for T {}
struct X(u32);
// Uncommenting either of these lines breaks due to conflict with blanket impls above
// impl KnownSize for X {}
// impl SizeIs<4> for X {}
crate bar
use foo::*;
struct X(u32);
// Uncommenting this line breaks due to conflict with blanket impl in `foo`
// impl KnownSize for X {}
// However this line works! (and is required if I want to use the `X: SizeIs<4>` impl)
impl SizeIs<4> for X {}
I expected to see this happen:
impl SizeIs<4> for X {} should work in both foo and bar, or in neither.
impl KnownSize for X {} and impl SizeIs<4> for X {} should either both work or neither work (in bar).
Meta
rustc --version --verbose:
rustc 1.76.0-nightly (6b771f6b5 2023-11-15)
binary: rustc
commit-hash: 6b771f6b5a6c8b03b6322a9c77ac77cb346148f0
commit-date: 2023-11-15
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two-crate examples with the recorded rustc 1.76.0-nightly version, comparing the coherence errors for the KnownSize and SizeIs implementations in crates foo and bar. Trace the compiler's trait implementation conflict handling for generic_const_exprs; done means the source-crate-dependent behavior is explained and the expected consistency is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100