Skip to main content

## source_span_for_markdown_range

# Function source_span_for_markdown_range

Source

    pub fn source_span_for_markdown_range(
        tcx: TyCtxt<'_>,
        markdown: &str,
        md_range: &Range<usize>,
        fragments: &[DocFragment],
    ) -> Option<(Span, bool)>

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`.

It returns a tuple containing a span encompassing all the document fragments and a boolean that is `true` if any of the matched fragments are from a macro expansion.