use rustc_span::{sym, Span};
declare_clippy_lint! {
- /// **What it does:** Checks for functions of type Result that contain `expect()` or `unwrap()`
+ /// ### What it does
+ /// Checks for functions of type Result that contain `expect()` or `unwrap()`
///
- /// **Why is this bad?** These functions promote recoverable errors to non-recoverable errors which may be undesirable in code bases which wish to avoid panics.
+ /// ### Why is this bad?
+ /// These functions promote recoverable errors to non-recoverable errors which may be undesirable in code bases which wish to avoid panics.
///
- /// **Known problems:** This can cause false positives in functions that handle both recoverable and non recoverable errors.
+ /// ### Known problems
+ /// This can cause false positives in functions that handle both recoverable and non recoverable errors.
///
- /// **Example:**
+ /// ### Example
/// Before:
/// ```rust
/// fn divisible_by_3(i_str: String) -> Result<(), String> {
// first check if it's a method or function
if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind;
// checking if its return type is `result` or `option`
- if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type)
- || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type);
+ if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::Result)
+ || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::Option);
then {
lint_impl_body(cx, impl_item.span, impl_item);
}
// check for `expect`
if let Some(arglists) = method_chain_args(expr, &["expect"]) {
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
- if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type)
- || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type)
+ if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option)
+ || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result)
{
self.result.push(expr.span);
}
// check for `unwrap`
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
- if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type)
- || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type)
+ if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option)
+ || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result)
{
self.result.push(expr.span);
}