File tree 4 files changed +29
-4
lines changed
4 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -786,6 +786,7 @@ impl IndividualTestOptions {
786
786
/// [`clean`]: crate::clean
787
787
/// [`run_merged_tests`]: crate::doctest::runner::DocTestRunner::run_merged_tests
788
788
/// [`generate_unique_doctest`]: crate::doctest::make::DocTestBuilder::generate_unique_doctest
789
+ #[ derive( Debug ) ]
789
790
pub ( crate ) struct ScrapedDocTest {
790
791
filename : FileName ,
791
792
line : usize ,
Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ impl ErrorCodes {
139
139
/// Controls whether a line will be hidden or shown in HTML output.
140
140
///
141
141
/// All lines are used in documentation tests.
142
- enum Line < ' a > {
142
+ pub ( crate ) enum Line < ' a > {
143
143
Hidden ( & ' a str ) ,
144
144
Shown ( Cow < ' a , str > ) ,
145
145
}
@@ -152,20 +152,22 @@ impl<'a> Line<'a> {
152
152
}
153
153
}
154
154
155
- fn for_code ( self ) -> Cow < ' a , str > {
155
+ pub ( crate ) fn for_code ( self ) -> Cow < ' a , str > {
156
156
match self {
157
157
Line :: Shown ( l) => l,
158
158
Line :: Hidden ( l) => Cow :: Borrowed ( l) ,
159
159
}
160
160
}
161
161
}
162
162
163
+ /// This function is used to handle the "hidden lines" (ie starting with `#`) in
164
+ /// doctests. It also transforms `##` back into `#`.
163
165
// FIXME: There is a minor inconsistency here. For lines that start with ##, we
164
166
// have no easy way of removing a potential single space after the hashes, which
165
167
// is done in the single # case. This inconsistency seems okay, if non-ideal. In
166
168
// order to fix it we'd have to iterate to find the first non-# character, and
167
169
// then reallocate to remove it; which would make us return a String.
168
- fn map_line ( s : & str ) -> Line < ' _ > {
170
+ pub ( crate ) fn map_line ( s : & str ) -> Line < ' _ > {
169
171
let trimmed = s. trim ( ) ;
170
172
if trimmed. starts_with ( "##" ) {
171
173
Line :: Shown ( Cow :: Owned ( s. replacen ( "##" , "#" , 1 ) ) )
Original file line number Diff line number Diff line change 1
1
//! Validates syntax inside Rust code blocks (\`\`\`rust).
2
2
3
+ use std:: borrow:: Cow ;
3
4
use std:: sync:: Arc ;
4
5
5
6
use rustc_data_structures:: sync:: Lock ;
@@ -43,7 +44,11 @@ fn check_rust_syntax(
43
44
44
45
let sm = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
45
46
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 > ( ) ;
47
52
let psess = ParseSess :: with_dcx ( dcx, sm) ;
48
53
49
54
let edition = code_block. lang_string . edition . unwrap_or_else ( || cx. tcx . sess . edition ( ) ) ;
Original file line number Diff line number Diff line change
1
+ // This test ensures that `##` are not emitting a warning when generating
2
+ // docs with the 2024 edition (or any edition).
3
+ // Regression test for <https://github.com/rust-lang/rust/issues/136899>.
4
+
5
+ //@ check-pass
6
+ //@revisions: edition2021 edition2024
7
+ //@[edition2021] edition:2021
8
+ //@[edition2024] edition:2024
9
+
10
+ #![ deny( warnings) ]
11
+
12
+ //! Test
13
+ //!
14
+ //! ```
15
+ //! ##[allow(dead_code)]
16
+ //! println!("hello world");
17
+ //! ```
You can’t perform that action at this time.
0 commit comments