Skip to content

Commit 5c28cd2

Browse files
committed
Allow empty lines in lint doc examples
This makes sure that empty lines in lint examples are preserved. It also fixes the documentation for the invalid_ref lint, which was not shown because of an extra newline before the lint declaration.
1 parent d5bac82 commit 5c28cd2

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clippy_lints/src/attrs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,11 @@ declare_lint! {
9797
/// // Good (as inner attribute)
9898
/// #![inline(always)]
9999
///
100-
/// fn this_is_fine_too(..) { ... }
100+
/// fn this_is_fine(..) { ... }
101101
///
102102
/// // Good (as outer attribute)
103103
/// #[inline(always)]
104-
/// fn this_is_fine(..) { ... }
105-
///
104+
/// fn this_is_fine_too(..) { ... }
106105
/// ```
107106
declare_lint! {
108107
pub EMPTY_LINE_AFTER_OUTER_ATTR,

clippy_lints/src/invalid_ref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use utils::{match_def_path, opt_def_id, paths, span_help_and_lint};
1313
/// ```rust
1414
/// let bad_ref: &usize = std::mem::zeroed();
1515
/// ```
16-
1716
declare_lint! {
1817
pub INVALID_REF,
1918
Warn,

util/export.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def parse_lint_def(lint):
2424
last_section = None
2525

2626
for line in lint.doc:
27-
if len(line.strip()) == 0:
27+
if len(line.strip()) == 0 and not last_section.startswith("Example"):
2828
continue
2929

3030
match = re.match(lint_subheadline, line)
@@ -39,8 +39,13 @@ def parse_lint_def(lint):
3939
log.warn("Skipping comment line as it was not preceded by a heading")
4040
log.debug("in lint `%s`, line `%s`", lint.name, line)
4141

42-
lint_dict['docs'][last_section] = \
43-
(lint_dict['docs'].get(last_section, "") + "\n" + text).strip()
42+
fragment = lint_dict['docs'].get(last_section, "")
43+
if text == "\n":
44+
line = fragment + text
45+
else:
46+
line = (fragment + "\n" + text).strip()
47+
48+
lint_dict['docs'][last_section] = line
4449

4550
return lint_dict
4651

0 commit comments

Comments
 (0)