Skip to content

Commit 906ec8a

Browse files
committed
move collapse and unindent docs passes earlier
1 parent 7f19f16 commit 906ec8a

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

src/librustdoc/passes/collapse_docs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use crate::clean::{self, DocFragment, Item};
2+
use crate::core::DocContext;
23
use crate::fold;
34
use crate::fold::{DocFolder};
45
use crate::passes::Pass;
56

67
use std::mem::replace;
78

89
pub const COLLAPSE_DOCS: Pass =
9-
Pass::late("collapse-docs", collapse_docs,
10+
Pass::early("collapse-docs", collapse_docs,
1011
"concatenates all document attributes into one document attribute");
1112

1213
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -26,7 +27,7 @@ impl DocFragment {
2627
}
2728
}
2829

29-
pub fn collapse_docs(krate: clean::Crate) -> clean::Crate {
30+
pub fn collapse_docs(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {
3031
Collapser.fold_crate(krate)
3132
}
3233

src/librustdoc/passes/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,27 @@ pub const PASSES: &'static [Pass] = &[
141141
];
142142

143143
/// The list of passes run by default.
144-
pub const DEFAULT_PASSES: &'static [&'static str] = &[
144+
pub const DEFAULT_PASSES: &[&str] = &[
145145
"collect-trait-impls",
146+
"collapse-docs",
147+
"unindent-comments",
146148
"check-private-items-doc-tests",
147149
"strip-hidden",
148150
"strip-private",
149151
"collect-intra-doc-links",
150152
"check-code-block-syntax",
151-
"collapse-docs",
152-
"unindent-comments",
153153
"propagate-doc-cfg",
154154
];
155155

156156
/// The list of default passes run with `--document-private-items` is passed to rustdoc.
157-
pub const DEFAULT_PRIVATE_PASSES: &'static [&'static str] = &[
157+
pub const DEFAULT_PRIVATE_PASSES: &[&str] = &[
158158
"collect-trait-impls",
159+
"collapse-docs",
160+
"unindent-comments",
159161
"check-private-items-doc-tests",
160162
"strip-priv-imports",
161163
"collect-intra-doc-links",
162164
"check-code-block-syntax",
163-
"collapse-docs",
164-
"unindent-comments",
165165
"propagate-doc-cfg",
166166
];
167167

@@ -438,11 +438,11 @@ crate fn source_span_for_markdown_range(
438438
.span_to_snippet(span_of_attrs(attrs))
439439
.ok()?;
440440

441-
let starting_line = markdown[..md_range.start].lines().count() - 1;
442-
let ending_line = markdown[..md_range.end].lines().count() - 1;
441+
let starting_line = markdown[..md_range.start].matches('\n').count();
442+
let ending_line = starting_line + markdown[md_range.start..md_range.end].matches('\n').count();
443443

444-
// We use `split_terminator('\n')` instead of `lines()` when counting bytes so that we only
445-
// we can treat CRLF and LF line endings the same way.
444+
// We use `split_terminator('\n')` instead of `lines()` when counting bytes so that we treat
445+
// CRLF and LF line endings the same way.
446446
let mut src_lines = snippet.split_terminator('\n');
447447
let md_lines = markdown.split_terminator('\n');
448448

src/librustdoc/passes/unindent_comments.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use std::string::String;
33
use std::usize;
44

55
use crate::clean::{self, DocFragment, Item};
6+
use crate::core::DocContext;
67
use crate::fold::{self, DocFolder};
78
use crate::passes::Pass;
89

910
pub const UNINDENT_COMMENTS: Pass =
10-
Pass::late("unindent-comments", unindent_comments,
11+
Pass::early("unindent-comments", unindent_comments,
1112
"removes excess indentation on comments in order for markdown to like it");
1213

13-
pub fn unindent_comments(krate: clean::Crate) -> clean::Crate {
14+
pub fn unindent_comments(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {
1415
CommentCleaner.fold_crate(krate)
1516
}
1617

src/test/rustdoc-ui/intra-links-warning.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ LL | | /// [error]
105105
|
106106
= note: the link appears in this line:
107107

108-
[error]
109-
^^^^^
108+
[error]
109+
^^^^^
110110
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
111111

112112
warning: `[error1]` cannot be resolved, ignoring it...

src/test/rustdoc-ui/issue-58473-2.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-pass
2+
3+
#![deny(private_doc_tests)]
4+
5+
mod foo {
6+
/**
7+
Does nothing, returns `()`
8+
9+
yadda-yadda-yadda
10+
*/
11+
fn foo() {}
12+
}

src/test/rustdoc-ui/issue-58473.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-pass
2+
3+
pub trait Foo {
4+
/**
5+
Does nothing, returns `()`
6+
7+
yadda-yadda-yadda
8+
*/
9+
fn foo() {}
10+
}

0 commit comments

Comments
 (0)