fix false positive (panic message) with assert macro using message parameter

This commit is contained in:
iobtl 2021-07-06 15:14:53 +08:00
parent 64d74df19c
commit eeefbb7617
2 changed files with 19 additions and 1 deletions

View File

@ -74,7 +74,9 @@
impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if match_panic_call(cx, expr).is_some() && is_expn_of(expr.span, "debug_assert").is_none() {
if match_panic_call(cx, expr).is_some()
&& (is_expn_of(expr.span, "debug_assert").is_none() && is_expn_of(expr.span, "assert").is_none())
{
let span = get_outer_span(expr);
if is_expn_of(expr.span, "unimplemented").is_some() {
span_lint(

View File

@ -43,6 +43,18 @@ fn core_versions() {
unreachable!();
}
fn assert() {
assert!(true);
assert_eq!(true, true);
assert_ne!(true, false);
}
fn assert_msg() {
assert!(true, "this should not panic");
assert_eq!(true, true, "this should not panic");
assert_ne!(true, false, "this should not panic");
}
fn debug_assert() {
debug_assert!(true);
debug_assert_eq!(true, true);
@ -61,4 +73,8 @@ fn main() {
unimplemented();
unreachable();
core_versions();
assert();
assert_msg();
debug_assert();
debug_assert_msg();
}