Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
don't let rustdoc get confused by text "fn main" in a line comment
This is in the matter of #21299.
  • Loading branch information
zackmdavis committed Sep 26, 2017
1 parent 930d3b1 commit 9f68d62
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/librustdoc/test.rs
Expand Up @@ -348,7 +348,21 @@ pub fn make_test(s: &str,
}
}
}
if dont_insert_main || s.contains("fn main") {

// FIXME (#21299): prefer libsyntax or some other actual parser over this
// best-effort ad hoc approach
let already_has_main = s.lines()
.map(|line| {
let comment = line.find("//");
if let Some(comment_begins) = comment {
&line[0..comment_begins]
} else {
line
}
})
.any(|code| code.contains("fn main"));

if dont_insert_main || already_has_main {
prog.push_str(&everything_else);
} else {
prog.push_str("fn main() {\n");
Expand Down

0 comments on commit 9f68d62

Please sign in to comment.