-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Rustc coerces smart pointer to unsized too eagerly #36007
Copy link
Copy link
Closed
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Full code: https://is.gd/hZ9nqK
Given a smart pointer, which only works on types implementing the trait
Baror onBartrait objects, such thatPointer<T>is allowed to coerce toPointer<Bar>, and the correspondingPartialEqimplementation :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
CoerceUnsizedimplementation lets the code build, which means that the coercion is not needed.As @Diggsey pointed out on reddit, if the
PartialEqis restricted to pointers with identical types (PartialEq for Pointer<T>), then no coercion occurs.