Skip to content

Commit 5826a04

Browse files
committed
Auto merge of #5106 - flip1995:dbg_assert_mut_async, r=oli-obk
Don't trigger [debug_assert_with_mut_call] on debug_assert!(_.await) Fixes #5105 cc #5112 changelog: Don't trigger [`debug_assert_with_mut_call`] on `debug_assert!(_.await)` and move it to nursery.
2 parents b901012 + 5ba4aa8 commit 5826a04

File tree

5 files changed

+68
-58
lines changed

5 files changed

+68
-58
lines changed

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12611261
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
12621262
LintId::of(&mut_key::MUTABLE_KEY_TYPE),
12631263
LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED),
1264-
LintId::of(&mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
12651264
LintId::of(&mutex_atomic::MUTEX_ATOMIC),
12661265
LintId::of(&needless_bool::BOOL_COMPARISON),
12671266
LintId::of(&needless_bool::NEEDLESS_BOOL),
@@ -1578,7 +1577,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15781577
LintId::of(&misc::FLOAT_CMP),
15791578
LintId::of(&misc::MODULO_ONE),
15801579
LintId::of(&mut_key::MUTABLE_KEY_TYPE),
1581-
LintId::of(&mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
15821580
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
15831581
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
15841582
LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS),
@@ -1632,6 +1630,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16321630
LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM),
16331631
LintId::of(&missing_const_for_fn::MISSING_CONST_FOR_FN),
16341632
LintId::of(&mul_add::MANUAL_MUL_ADD),
1633+
LintId::of(&mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
16351634
LintId::of(&mutex_atomic::MUTEX_INTEGER),
16361635
LintId::of(&needless_borrow::NEEDLESS_BORROW),
16371636
LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),

clippy_lints/src/mutable_debug_assertion.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use matches::matches;
44
use rustc::hir::map::Map;
55
use rustc::ty;
66
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
7-
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, StmtKind, UnOp};
7+
use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability, StmtKind, UnOp};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
1010
use rustc_span::Span;
@@ -28,7 +28,7 @@ declare_clippy_lint! {
2828
/// debug_assert!(take_a_mut_parameter(&mut 5));
2929
/// ```
3030
pub DEBUG_ASSERT_WITH_MUT_CALL,
31-
correctness,
31+
nursery,
3232
"mutable arguments in `debug_assert{,_ne,_eq}!`"
3333
}
3434

@@ -61,38 +61,38 @@ fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> O
6161
if block.stmts.len() == 1;
6262
if let StmtKind::Semi(ref matchexpr) = block.stmts[0].kind;
6363
then {
64+
// debug_assert
6465
if_chain! {
6566
if let ExprKind::Match(ref ifclause, _, _) = matchexpr.kind;
6667
if let ExprKind::DropTemps(ref droptmp) = ifclause.kind;
6768
if let ExprKind::Unary(UnOp::UnNot, ref condition) = droptmp.kind;
6869
then {
69-
// debug_assert
7070
let mut visitor = MutArgVisitor::new(cx);
7171
visitor.visit_expr(condition);
7272
return visitor.expr_span();
73-
} else {
74-
// debug_assert_{eq,ne}
75-
if_chain! {
76-
if let ExprKind::Block(ref matchblock, _) = matchexpr.kind;
77-
if let Some(ref matchheader) = matchblock.expr;
78-
if let ExprKind::Match(ref headerexpr, _, _) = matchheader.kind;
79-
if let ExprKind::Tup(ref conditions) = headerexpr.kind;
80-
if conditions.len() == 2;
81-
then {
82-
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref lhs) = conditions[0].kind {
83-
let mut visitor = MutArgVisitor::new(cx);
84-
visitor.visit_expr(lhs);
85-
if let Some(span) = visitor.expr_span() {
86-
return Some(span);
87-
}
88-
}
89-
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref rhs) = conditions[1].kind {
90-
let mut visitor = MutArgVisitor::new(cx);
91-
visitor.visit_expr(rhs);
92-
if let Some(span) = visitor.expr_span() {
93-
return Some(span);
94-
}
95-
}
73+
}
74+
}
75+
76+
// debug_assert_{eq,ne}
77+
if_chain! {
78+
if let ExprKind::Block(ref matchblock, _) = matchexpr.kind;
79+
if let Some(ref matchheader) = matchblock.expr;
80+
if let ExprKind::Match(ref headerexpr, _, _) = matchheader.kind;
81+
if let ExprKind::Tup(ref conditions) = headerexpr.kind;
82+
if conditions.len() == 2;
83+
then {
84+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref lhs) = conditions[0].kind {
85+
let mut visitor = MutArgVisitor::new(cx);
86+
visitor.visit_expr(lhs);
87+
if let Some(span) = visitor.expr_span() {
88+
return Some(span);
89+
}
90+
}
91+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref rhs) = conditions[1].kind {
92+
let mut visitor = MutArgVisitor::new(cx);
93+
visitor.visit_expr(rhs);
94+
if let Some(span) = visitor.expr_span() {
95+
return Some(span);
9696
}
9797
}
9898
}
@@ -147,6 +147,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
147147
}
148148
}
149149
},
150+
// Don't check await desugars
151+
ExprKind::Match(_, _, MatchSource::AwaitDesugar) => return,
150152
_ if !self.found => self.expr_span = Some(expr.span),
151153
_ => return,
152154
}

src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub const ALL_LINTS: [Lint; 351] = [
289289
},
290290
Lint {
291291
name: "debug_assert_with_mut_call",
292-
group: "correctness",
292+
group: "nursery",
293293
desc: "mutable arguments in `debug_assert{,_ne,_eq}!`",
294294
deprecation: None,
295295
module: "mutable_debug_assertion",

tests/ui/debug_assert_with_mut_call.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// compile-flags: --edition=2018
12
#![feature(custom_inner_attributes)]
23
#![rustfmt::skip]
4+
#![warn(clippy::debug_assert_with_mut_call)]
35
#![allow(clippy::trivially_copy_pass_by_ref, clippy::cognitive_complexity, clippy::redundant_closure_call)]
46

57
struct S;
@@ -114,11 +116,18 @@ fn misc() {
114116
})());
115117
}
116118

119+
async fn debug_await() {
120+
debug_assert!(async {
121+
true
122+
}.await);
123+
}
124+
117125
fn main() {
118126
func_non_mutable();
119127
func_mutable();
120128
method_non_mutable();
121129
method_mutable();
122130

123131
misc();
132+
debug_await();
124133
}

tests/ui/debug_assert_with_mut_call.stderr

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,169 @@
11
error: do not call a function with mutable arguments inside of `debug_assert!`
2-
--> $DIR/debug_assert_with_mut_call.rs:40:19
2+
--> $DIR/debug_assert_with_mut_call.rs:42:19
33
|
44
LL | debug_assert!(bool_mut(&mut 3));
55
| ^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[deny(clippy::debug_assert_with_mut_call)]` on by default
7+
= note: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings`
88

99
error: do not call a function with mutable arguments inside of `debug_assert!`
10-
--> $DIR/debug_assert_with_mut_call.rs:41:20
10+
--> $DIR/debug_assert_with_mut_call.rs:43:20
1111
|
1212
LL | debug_assert!(!bool_mut(&mut 3));
1313
| ^^^^^^^^^^^^^^^^
1414

1515
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
16-
--> $DIR/debug_assert_with_mut_call.rs:43:25
16+
--> $DIR/debug_assert_with_mut_call.rs:45:25
1717
|
1818
LL | debug_assert_eq!(0, u32_mut(&mut 3));
1919
| ^^^^^^^^^^^^^^^
2020

2121
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
22-
--> $DIR/debug_assert_with_mut_call.rs:44:22
22+
--> $DIR/debug_assert_with_mut_call.rs:46:22
2323
|
2424
LL | debug_assert_eq!(u32_mut(&mut 3), 0);
2525
| ^^^^^^^^^^^^^^^
2626

2727
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
28-
--> $DIR/debug_assert_with_mut_call.rs:46:25
28+
--> $DIR/debug_assert_with_mut_call.rs:48:25
2929
|
3030
LL | debug_assert_ne!(1, u32_mut(&mut 3));
3131
| ^^^^^^^^^^^^^^^
3232

3333
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
34-
--> $DIR/debug_assert_with_mut_call.rs:47:22
34+
--> $DIR/debug_assert_with_mut_call.rs:49:22
3535
|
3636
LL | debug_assert_ne!(u32_mut(&mut 3), 1);
3737
| ^^^^^^^^^^^^^^^
3838

3939
error: do not call a function with mutable arguments inside of `debug_assert!`
40-
--> $DIR/debug_assert_with_mut_call.rs:62:19
40+
--> $DIR/debug_assert_with_mut_call.rs:64:19
4141
|
4242
LL | debug_assert!(S.bool_self_mut());
4343
| ^^^^^^^^^^^^^^^^^
4444

4545
error: do not call a function with mutable arguments inside of `debug_assert!`
46-
--> $DIR/debug_assert_with_mut_call.rs:63:20
46+
--> $DIR/debug_assert_with_mut_call.rs:65:20
4747
|
4848
LL | debug_assert!(!S.bool_self_mut());
4949
| ^^^^^^^^^^^^^^^^^
5050

5151
error: do not call a function with mutable arguments inside of `debug_assert!`
52-
--> $DIR/debug_assert_with_mut_call.rs:64:19
52+
--> $DIR/debug_assert_with_mut_call.rs:66:19
5353
|
5454
LL | debug_assert!(S.bool_self_ref_arg_mut(&mut 3));
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5656

5757
error: do not call a function with mutable arguments inside of `debug_assert!`
58-
--> $DIR/debug_assert_with_mut_call.rs:65:19
58+
--> $DIR/debug_assert_with_mut_call.rs:67:19
5959
|
6060
LL | debug_assert!(S.bool_self_mut_arg_ref(&3));
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6262

6363
error: do not call a function with mutable arguments inside of `debug_assert!`
64-
--> $DIR/debug_assert_with_mut_call.rs:66:19
64+
--> $DIR/debug_assert_with_mut_call.rs:68:19
6565
|
6666
LL | debug_assert!(S.bool_self_mut_arg_mut(&mut 3));
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6868

6969
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
70-
--> $DIR/debug_assert_with_mut_call.rs:68:22
70+
--> $DIR/debug_assert_with_mut_call.rs:70:22
7171
|
7272
LL | debug_assert_eq!(S.u32_self_mut(), 0);
7373
| ^^^^^^^^^^^^^^^^
7474

7575
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
76-
--> $DIR/debug_assert_with_mut_call.rs:69:22
76+
--> $DIR/debug_assert_with_mut_call.rs:71:22
7777
|
7878
LL | debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0);
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
8080

8181
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
82-
--> $DIR/debug_assert_with_mut_call.rs:70:22
82+
--> $DIR/debug_assert_with_mut_call.rs:72:22
8383
|
8484
LL | debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0);
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8686

8787
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
88-
--> $DIR/debug_assert_with_mut_call.rs:71:22
88+
--> $DIR/debug_assert_with_mut_call.rs:73:22
8989
|
9090
LL | debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0);
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9292

9393
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
94-
--> $DIR/debug_assert_with_mut_call.rs:73:22
94+
--> $DIR/debug_assert_with_mut_call.rs:75:22
9595
|
9696
LL | debug_assert_ne!(S.u32_self_mut(), 1);
9797
| ^^^^^^^^^^^^^^^^
9898

9999
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
100-
--> $DIR/debug_assert_with_mut_call.rs:74:22
100+
--> $DIR/debug_assert_with_mut_call.rs:76:22
101101
|
102102
LL | debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1);
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
104104

105105
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
106-
--> $DIR/debug_assert_with_mut_call.rs:75:22
106+
--> $DIR/debug_assert_with_mut_call.rs:77:22
107107
|
108108
LL | debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1);
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110110

111111
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
112-
--> $DIR/debug_assert_with_mut_call.rs:76:22
112+
--> $DIR/debug_assert_with_mut_call.rs:78:22
113113
|
114114
LL | debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1);
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116116

117117
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
118-
--> $DIR/debug_assert_with_mut_call.rs:84:22
118+
--> $DIR/debug_assert_with_mut_call.rs:86:22
119119
|
120120
LL | debug_assert_eq!(v.pop(), Some(1));
121121
| ^^^^^^^
122122

123123
error: do not call a function with mutable arguments inside of `debug_assert_ne!`
124-
--> $DIR/debug_assert_with_mut_call.rs:85:31
124+
--> $DIR/debug_assert_with_mut_call.rs:87:31
125125
|
126126
LL | debug_assert_ne!(Some(3), v.pop());
127127
| ^^^^^^^
128128

129129
error: do not call a function with mutable arguments inside of `debug_assert!`
130-
--> $DIR/debug_assert_with_mut_call.rs:88:19
130+
--> $DIR/debug_assert_with_mut_call.rs:90:19
131131
|
132132
LL | debug_assert!(bool_mut(a));
133133
| ^^^^^^^^^^^
134134

135135
error: do not call a function with mutable arguments inside of `debug_assert!`
136-
--> $DIR/debug_assert_with_mut_call.rs:91:31
136+
--> $DIR/debug_assert_with_mut_call.rs:93:31
137137
|
138138
LL | debug_assert!(!(bool_ref(&u32_mut(&mut 3))));
139139
| ^^^^^^^^^^^^^^^
140140

141141
error: do not call a function with mutable arguments inside of `debug_assert_eq!`
142-
--> $DIR/debug_assert_with_mut_call.rs:94:22
142+
--> $DIR/debug_assert_with_mut_call.rs:96:22
143143
|
144144
LL | debug_assert_eq!(v.pop().unwrap(), 3);
145145
| ^^^^^^^
146146

147147
error: do not call a function with mutable arguments inside of `debug_assert!`
148-
--> $DIR/debug_assert_with_mut_call.rs:98:19
148+
--> $DIR/debug_assert_with_mut_call.rs:100:19
149149
|
150150
LL | debug_assert!(bool_mut(&mut 3), "w/o format");
151151
| ^^^^^^^^^^^^^^^^
152152

153153
error: do not call a function with mutable arguments inside of `debug_assert!`
154-
--> $DIR/debug_assert_with_mut_call.rs:100:19
154+
--> $DIR/debug_assert_with_mut_call.rs:102:19
155155
|
156156
LL | debug_assert!(bool_mut(&mut 3), "{} format", "w/");
157157
| ^^^^^^^^^^^^^^^^
158158

159159
error: do not call a function with mutable arguments inside of `debug_assert!`
160-
--> $DIR/debug_assert_with_mut_call.rs:105:9
160+
--> $DIR/debug_assert_with_mut_call.rs:107:9
161161
|
162162
LL | bool_mut(&mut x);
163163
| ^^^^^^^^^^^^^^^^
164164

165165
error: do not call a function with mutable arguments inside of `debug_assert!`
166-
--> $DIR/debug_assert_with_mut_call.rs:112:9
166+
--> $DIR/debug_assert_with_mut_call.rs:114:9
167167
|
168168
LL | bool_mut(&mut x);
169169
| ^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)