From 0cf5ffe2e6dfbb14e7d2e8b672e15ecc3fe03ff1 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 19 Dec 2024 11:47:20 -0700 Subject: [PATCH] Hard error when more than five doctests are on one item --- src/librustdoc/doctest/rust.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/doctest/rust.rs b/src/librustdoc/doctest/rust.rs index 0903baddabebe..f2e39a26910da 100644 --- a/src/librustdoc/doctest/rust.rs +++ b/src/librustdoc/doctest/rust.rs @@ -126,6 +126,8 @@ impl HirCollector<'_> { }) .unwrap_or(DUMMY_SP) }; + // TEST(notriddle): fail if there's more than 5 tests in a single docblock + let test_count_before = self.collector.tests.len(); markdown::find_testable_code( &doc, &mut self.collector, @@ -133,6 +135,10 @@ impl HirCollector<'_> { self.enable_per_target_ignores, Some(&crate::html::markdown::ExtraInfo::new(self.tcx, def_id, span)), ); + let test_count_after = self.collector.tests.len(); + if test_count_after - test_count_before > 5 { + self.tcx.sess.dcx().fatal(format!("{def_id:?} has more than five doctests")); + } } nested(self);