Skip to content

Commit

Permalink
reword documentation and lint message
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Oct 30, 2023
1 parent 64875c2 commit 5df9856
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 7 additions & 9 deletions clippy_lints/src/methods/mod.rs
Expand Up @@ -3657,24 +3657,22 @@ declare_clippy_lint! {
}

declare_clippy_lint! {
/// Looks for one of two kinds of expressions:
/// - Calling `<T as TryInto<U>>::try_into` where `T` also implements `Into<U>`
/// - Calling `<T as TryFrom<U>>::try_from` where `T` also implements `From<U>`
/// ### What it does
/// Checks for calls to `TryInto::try_into` and `TryFrom::try_from` when their infallible counterparts
/// could be used.
///
/// ### Why is this bad?
/// In those cases, the `TryInto` and `TryFrom` trait implementation is a blanket impl which forwards
/// In those cases, the `TryInto` and `TryFrom` trait implementation is a blanket impl that forwards
/// to `Into` or `From`, which always succeeds.
/// Indeed, its associated `Error` type is the empty enum `Infallible`,
/// which is impossible to construct by nature, so the error handling that is then imposed by
/// the `Result<_, Infallible>` is unnecessary and can be avoided simply by calling `.into()` or `::from`
/// directly in the first place.
/// The returned `Result<_, Infallible>` requires error handling to get the contained value
/// even though the conversion can never fail.
///
/// ### Example
/// ```rust
/// let _: Result<i64, _> = 1i32.try_into();
/// let _: Result<i64, _> = <_>::try_from(1i32);
/// ```
/// Use instead:
/// Use `from`/`into` instead:
/// ```rust
/// let _: i64 = 1i32.into();
/// let _: i64 = <_>::from(1i32);
Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/methods/unnecessary_fallible_conversions.rs
Expand Up @@ -74,11 +74,7 @@ fn check<'tcx>(
cx,
UNNECESSARY_FALLIBLE_CONVERSIONS,
span,
match kind {
FunctionKind::TryFromFunction => "calling `TryFrom::try_from` when `From` could be used",
FunctionKind::TryIntoMethod
| FunctionKind::TryIntoFunction => "calling `TryInto::try_into` when `Into` could be used",
},
"use of a fallible conversion when an infallible one could be used",
"use",
sugg.into(),
applicability
Expand Down

0 comments on commit 5df9856

Please sign in to comment.