missing_panics_doc: pickup expect method
This commit is contained in:
parent
1d0d686f10
commit
79f93a655a
@ -916,8 +916,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
// check for `unwrap`
|
||||
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
|
||||
// check for `unwrap` and `expect` both `Option` and `Result`
|
||||
if let Some(arglists) = method_chain_args(expr, &["unwrap"]).or(method_chain_args(expr, &["expect"])) {
|
||||
let receiver_ty = self.typeck_results.expr_ty(arglists[0].0).peel_refs();
|
||||
if is_type_diagnostic_item(self.cx, receiver_ty, sym::Option)
|
||||
|| is_type_diagnostic_item(self.cx, receiver_ty, sym::Result)
|
||||
|
31
tests/ui/doc/missing_panics_doc.rs
Normal file
31
tests/ui/doc/missing_panics_doc.rs
Normal file
@ -0,0 +1,31 @@
|
||||
#![warn(clippy::missing_panics_doc)]
|
||||
|
||||
pub fn option_unwrap<T>(v: &[T]) -> &T {
|
||||
let o: Option<&T> = v.last();
|
||||
o.unwrap()
|
||||
}
|
||||
|
||||
pub fn option_expect<T>(v: &[T]) -> &T {
|
||||
let o: Option<&T> = v.last();
|
||||
o.expect("passed an empty thing")
|
||||
}
|
||||
|
||||
pub fn result_unwrap<T>(v: &[T]) -> &T {
|
||||
let res: Result<&T, &str> = v.last().ok_or("oh noes");
|
||||
res.unwrap()
|
||||
}
|
||||
|
||||
pub fn result_expect<T>(v: &[T]) -> &T {
|
||||
let res: Result<&T, &str> = v.last().ok_or("oh noes");
|
||||
res.expect("passed an empty thing")
|
||||
}
|
||||
|
||||
pub fn last_unwrap(v: &[u32]) -> u32 {
|
||||
*v.last().unwrap()
|
||||
}
|
||||
|
||||
pub fn last_expect(v: &[u32]) -> u32 {
|
||||
*v.last().expect("passed an empty thing")
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user