Skip to content
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

Clarify how deref coercions interact with traits #3670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ch15-02-deref.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ initial immutable reference is the only immutable reference to that data, but
the borrowing rules don’t guarantee that. Therefore, Rust can’t make the
assumption that converting an immutable reference to a mutable reference is
possible.

### Deref Coercion and Traits

The compiler only performs deref coercion when matching traits if the trait method is
called via the dot operator (e.g `x.into()`), and not when the method is called
using 'fully-qualified' syntax (e.g `SomeType::from(&x)`).

For more information, see the [Nomicon][nomicon-coercions].

[impl-trait]: ch10-02-traits.html#implementing-a-trait-on-a-type
[tuple-structs]: ch05-01-defining-structs.html#using-tuple-structs-without-named-fields-to-create-different-types
[nomicon-coercions]: https://doc.rust-lang.org/nomicon/coercions.html