use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
-use crate::utils::{
- higher::if_block, in_macro_or_desugar, match_type, paths, span_lint_and_then, usage::is_potentially_mutated,
-};
+use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
use rustc::hir::intravisit::*;
use rustc::hir::*;
use syntax::source_map::Span;
///
/// **Why is this bad?** Using `if let` or `match` is more idiomatic.
///
- /// **Known problems:** Limitations of the borrow checker might make unwrap() necessary sometimes?
+ /// **Known problems:** None
///
/// **Example:**
/// ```rust
+ /// # let option = Some(0);
+ /// # fn do_something_with(_x: usize) {}
/// if option.is_some() {
/// do_something_with(option.unwrap())
/// }
/// Could be written:
///
/// ```rust
+ /// # let option = Some(0);
+ /// # fn do_something_with(_x: usize) {}
/// if let Some(value) = option {
/// do_something_with(value)
/// }
/// ```
pub UNNECESSARY_UNWRAP,
- nursery,
+ complexity,
"checks for calls of unwrap[_err]() that cannot fail"
}
///
/// **Example:**
/// ```rust
+ /// # let option = Some(0);
+ /// # fn do_something_with(_x: usize) {}
/// if option.is_none() {
/// do_something_with(option.unwrap())
/// }
///
/// This code will always panic. The if condition should probably be inverted.
pub PANICKING_UNWRAP,
- nursery,
+ correctness,
"checks for calls of unwrap[_err]() that will always fail"
}
span: Span,
fn_id: HirId,
) {
- if in_macro_or_desugar(span) {
+ if span.from_expansion() {
return;
}