Skip to content

Commit 79f93a6

Browse files
missing_panics_doc: pickup expect method
1 parent 1d0d686 commit 79f93a6

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

clippy_lints/src/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
916916
}
917917
}
918918

919-
// check for `unwrap`
920-
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
919+
// check for `unwrap` and `expect` both `Option` and `Result`
920+
if let Some(arglists) = method_chain_args(expr, &["unwrap"]).or(method_chain_args(expr, &["expect"])) {
921921
let receiver_ty = self.typeck_results.expr_ty(arglists[0].0).peel_refs();
922922
if is_type_diagnostic_item(self.cx, receiver_ty, sym::Option)
923923
|| is_type_diagnostic_item(self.cx, receiver_ty, sym::Result)

tests/ui/doc/missing_panics_doc.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![warn(clippy::missing_panics_doc)]
2+
3+
pub fn option_unwrap<T>(v: &[T]) -> &T {
4+
let o: Option<&T> = v.last();
5+
o.unwrap()
6+
}
7+
8+
pub fn option_expect<T>(v: &[T]) -> &T {
9+
let o: Option<&T> = v.last();
10+
o.expect("passed an empty thing")
11+
}
12+
13+
pub fn result_unwrap<T>(v: &[T]) -> &T {
14+
let res: Result<&T, &str> = v.last().ok_or("oh noes");
15+
res.unwrap()
16+
}
17+
18+
pub fn result_expect<T>(v: &[T]) -> &T {
19+
let res: Result<&T, &str> = v.last().ok_or("oh noes");
20+
res.expect("passed an empty thing")
21+
}
22+
23+
pub fn last_unwrap(v: &[u32]) -> u32 {
24+
*v.last().unwrap()
25+
}
26+
27+
pub fn last_expect(v: &[u32]) -> u32 {
28+
*v.last().expect("passed an empty thing")
29+
}
30+
31+
fn main() {}

0 commit comments

Comments
 (0)