This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -786,6 +786,7 @@ impl IndividualTestOptions {
786786/// [`clean`]: crate::clean
787787/// [`run_merged_tests`]: crate::doctest::runner::DocTestRunner::run_merged_tests
788788/// [`generate_unique_doctest`]: crate::doctest::make::DocTestBuilder::generate_unique_doctest
789+ #[ derive( Debug ) ]
789790pub ( crate ) struct ScrapedDocTest {
790791 filename : FileName ,
791792 line : usize ,
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ impl ErrorCodes {
140140/// Controls whether a line will be hidden or shown in HTML output.
141141///
142142/// All lines are used in documentation tests.
143- enum Line < ' a > {
143+ pub ( crate ) enum Line < ' a > {
144144 Hidden ( & ' a str ) ,
145145 Shown ( Cow < ' a , str > ) ,
146146}
@@ -153,20 +153,22 @@ impl<'a> Line<'a> {
153153 }
154154 }
155155
156- fn for_code ( self ) -> Cow < ' a , str > {
156+ pub ( crate ) fn for_code ( self ) -> Cow < ' a , str > {
157157 match self {
158158 Line :: Shown ( l) => l,
159159 Line :: Hidden ( l) => Cow :: Borrowed ( l) ,
160160 }
161161 }
162162}
163163
164+ /// This function is used to handle the "hidden lines" (ie starting with `#`) in
165+ /// doctests. It also transforms `##` back into `#`.
164166// FIXME: There is a minor inconsistency here. For lines that start with ##, we
165167// have no easy way of removing a potential single space after the hashes, which
166168// is done in the single # case. This inconsistency seems okay, if non-ideal. In
167169// order to fix it we'd have to iterate to find the first non-# character, and
168170// then reallocate to remove it; which would make us return a String.
169- fn map_line ( s : & str ) -> Line < ' _ > {
171+ pub ( crate ) fn map_line ( s : & str ) -> Line < ' _ > {
170172 let trimmed = s. trim ( ) ;
171173 if trimmed. starts_with ( "##" ) {
172174 Line :: Shown ( Cow :: Owned ( s. replacen ( "##" , "#" , 1 ) ) )
Original file line number Diff line number Diff line change 11//! Validates syntax inside Rust code blocks (\`\`\`rust).
22
3+ use std:: borrow:: Cow ;
34use std:: sync:: Arc ;
45
56use rustc_data_structures:: sync:: Lock ;
@@ -43,7 +44,11 @@ fn check_rust_syntax(
4344
4445 let sm = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
4546 let dcx = DiagCtxt :: new ( Box :: new ( emitter) ) . disable_warnings ( ) ;
46- let source = dox[ code_block. code ] . to_owned ( ) ;
47+ let source = dox[ code_block. code ]
48+ . lines ( )
49+ . map ( |line| crate :: html:: markdown:: map_line ( line) . for_code ( ) )
50+ . intersperse ( Cow :: Borrowed ( "\n " ) )
51+ . collect :: < String > ( ) ;
4752 let psess = ParseSess :: with_dcx ( dcx, sm) ;
4853
4954 let edition = code_block. lang_string . edition . unwrap_or_else ( || cx. tcx . sess . edition ( ) ) ;
You can’t perform that action at this time.
0 commit comments