Do not lint unnecessary_unwrap
in macros
This commit is contained in:
parent
536c255b43
commit
514b1bc2af
@ -1,4 +1,4 @@
|
||||
use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
|
||||
use crate::utils::{higher::if_block, in_macro, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::map::Map;
|
||||
use rustc_hir::intravisit::*;
|
||||
@ -138,6 +138,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
|
||||
type Map = Map<'tcx>;
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
// Shouldn't lint when `expr` is in macro.
|
||||
if in_macro(expr.span) {
|
||||
return;
|
||||
}
|
||||
if let Some((cond, then, els)) = if_block(&expr) {
|
||||
walk_expr(self, cond);
|
||||
self.visit_branch(cond, then, false);
|
||||
|
@ -39,4 +39,6 @@ fn main() {
|
||||
// it will always panic but the lint is not smart enough to see this (it
|
||||
// only checks if conditions).
|
||||
}
|
||||
|
||||
assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user