@@ -6,7 +6,6 @@ use rustc::lint as lint;
6
6
use rustc:: middle:: privacy:: AccessLevels ;
7
7
use rustc:: util:: nodemap:: DefIdSet ;
8
8
use std:: mem;
9
- use std:: fmt;
10
9
use syntax:: ast:: NodeId ;
11
10
use syntax_pos:: { DUMMY_SP , Span } ;
12
11
use std:: ops:: Range ;
@@ -46,84 +45,14 @@ pub use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
46
45
mod check_code_block_syntax;
47
46
pub use self :: check_code_block_syntax:: CHECK_CODE_BLOCK_SYNTAX ;
48
47
49
- /// Represents a single pass.
48
+ /// A single pass over the cleaned documentation.
49
+ ///
50
+ /// Runs in the compiler context, so it has access to types and traits and the like.
50
51
#[ derive( Copy , Clone ) ]
51
- pub enum Pass {
52
- /// An "early pass" is run in the compiler context, and can gather information about types and
53
- /// traits and the like.
54
- EarlyPass {
55
- name : & ' static str ,
56
- pass : fn ( clean:: Crate , & DocContext < ' _ , ' _ , ' _ > ) -> clean:: Crate ,
57
- description : & ' static str ,
58
- } ,
59
- /// A "late pass" is run between crate cleaning and page generation.
60
- LatePass {
61
- name : & ' static str ,
62
- pass : fn ( clean:: Crate ) -> clean:: Crate ,
63
- description : & ' static str ,
64
- } ,
65
- }
66
-
67
- impl fmt:: Debug for Pass {
68
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
69
- let mut dbg = match * self {
70
- Pass :: EarlyPass { .. } => f. debug_struct ( "EarlyPass" ) ,
71
- Pass :: LatePass { .. } => f. debug_struct ( "LatePass" ) ,
72
- } ;
73
-
74
- dbg. field ( "name" , & self . name ( ) )
75
- . field ( "pass" , & "..." )
76
- . field ( "description" , & self . description ( ) )
77
- . finish ( )
78
- }
79
- }
80
-
81
- impl Pass {
82
- /// Constructs a new early pass.
83
- pub const fn early ( name : & ' static str ,
84
- pass : fn ( clean:: Crate , & DocContext < ' _ , ' _ , ' _ > ) -> clean:: Crate ,
85
- description : & ' static str ) -> Pass {
86
- Pass :: EarlyPass { name, pass, description }
87
- }
88
-
89
- /// Constructs a new late pass.
90
- pub const fn late ( name : & ' static str ,
91
- pass : fn ( clean:: Crate ) -> clean:: Crate ,
92
- description : & ' static str ) -> Pass {
93
- Pass :: LatePass { name, pass, description }
94
- }
95
-
96
- /// Returns the name of this pass.
97
- pub fn name ( self ) -> & ' static str {
98
- match self {
99
- Pass :: EarlyPass { name, .. } |
100
- Pass :: LatePass { name, .. } => name,
101
- }
102
- }
103
-
104
- /// Returns the description of this pass.
105
- pub fn description ( self ) -> & ' static str {
106
- match self {
107
- Pass :: EarlyPass { description, .. } |
108
- Pass :: LatePass { description, .. } => description,
109
- }
110
- }
111
-
112
- /// If this pass is an early pass, returns the pointer to its function.
113
- pub fn early_fn ( self ) -> Option < fn ( clean:: Crate , & DocContext < ' _ , ' _ , ' _ > ) -> clean:: Crate > {
114
- match self {
115
- Pass :: EarlyPass { pass, .. } => Some ( pass) ,
116
- _ => None ,
117
- }
118
- }
119
-
120
- /// If this pass is a late pass, returns the pointer to its function.
121
- pub fn late_fn ( self ) -> Option < fn ( clean:: Crate ) -> clean:: Crate > {
122
- match self {
123
- Pass :: LatePass { pass, .. } => Some ( pass) ,
124
- _ => None ,
125
- }
126
- }
52
+ pub struct Pass {
53
+ pub name : & ' static str ,
54
+ pub pass : fn ( clean:: Crate , & DocContext < ' _ , ' _ , ' _ > ) -> clean:: Crate ,
55
+ pub description : & ' static str ,
127
56
}
128
57
129
58
/// The full list of passes.
@@ -141,27 +70,27 @@ pub const PASSES: &'static [Pass] = &[
141
70
] ;
142
71
143
72
/// The list of passes run by default.
144
- pub const DEFAULT_PASSES : & ' static [ & ' static str ] = & [
73
+ pub const DEFAULT_PASSES : & [ & str ] = & [
145
74
"collect-trait-impls" ,
75
+ "collapse-docs" ,
76
+ "unindent-comments" ,
146
77
"check-private-items-doc-tests" ,
147
78
"strip-hidden" ,
148
79
"strip-private" ,
149
80
"collect-intra-doc-links" ,
150
81
"check-code-block-syntax" ,
151
- "collapse-docs" ,
152
- "unindent-comments" ,
153
82
"propagate-doc-cfg" ,
154
83
] ;
155
84
156
85
/// The list of default passes run with `--document-private-items` is passed to rustdoc.
157
- pub const DEFAULT_PRIVATE_PASSES : & ' static [ & ' static str ] = & [
86
+ pub const DEFAULT_PRIVATE_PASSES : & [ & str ] = & [
158
87
"collect-trait-impls" ,
88
+ "collapse-docs" ,
89
+ "unindent-comments" ,
159
90
"check-private-items-doc-tests" ,
160
91
"strip-priv-imports" ,
161
92
"collect-intra-doc-links" ,
162
93
"check-code-block-syntax" ,
163
- "collapse-docs" ,
164
- "unindent-comments" ,
165
94
"propagate-doc-cfg" ,
166
95
] ;
167
96
@@ -184,8 +113,8 @@ pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
184
113
}
185
114
186
115
/// If the given name matches a known pass, returns its information.
187
- pub fn find_pass ( pass_name : & str ) -> Option < Pass > {
188
- PASSES . iter ( ) . find ( |p| p. name ( ) == pass_name) . cloned ( )
116
+ pub fn find_pass ( pass_name : & str ) -> Option < & ' static Pass > {
117
+ PASSES . iter ( ) . find ( |p| p. name == pass_name)
189
118
}
190
119
191
120
struct Stripper < ' a > {
@@ -438,11 +367,11 @@ crate fn source_span_for_markdown_range(
438
367
. span_to_snippet ( span_of_attrs ( attrs) )
439
368
. ok ( ) ?;
440
369
441
- let starting_line = markdown[ ..md_range. start ] . lines ( ) . count ( ) - 1 ;
442
- let ending_line = markdown[ .. md_range. end ] . lines ( ) . count ( ) - 1 ;
370
+ let starting_line = markdown[ ..md_range. start ] . matches ( '\n' ) . count ( ) ;
371
+ let ending_line = starting_line + markdown[ md_range . start .. md_range. end ] . matches ( '\n' ) . count ( ) ;
443
372
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.
373
+ // We use `split_terminator('\n')` instead of `lines()` when counting bytes so that we treat
374
+ // CRLF and LF line endings the same way.
446
375
let mut src_lines = snippet. split_terminator ( '\n' ) ;
447
376
let md_lines = markdown. split_terminator ( '\n' ) ;
448
377
0 commit comments