@@ -6,7 +6,6 @@ use rustc::lint as lint;
66use rustc:: middle:: privacy:: AccessLevels ;
77use rustc:: util:: nodemap:: DefIdSet ;
88use std:: mem;
9- use std:: fmt;
109use syntax:: ast:: NodeId ;
1110use syntax_pos:: { DUMMY_SP , Span } ;
1211use std:: ops:: Range ;
@@ -46,84 +45,14 @@ pub use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
4645mod check_code_block_syntax;
4746pub use self :: check_code_block_syntax:: CHECK_CODE_BLOCK_SYNTAX ;
4847
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.
5051#[ 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 ,
12756}
12857
12958/// The full list of passes.
@@ -141,27 +70,27 @@ pub const PASSES: &'static [Pass] = &[
14170] ;
14271
14372/// The list of passes run by default.
144- pub const DEFAULT_PASSES : & ' static [ & ' static str ] = & [
73+ pub const DEFAULT_PASSES : & [ & str ] = & [
14574 "collect-trait-impls" ,
75+ "collapse-docs" ,
76+ "unindent-comments" ,
14677 "check-private-items-doc-tests" ,
14778 "strip-hidden" ,
14879 "strip-private" ,
14980 "collect-intra-doc-links" ,
15081 "check-code-block-syntax" ,
151- "collapse-docs" ,
152- "unindent-comments" ,
15382 "propagate-doc-cfg" ,
15483] ;
15584
15685/// 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 ] = & [
15887 "collect-trait-impls" ,
88+ "collapse-docs" ,
89+ "unindent-comments" ,
15990 "check-private-items-doc-tests" ,
16091 "strip-priv-imports" ,
16192 "collect-intra-doc-links" ,
16293 "check-code-block-syntax" ,
163- "collapse-docs" ,
164- "unindent-comments" ,
16594 "propagate-doc-cfg" ,
16695] ;
16796
@@ -184,8 +113,8 @@ pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
184113}
185114
186115/// 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)
189118}
190119
191120struct Stripper < ' a > {
@@ -438,11 +367,11 @@ crate fn source_span_for_markdown_range(
438367 . span_to_snippet ( span_of_attrs ( attrs) )
439368 . ok ( ) ?;
440369
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 ( ) ;
443372
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.
446375 let mut src_lines = snippet. split_terminator ( '\n' ) ;
447376 let md_lines = markdown. split_terminator ( '\n' ) ;
448377
0 commit comments