pub fn source_span_for_markdown_range(
tcx: TyCtxt<'_>,
markdown: &str,
md_range: &Range<usize>,
fragments: &[DocFragment],
) -> Option<Span>
Expand description
Attempts to match a range of bytes from parsed markdown to a Span
in the source code.
This method does not always work, because markdown bytes don’t necessarily match source bytes,
like if escapes are used in the string. In this case, it returns None
.
markdown
is typically the entire documentation for an item,
after combining fragments.
This method will return Some
only if one of the following is true:
- The doc is made entirely from sugared doc comments, which cannot contain escapes
- The doc is entirely from a single doc fragment with a string literal exactly equal to
markdown
. - The doc comes from
include_str!
- The doc includes exactly one substring matching
markdown[md_range]
which is contained in a single doc fragment.
This function is defined in the compiler so it can be used by
both rustdoc
and clippy
.