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> {
|
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
|
||||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||||
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind {
|
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind &&
|
||||||
if let Some(suggestion) = simplify_not(self.cx, inner) {
|
!inner.span.from_expansion() &&
|
||||||
span_lint_and_sugg(
|
let Some(suggestion) = simplify_not(self.cx, inner)
|
||||||
self.cx,
|
{
|
||||||
NONMINIMAL_BOOL,
|
span_lint_and_sugg(
|
||||||
expr.span,
|
self.cx,
|
||||||
"this boolean expression can be simplified",
|
NONMINIMAL_BOOL,
|
||||||
"try",
|
expr.span,
|
||||||
suggestion,
|
"this boolean expression can be simplified",
|
||||||
Applicability::MachineApplicable,
|
"try",
|
||||||
);
|
suggestion,
|
||||||
}
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
|
@ -63,3 +63,32 @@ fn issue9428() {
|
|||||||
println!("foo");
|
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