Skip to content

Commit 3cc0ae7

Browse files
committed
Format and comment code
1 parent 5f4c836 commit 3cc0ae7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clippy_lints/src/methods/err_expect.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ pub(super) fn check(
1919
) {
2020
if_chain! {
2121
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
22+
// Test the version to make sure the lint can be showed (expect_err has been introduced in rust 1.17.0 : https://github.com/rust-lang/rust/pull/38982)
2223
if meets_msrv(msrv, &msrvs::EXPECT_ERR);
2324

25+
// Grabs the `Result<T, E>` type
2426
let result_type = cx.typeck_results().expr_ty(recv);
27+
// Tests if the T type in a `Result<T, E>` is not None
2528
if let Some(data_type) = get_data_type(cx, result_type);
29+
// Tests if the T type in a `Result<T, E>` implements debug
2630
if has_debug_impl(data_type, cx);
2731

2832
then {
@@ -42,11 +46,12 @@ pub(super) fn check(
4246
/// Given a `Result<T, E>` type, return its data (`T`).
4347
fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
4448
match ty.kind() {
45-
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().nth(0),
49+
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().next(),
4650
_ => None,
4751
}
4852
}
4953

54+
/// Givn a type, very if the Debug trait has been impl'd
5055
fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
5156
cx.tcx
5257
.get_diagnostic_item(sym::Debug)

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ declare_clippy_lint! {
368368
/// Checks for `.err().expect()` calls on the `Result` type.
369369
///
370370
/// ### Why is this bad?
371-
/// Because .expect_err() can be called directly.
371+
/// `.expect_err()` can be called directly to avoid the extra type conversion from `ok()`.
372372
///
373373
/// ### Example
374374
/// ```should_panic

0 commit comments

Comments
 (0)