@@ -211,6 +211,33 @@ declare_clippy_lint! {
211211 "`pub fn` may panic without `# Panics` in doc comment"
212212}
213213
214+ declare_clippy_lint ! {
215+ /// ### What it does
216+ /// Checks the doc comments of publicly visible functions and warns if
217+ /// there is no `# Examples` section.
218+ ///
219+ /// ### Why is this bad?
220+ /// Examples help readers better understand how and why to use the function.
221+ ///
222+ /// ### Examples
223+ /// The following function has an `# Examples` section in its doc comment:
224+ ///
225+ /// ```
226+ /// /// # Examples
227+ /// ///
228+ /// /// ```
229+ /// /// assert_eq!(bikeshed_color(), "blue");
230+ /// /// ```
231+ /// pub fn bikeshed_color() -> &'static str {
232+ /// "blue"
233+ /// }
234+ /// ```
235+ #[ clippy:: version = "1.92.0" ]
236+ pub MISSING_EXAMPLES_DOC ,
237+ pedantic,
238+ "`pub fn` without `# Examples` in doc comment"
239+ }
240+
214241declare_clippy_lint ! {
215242 /// ### What it does
216243 /// Checks for `fn main() { .. }` in doctests
@@ -721,6 +748,7 @@ impl_lint_pass!(Documentation => [
721748 MISSING_SAFETY_DOC ,
722749 MISSING_ERRORS_DOC ,
723750 MISSING_PANICS_DOC ,
751+ MISSING_EXAMPLES_DOC ,
724752 NEEDLESS_DOCTEST_MAIN ,
725753 TEST_ATTR_IN_DOCTEST ,
726754 UNNECESSARY_SAFETY_DOC ,
@@ -832,10 +860,12 @@ impl Fragments<'_> {
832860}
833861
834862#[ derive( Copy , Clone , Default ) ]
863+ #[ expect( clippy:: struct_excessive_bools) ]
835864struct DocHeaders {
836865 safety : bool ,
837866 errors : bool ,
838867 panics : bool ,
868+ examples : bool ,
839869 first_paragraph_len : usize ,
840870}
841871
@@ -1282,6 +1312,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
12821312 headers. safety |= in_heading && trimmed_text == "Implementation Safety" ;
12831313 headers. errors |= in_heading && trimmed_text == "Errors" ;
12841314 headers. panics |= in_heading && trimmed_text == "Panics" ;
1315+ headers. examples |= in_heading && trimmed_text == "Examples" ;
12851316
12861317 if let Some ( tags) = code {
12871318 if tags. rust && !tags. compile_fail && !tags. ignore {
0 commit comments