move collapse and unindent docs passes earlier

This commit is contained in:
Andy Russell 2019-02-20 16:20:01 -05:00
parent 7f19f161f2
commit 906ec8acce
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
6 changed files with 40 additions and 16 deletions

View file

@ -1,4 +1,5 @@
use crate::clean::{self, DocFragment, Item};
use crate::core::DocContext;
use crate::fold;
use crate::fold::{DocFolder};
use crate::passes::Pass;
@ -6,7 +7,7 @@ use crate::passes::Pass;
use std::mem::replace;
pub const COLLAPSE_DOCS: Pass =
Pass::late("collapse-docs", collapse_docs,
Pass::early("collapse-docs", collapse_docs,
"concatenates all document attributes into one document attribute");
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -26,7 +27,7 @@ impl DocFragment {
}
}
pub fn collapse_docs(krate: clean::Crate) -> clean::Crate {
pub fn collapse_docs(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {
Collapser.fold_crate(krate)
}

View file

@ -141,27 +141,27 @@ pub const PASSES: &'static [Pass] = &[
];
/// The list of passes run by default.
pub const DEFAULT_PASSES: &'static [&'static str] = &[
pub const DEFAULT_PASSES: &[&str] = &[
"collect-trait-impls",
"collapse-docs",
"unindent-comments",
"check-private-items-doc-tests",
"strip-hidden",
"strip-private",
"collect-intra-doc-links",
"check-code-block-syntax",
"collapse-docs",
"unindent-comments",
"propagate-doc-cfg",
];
/// The list of default passes run with `--document-private-items` is passed to rustdoc.
pub const DEFAULT_PRIVATE_PASSES: &'static [&'static str] = &[
pub const DEFAULT_PRIVATE_PASSES: &[&str] = &[
"collect-trait-impls",
"collapse-docs",
"unindent-comments",
"check-private-items-doc-tests",
"strip-priv-imports",
"collect-intra-doc-links",
"check-code-block-syntax",
"collapse-docs",
"unindent-comments",
"propagate-doc-cfg",
];
@ -438,11 +438,11 @@ crate fn source_span_for_markdown_range(
.span_to_snippet(span_of_attrs(attrs))
.ok()?;
let starting_line = markdown[..md_range.start].lines().count() - 1;
let ending_line = markdown[..md_range.end].lines().count() - 1;
let starting_line = markdown[..md_range.start].matches('\n').count();
let ending_line = starting_line + markdown[md_range.start..md_range.end].matches('\n').count();
// We use `split_terminator('\n')` instead of `lines()` when counting bytes so that we only
// we can treat CRLF and LF line endings the same way.
// We use `split_terminator('\n')` instead of `lines()` when counting bytes so that we treat
// CRLF and LF line endings the same way.
let mut src_lines = snippet.split_terminator('\n');
let md_lines = markdown.split_terminator('\n');

View file

@ -3,14 +3,15 @@ use std::string::String;
use std::usize;
use crate::clean::{self, DocFragment, Item};
use crate::core::DocContext;
use crate::fold::{self, DocFolder};
use crate::passes::Pass;
pub const UNINDENT_COMMENTS: Pass =
Pass::late("unindent-comments", unindent_comments,
Pass::early("unindent-comments", unindent_comments,
"removes excess indentation on comments in order for markdown to like it");
pub fn unindent_comments(krate: clean::Crate) -> clean::Crate {
pub fn unindent_comments(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {
CommentCleaner.fold_crate(krate)
}

View file

@ -105,8 +105,8 @@ LL | | /// [error]
|
= note: the link appears in this line:
[error]
^^^^^
[error]
^^^^^
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
warning: `[error1]` cannot be resolved, ignoring it...

View file

@ -0,0 +1,12 @@
// compile-pass
#![deny(private_doc_tests)]
mod foo {
/**
Does nothing, returns `()`
yadda-yadda-yadda
*/
fn foo() {}
}

View file

@ -0,0 +1,10 @@
// compile-pass
pub trait Foo {
/**
Does nothing, returns `()`
yadda-yadda-yadda
*/
fn foo() {}
}