-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding trait bound causes unrelated trait resolution to fail #115080
Comments
This is a somewhat known bug, where a |
I ended up figuring out how to work around the issue thankfully: fn try_read_from(bytes: &[u8]) -> Option<Self>
where
Self: Sized,
{
// TODO(https://github.com/rust-lang/rust/issues/115080): Inline this
// function once #115080 is resolved.
#[inline(always)]
fn try_read_from_inner<T: Sized, F: FnOnce(&MaybeValid<T>) -> bool>(
bytes: &[u8],
is_bit_valid: F,
) -> Option<T> {
let maybe_valid = MaybeValid::<T>::read_from(bytes)?;
if is_bit_valid(&maybe_valid) {
Some(unsafe { maybe_valid.assume_valid() })
} else {
None
}
}
try_read_from_inner(bytes, Self::is_bit_valid)
} The idea is that I actually remove trait information from (This fix doesn't really have an analogue in the minimized example that I provided in the original issue description, so I'm just pasting the actual fix, not a minimized version of it.) |
Yes, the "fix" is to remove any redundant where clauses that conflict with blanket impls that are known to hold, or to explicitly annotate those where clauses with the associated type bounds that would be inferred from that where clause. |
Mmmk well thanks for the background! The fix unblocks me for now. |
For the record, this sounds close (if not duplicating) to #24066. |
I ran into this issue again, but now in a more fundamental way because it appears in the definition of a trait impl rather than in a method body that I can refactor. This works fine: unsafe impl<T: Sized> TryFromBytes for MaybeUninit<T> {
fn is_bit_valid(_c: &MaybeValid<MaybeUninit<T>>) -> bool {
true
}
} However, when I add a
I haven't found a good way to minimize this, but the code is available here; just |
This example is minimized from this code. Also discussed on URLO.
I have the following code:
This code compiles fine. However, when I modify the definition of
Bar
totrait Bar: HasAssocType
, it fails:I'm surprised by this - the existing
Self: Foo
bound onfn bar
was previously sufficient to constrain<Self as HasAssocType>::Assoc == ()
, so I don't understand why further constrainingSelf: HasAssocType
would somehow cause that to no longer hold.cc @CAD97
The text was updated successfully, but these errors were encountered: