Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1c5bf1

Browse files
committed
fix(docs): remove newlines interpreted as test
When documenting mandatory arguments of a methods builder, it was possible to document 'parts', which have a long multi-line description with empty lines inbetween. This caused the indentation to be funny and tricked rustdoc into thinking these are indented doc-tests. Now we remove these empty lines, also hoping we dont encounter lines with just whitespace in them. The latter would require a tiny update of our regex.
1 parent e5b013e commit d1c5bf1

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/mako/lib/rbuild.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME,
77
build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s, mb_additional_type_params,
88
struct_type_bounds_s, METHODS_RESOURCE, SPACES_PER_TAB, prefix_all_but_first_with,
9-
METHODS_BUILDER_MARKER_TRAIT)
9+
METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines)
1010
%>\
1111
<%namespace name="util" file="util.mako"/>\
1212
<%namespace name="lib" file="lib.mako"/>\
@@ -91,7 +91,7 @@ impl${rb_params} ${ThisType} {
9191
arg_prefix = "/// * `" + p.name + "` - "
9292
%>\
9393
${arg_prefix}${p.get('description', "No description provided.")
94-
| prefix_all_but_first_with(' ' * SPACES_PER_TAB + '///' + ' ' * (len(arg_prefix) - len('///')))}
94+
| remove_empty_lines, prefix_all_but_first_with(' ' * SPACES_PER_TAB + '///' + ' ' * (len(arg_prefix) - len('///')))}
9595
% endfor
9696
% endif
9797
pub fn ${mangle_ident(a)}${type_params}(&self${method_args}) -> ${RType}${mb_tparams} {

src/mako/lib/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def unindent_inner(s):
150150
return re_linestart.sub(' ' * tabs * SPACES_PER_TAB, s)
151151
return unindent_inner
152152

153+
# filter to remove empty lines from a string
154+
def remove_empty_lines(s):
155+
return re.sub("^\n", '', s, flags=re.MULTILINE)
156+
153157
# Prepend prefix to each line but the first
154158
def prefix_all_but_first_with(prefix):
155159
def indent_inner(s):

0 commit comments

Comments
 (0)