Do not lint unnecessary_unwrap in macros

This commit is contained in:
Yuki Okushi 2020-02-04 04:01:42 +09:00
parent 536c255b43
commit 514b1bc2af
2 changed files with 7 additions and 1 deletions

View file

@ -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);

View file

@ -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
}