We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 412ac93 + 9f68d62 commit 1fd3a42Copy full SHA for 1fd3a42
src/librustdoc/test.rs
@@ -348,7 +348,21 @@ pub fn make_test(s: &str,
348
}
349
350
351
- if dont_insert_main || s.contains("fn main") {
+
352
+ // FIXME (#21299): prefer libsyntax or some other actual parser over this
353
+ // best-effort ad hoc approach
354
+ let already_has_main = s.lines()
355
+ .map(|line| {
356
+ let comment = line.find("//");
357
+ if let Some(comment_begins) = comment {
358
+ &line[0..comment_begins]
359
+ } else {
360
+ line
361
+ }
362
+ })
363
+ .any(|code| code.contains("fn main"));
364
365
+ if dont_insert_main || already_has_main {
366
prog.push_str(&everything_else);
367
} else {
368
prog.push_str("fn main() {\n");
0 commit comments