Skip to content

Commit 7d708a4

Browse files
committed
fix: needless_doctest_main panic when doctest is invalid
1 parent 4ef7529 commit 7d708a4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clippy_lints/src/doc/needless_doctest_main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ pub fn check(
105105
},
106106
Ok(None) => break,
107107
Err(e) => {
108-
e.cancel();
108+
// See issue #15041. When calling `.cancel()` on the `Diag`, Clippy will unexpectedly panic
109+
// when the `Diag` is unwinded. Meanwhile, we can just call `.emit()`, since the `DiagCtxt`
110+
// is just a sink, nothing will be printed.
111+
e.emit();
109112
return (false, test_attr_spans);
110113
},
111114
}

tests/ui/doc/needless_doctest_main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,19 @@
2020
fn foo() {}
2121

2222
fn main() {}
23+
24+
fn issue8244() -> Result<(), ()> {
25+
//! ```compile_fail
26+
//! fn test() -> Result< {}
27+
//! ```
28+
Ok(())
29+
}
30+
31+
/// # Examples
32+
///
33+
/// ```
34+
/// use std::error::Error;
35+
/// fn main() -> Result<(), Box<dyn Error>/* > */ {
36+
/// }
37+
/// ```
38+
fn issue15041() {}

0 commit comments

Comments
 (0)