-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Rustc coerces smart pointer to unsized too eagerly #36007
Comments
Seems related to #31740 |
I've discovered a simpler reproduction: https://is.gd/0OpDXV #![feature(coerce_unsized, unsize)]
use std::marker::Unsize;
use std::ops::CoerceUnsized;
struct Foo<T: ?Sized>(Box<T>);
impl<T> CoerceUnsized<Foo<Baz>> for Foo<T> where T: Unsize<Baz> {}
struct Bar;
trait Baz {}
impl Baz for Bar {}
fn main() {
let foo = Foo(Box::new(Bar));
let foobar: Foo<Bar> = foo;
} Curiously, when you just do It also only occurs when the impl<T, U: ?Sized> CoerceUnsized<Foo<U>> for Foo<T> where T: Unsize<U> {} Likely because this |
The original code compiles with no errors today, so seems like E-needstest. |
I think I tested the wrong thing; not E-needstest. |
The linked reproduction from @abonander no longer fails to compile; is this fixed? |
This is fixed but does need a test, though I think it could also be closed without a test, since it's been open for so long there's probably already coverage 🤔 |
I think we should add the test just to be sure. |
@rustbot claim |
…, r=compiler-errors Add test for issue 36007 Fixes rust-lang#36007 r? `@compiler-errors`
Full code: https://is.gd/hZ9nqK
Given a smart pointer, which only works on types implementing the trait
Bar
or onBar
trait objects, such thatPointer<T>
is allowed to coerce toPointer<Bar>
, and the correspondingPartialEq
implementation :Applying the
==
operator on twoPointer<Foo>
will try to coerce them toPointer<Bar>
, even though this isn't needed. This is an issue since coercion moves the original pointer.Removing the
CoerceUnsized
implementation lets the code build, which means that the coercion is not needed.As @Diggsey pointed out on reddit, if the
PartialEq
is restricted to pointers with identical types (PartialEq for Pointer<T>
), then no coercion occurs.The text was updated successfully, but these errors were encountered: