Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
145d7fc
commit 66a83d3
Showing
6 changed files
with
63 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
use clippy_utils::diagnostics::span_lint; | ||
use clippy_utils::is_ty_param_diagnostic_item; | ||
use clippy_utils::{path_def_id, qpath_generic_tys}; | ||
use if_chain::if_chain; | ||
use rustc_hir::{self as hir, def_id::DefId, QPath}; | ||
use rustc_lint::LateContext; | ||
use rustc_span::symbol::sym; | ||
|
||
use super::OPTION_OPTION; | ||
|
||
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { | ||
if cx.tcx.is_diagnostic_item(sym::Option, def_id) && is_ty_param_diagnostic_item(cx, qpath, sym::Option).is_some() { | ||
span_lint( | ||
cx, | ||
OPTION_OPTION, | ||
hir_ty.span, | ||
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \ | ||
enum if you need to distinguish all 3 cases", | ||
); | ||
true | ||
} else { | ||
false | ||
if_chain! { | ||
if cx.tcx.is_diagnostic_item(sym::Option, def_id); | ||
if let Some(arg) = qpath_generic_tys(qpath).next(); | ||
if path_def_id(cx, arg) == Some(def_id); | ||
then { | ||
span_lint( | ||
cx, | ||
OPTION_OPTION, | ||
hir_ty.span, | ||
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \ | ||
enum if you need to distinguish all 3 cases", | ||
); | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters