Skip to content

Commit 38a7db5

Browse files
authored
Unrolled build for rust-lang#140791
Rollup merge of rust-lang#140791 - xizheyin:issue-140761, r=ibraheemdev std: explain prefer `TryInto` over `TryFrom` when specifying traits bounds on generic function Fixes rust-lang#140761 This PR keeps the explanations of `Into` and `From` consistent and adds explanations for `TryInto` and `TryFrom`. r? libs
2 parents 7e19eef + 4101d90 commit 38a7db5

File tree

1 file changed

+8
-2
lines changed
  • library/core/src/convert

1 file changed

+8
-2
lines changed

library/core/src/convert/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ pub trait Into<T>: Sized {
464464
/// orphaning rules.
465465
/// See [`Into`] for more details.
466466
///
467-
/// Prefer using [`Into`] over using `From` when specifying trait bounds on a generic function.
468-
/// This way, types that directly implement [`Into`] can be used as arguments as well.
467+
/// Prefer using [`Into`] over [`From`] when specifying trait bounds on a generic function
468+
/// to ensure that types that only implement [`Into`] can be used as well.
469469
///
470470
/// The `From` trait is also very useful when performing error handling. When constructing a function
471471
/// that is capable of failing, the return type will generally be of the form `Result<T, E>`.
@@ -597,6 +597,9 @@ pub trait From<T>: Sized {
597597
/// standard library. For more information on this, see the
598598
/// documentation for [`Into`].
599599
///
600+
/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
601+
/// to ensure that types that only implement [`TryInto`] can be used as well.
602+
///
600603
/// # Implementing `TryInto`
601604
///
602605
/// This suffers the same restrictions and reasoning as implementing
@@ -636,6 +639,9 @@ pub trait TryInto<T>: Sized {
636639
/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
637640
/// equivalent.
638641
///
642+
/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
643+
/// to ensure that types that only implement [`TryInto`] can be used as well.
644+
///
639645
/// `TryFrom<T>` can be implemented as follows:
640646
///
641647
/// ```

0 commit comments

Comments
 (0)