Skip to content

Commit 442a6e7

Browse files
committed
Strengthen documentation discouraging implementing Into over From
1 parent 3b7c0d3 commit 442a6e7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/libcore/convert.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ pub trait AsMut<T: ?Sized> {
205205
/// A value-to-value conversion that consumes the input value. The
206206
/// opposite of [`From`].
207207
///
208-
/// One should only implement [`Into`] if a conversion to a type outside the current crate is
209-
/// required. Otherwise one should always prefer implementing [`From`] over [`Into`] because
210-
/// implementing [`From`] automatically provides one with a implementation of [`Into`] thanks to
211-
/// the blanket implementation in the standard library. [`From`] cannot do these type of
212-
/// conversions because of Rust's orphaning rules.
208+
/// One should avoid implementing [`Into`] and implement [`From`] instead.
209+
/// Implementing [`From`] automatically provides one with an implementation of [`Into`]
210+
/// thanks to the blanket implementation in the standard library.
211+
///
212+
/// Prefer using [`Into`] over [`From`] when specifying trait bounds on a generic function
213+
/// to ensure that types that only implement [`Into`] can be used as well.
213214
///
214215
/// **Note: This trait must not fail**. If the conversion can fail, use [`TryInto`].
215216
///
@@ -218,7 +219,7 @@ pub trait AsMut<T: ?Sized> {
218219
/// - [`From`]`<T> for U` implies `Into<U> for T`
219220
/// - [`Into`] is reflexive, which means that `Into<T> for T` is implemented
220221
///
221-
/// # Implementing [`Into`] for conversions to external types
222+
/// # Implementing [`Into`] for conversions to external types in old versions of Rust
222223
///
223224
/// Prior to Rust 1.40, if the destination type was not part of the current crate
224225
/// then you couldn't implement [`From`] directly.
@@ -248,9 +249,6 @@ pub trait AsMut<T: ?Sized> {
248249
/// (as [`From`] does with [`Into`]). Therefore, you should always try to implement [`From`]
249250
/// and then fall back to [`Into`] if [`From`] can't be implemented.
250251
///
251-
/// Prefer using [`Into`] over [`From`] when specifying trait bounds on a generic function
252-
/// to ensure that types that only implement [`Into`] can be used as well.
253-
///
254252
/// # Examples
255253
///
256254
/// [`String`] implements [`Into`]`<`[`Vec`]`<`[`u8`]`>>`:

0 commit comments

Comments
 (0)