mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Do not propose to simplify a not expression coming from a macro
This commit is contained in:
parent
6cebe58dfe
commit
b138bb587b
@ -495,18 +495,19 @@ struct NotSimplificationVisitor<'a, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind {
|
||||
if let Some(suggestion) = simplify_not(self.cx, inner) {
|
||||
span_lint_and_sugg(
|
||||
self.cx,
|
||||
NONMINIMAL_BOOL,
|
||||
expr.span,
|
||||
"this boolean expression can be simplified",
|
||||
"try",
|
||||
suggestion,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind &&
|
||||
!inner.span.from_expansion() &&
|
||||
let Some(suggestion) = simplify_not(self.cx, inner)
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
self.cx,
|
||||
NONMINIMAL_BOOL,
|
||||
expr.span,
|
||||
"this boolean expression can be simplified",
|
||||
"try",
|
||||
suggestion,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
|
||||
walk_expr(self, expr);
|
||||
|
@ -63,3 +63,32 @@ fn issue9428() {
|
||||
println!("foo");
|
||||
}
|
||||
}
|
||||
|
||||
fn issue_10523() {
|
||||
macro_rules! a {
|
||||
($v:expr) => {
|
||||
$v.is_some()
|
||||
};
|
||||
}
|
||||
let x: Option<u32> = None;
|
||||
if !a!(x) {}
|
||||
}
|
||||
|
||||
fn issue_10523_1() {
|
||||
macro_rules! a {
|
||||
($v:expr) => {
|
||||
!$v.is_some()
|
||||
};
|
||||
}
|
||||
let x: Option<u32> = None;
|
||||
if a!(x) {}
|
||||
}
|
||||
|
||||
fn issue_10523_2() {
|
||||
macro_rules! a {
|
||||
() => {
|
||||
!None::<u32>.is_some()
|
||||
};
|
||||
}
|
||||
if a!() {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user