Skip to content

Commit

Permalink
Clarify effect of orphan rule changes on From/Into
Browse files Browse the repository at this point in the history
Updated documentation for `std::convert` and `std::convert::From` to
reflect changes to orphan rule in Rust 1.41. It should no longer be
necessary to implement Into directly, unless targeting an older version.
  • Loading branch information
janikrabe committed Jul 15, 2020
1 parent f315c35 commit d2fe7a7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libcore/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
//! [`TryFrom<T>`][`TryFrom`] rather than [`Into<U>`][`Into`] or [`TryInto<U>`][`TryInto`],
//! as [`From`] and [`TryFrom`] provide greater flexibility and offer
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a
//! blanket implementation in the standard library. Only implement [`Into`] or [`TryInto`]
//! when a conversion to a type outside the current crate is required.
//! blanket implementation in the standard library. When targeting a version prior to Rust 1.41, it
//! may be necessary to implement [`Into`] or [`TryInto`] directly when converting to a type
//! outside the current crate.
//!
//! # Generic Implementations
//!
Expand Down Expand Up @@ -298,8 +299,10 @@ pub trait Into<T>: Sized {
/// because implementing `From` automatically provides one with an implementation of [`Into`]
/// thanks to the blanket implementation in the standard library.
///
/// Only implement [`Into`] if a conversion to a type outside the current crate is required.
/// `From` cannot do these type of conversions because of Rust's orphaning rules.
/// Only implement [`Into`] when targeting a version prior to Rust 1.41 and converting to a type
/// outside the current crate.
/// `From` was not able to do these types of conversions in earlier versions because of Rust's
/// orphaning rules.
/// See [`Into`] for more details.
///
/// Prefer using [`Into`] over using `From` when specifying trait bounds on a generic function.
Expand Down

0 comments on commit d2fe7a7

Please sign in to comment.