Skip to content

Commit 1fd3a42

Browse files
committed
Auto merge of #44713 - zackmdavis:fn_main_in_a_comment_in_rustdoc_breaks_tests, r=QuietMisdreavus
don't let rustdoc get confused by text "fn main" in a line comment ~~~Resolves~~~ (edited) partially addresses #21299. ![rustdoc_fn_main](https://user-images.githubusercontent.com/1076988/30630993-9aeecc4a-9d97-11e7-8e56-2b973f23f683.png) r? @QuietMisdreavus
2 parents 412ac93 + 9f68d62 commit 1fd3a42

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/librustdoc/test.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,21 @@ pub fn make_test(s: &str,
348348
}
349349
}
350350
}
351-
if dont_insert_main || s.contains("fn main") {
351+
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 {
352366
prog.push_str(&everything_else);
353367
} else {
354368
prog.push_str("fn main() {\n");

0 commit comments

Comments
 (0)