about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-05-16 07:19:38 +0200
committerGitHub <noreply@github.com>2025-05-16 07:19:38 +0200
commit315296b0b991595d870019958a8ba47bb961af91 (patch)
tree055c7827782542bc6255784d90f2ad22e7787d35 /library
parent6d1875f99b2d5c1499410505f4233fbf8dbdc23b (diff)
parent4101d90818b7e5574d5366e24c995980fa2de866 (diff)
downloadrust-315296b0b991595d870019958a8ba47bb961af91.tar.gz
rust-315296b0b991595d870019958a8ba47bb961af91.zip
Rollup merge of #140791 - xizheyin:issue-140761, r=ibraheemdev
std: explain prefer `TryInto` over `TryFrom` when specifying traits bounds on generic function

Fixes #140761

This PR keeps the explanations of `Into` and `From` consistent and adds explanations for `TryInto` and `TryFrom`.

r? libs
Diffstat (limited to 'library')
-rw-r--r--library/core/src/convert/mod.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs
index e1b10e1074d..c542a28beb8 100644
--- a/library/core/src/convert/mod.rs
+++ b/library/core/src/convert/mod.rs
@@ -464,8 +464,8 @@ pub trait Into<T>: Sized {
 /// orphaning rules.
 /// See [`Into`] for more details.
 ///
-/// Prefer using [`Into`] over using `From` when specifying trait bounds on a generic function.
-/// This way, types that directly implement [`Into`] can be used as arguments as well.
+/// Prefer using [`Into`] over [`From`] when specifying trait bounds on a generic function
+/// to ensure that types that only implement [`Into`] can be used as well.
 ///
 /// The `From` trait is also very useful when performing error handling. When constructing a function
 /// 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 {
 /// standard library. For more information on this, see the
 /// documentation for [`Into`].
 ///
+/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
+/// to ensure that types that only implement [`TryInto`] can be used as well.
+///
 /// # Implementing `TryInto`
 ///
 /// This suffers the same restrictions and reasoning as implementing
@@ -636,6 +639,9 @@ pub trait TryInto<T>: Sized {
 /// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
 /// equivalent.
 ///
+/// Prefer using [`TryInto`] over [`TryFrom`] when specifying trait bounds on a generic function
+/// to ensure that types that only implement [`TryInto`] can be used as well.
+///
 /// `TryFrom<T>` can be implemented as follows:
 ///
 /// ```