Different Behaviors When Using from and into with Implemented From<&mut T> #125064
Labels
C-discussion
Category: Discussion or questions that doesn't represent real issues.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Bug Description
The issue arises when attempting to convert &mut C to two different structs (A and B) using the From trait within the drop method. The behavior differs depending on whether from or into is used, leading to unexpected compiler errors.
Reproduction Code
Next, I attempt to use these implementations within a drop method. I expect that using a mutable reference should allow obtaining both A and B instances. However, this behaves differently depending on whether from or into is utilized.
The first code snippet fails to compile with the following error:
But the second code snippet compiles successfully.
I think both of the code snippets should compile successfully.
The underlying issue might stem from the From trait's specialization process. It seems that when the trait is implemented for &mut C, the compiler does not recognize it specifically as a reference, and thus expects ownership. This inconsistency between reference handling and ownership expectation could lead to the aforementioned compilation errors.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: