Skip to content

Commit 25c1ed3

Browse files
committed
Auto merge of rust-lang#7029 - ABouttefeux:master, r=Manishearth
fix `missing_panics_doc` not detecting `assert_eq!` and `assert_ne!` fixes rust-lang#6997 changelog: `missing_panics_doc` detects `assert_eq!` and `assert_ne!` --- searching for `assert_eq!` and `assert_ne!` in `FindPanicUnwrap`
2 parents d91da40 + 8e5dd4b commit 25c1ed3

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

clippy_lints/src/doc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,11 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
721721
}
722722
}
723723

724+
// check for `assert_eq` or `assert_ne`
725+
if is_expn_of(expr.span, "assert_eq").is_some() || is_expn_of(expr.span, "assert_ne").is_some() {
726+
self.panic_span = Some(expr.span);
727+
}
728+
724729
// check for `unwrap`
725730
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
726731
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();

tests/ui/missing_panics_doc.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ pub fn unreachable_and_panic() {
3333
if true { unreachable!() } else { panic!() }
3434
}
3535

36+
/// This needs to be documented
37+
pub fn assert_eq() {
38+
let x = 0;
39+
assert_eq!(x, 0);
40+
}
41+
42+
/// This needs to be documented
43+
pub fn assert_ne() {
44+
let x = 0;
45+
assert_ne!(x, 0);
46+
}
47+
3648
/// This is documented
3749
///
3850
/// # Panics
@@ -83,6 +95,26 @@ pub fn unreachable_amd_panic_documented() {
8395
if true { unreachable!() } else { panic!() }
8496
}
8597

98+
/// This is documented
99+
///
100+
/// # Panics
101+
///
102+
/// Panics if `x` is not 0.
103+
pub fn assert_eq_documented() {
104+
let x = 0;
105+
assert_eq!(x, 0);
106+
}
107+
108+
/// This is documented
109+
///
110+
/// # Panics
111+
///
112+
/// Panics if `x` is 0.
113+
pub fn assert_ne_documented() {
114+
let x = 0;
115+
assert_ne!(x, 0);
116+
}
117+
86118
/// This is okay because it is private
87119
fn unwrap_private() {
88120
let result = Err("Hi");

tests/ui/missing_panics_doc.stderr

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,37 @@ LL | if true { unreachable!() } else { panic!() }
7878
| ^^^^^^^^
7979
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8080

81-
error: aborting due to 5 previous errors
81+
error: docs for function which may panic missing `# Panics` section
82+
--> $DIR/missing_panics_doc.rs:37:1
83+
|
84+
LL | / pub fn assert_eq() {
85+
LL | | let x = 0;
86+
LL | | assert_eq!(x, 0);
87+
LL | | }
88+
| |_^
89+
|
90+
note: first possible panic found here
91+
--> $DIR/missing_panics_doc.rs:39:5
92+
|
93+
LL | assert_eq!(x, 0);
94+
| ^^^^^^^^^^^^^^^^^
95+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
96+
97+
error: docs for function which may panic missing `# Panics` section
98+
--> $DIR/missing_panics_doc.rs:43:1
99+
|
100+
LL | / pub fn assert_ne() {
101+
LL | | let x = 0;
102+
LL | | assert_ne!(x, 0);
103+
LL | | }
104+
| |_^
105+
|
106+
note: first possible panic found here
107+
--> $DIR/missing_panics_doc.rs:45:5
108+
|
109+
LL | assert_ne!(x, 0);
110+
| ^^^^^^^^^^^^^^^^^
111+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
112+
113+
error: aborting due to 7 previous errors
82114

0 commit comments

Comments
 (0)