Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn main in a comment in rustdoc breaks tests #21299

Closed
aidanhs opened this issue Jan 17, 2015 · 8 comments
Closed

fn main in a comment in rustdoc breaks tests #21299

aidanhs opened this issue Jan 17, 2015 · 8 comments
Assignees
Labels
C-bug Category: This is a bug. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aidanhs
Copy link
Member

aidanhs commented Jan 17, 2015

$ cat confuse.md
```rust
// pub fn mai
```
$ rustdoc --test confuse.md

running 1 test
test _0 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

$ sed -i 's/mai/main/' confuse.md
$ rustdoc --test confuse.md

running 1 test
test _0 ... FAILED

failures:

---- _0 stdout ----
        error: main function not found
error: aborting due to previous error
thread '_0' panicked at 'Box<Any>', /home/aidanhs/Desktop/rust/rust/src/libsyntax/diagnostic.rs:144



failures:
    _0

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

thread '<unnamed>' panicked at 'Some tests failed', /home/aidanhs/Desktop/rust/rust/src/libtest/lib.rs:265
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: ()', /home/aidanhs/Desktop/rust/rust/src/libcore/result.rs:746

Per http://doc.rust-lang.org/rustdoc.html, "Given a code block, if it does not contain fn main, it is wrapped in fn main() { your_code }"

Can it not be "does not contain 'fn main (' outside of a comment"?

@aidanhs
Copy link
Member Author

aidanhs commented Jan 17, 2015

A more painful example is

```
fn main_test () {}
```

Which of course gives the same error.

@kmcallister kmcallister added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 17, 2015
@estsauver
Copy link
Contributor

Looks like it's just doing a .contains on the string looking for fn main. I'll add some tests and start on this.

@steveklabnik
Copy link
Member

Traige: still an error

@steveklabnik
Copy link
Member

Triage: no change.

@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@QuietMisdreavus
Copy link
Member

For anyone that wants to tackle this, the offending line is right here. Changing that s.contains("fn main") to some more-robust kind of scan would fix this.

@QuietMisdreavus QuietMisdreavus added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Jul 31, 2017
@QuietMisdreavus QuietMisdreavus self-assigned this Jul 31, 2017
zackmdavis added a commit to zackmdavis/rust that referenced this issue Sep 26, 2017
bors added a commit that referenced this issue Sep 27, 2017
…aks_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
@QuietMisdreavus QuietMisdreavus removed E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. WG-docs-rustdoc labels Sep 29, 2017
@QuietMisdreavus
Copy link
Member

Current status: Thanks to #44713 the exact example in the OP now doesn't break! But we'd like to make a "more complete" fix, likely by using libsyntax to properly parse tests and looking for a parsed function called "main" that way. It's probably not that cumbersome to set up if you can get a Parser rolling, but... i haven't worked with it myself, so i can't mentor that without tinkering on it myself. >_>

@repnop
Copy link
Contributor

repnop commented Oct 4, 2018

I'd like to take a stab at a proper fix for this, if that's okay!

@QuietMisdreavus
Copy link
Member

@rep-nop Feel free! If you have any questions, don't be afraid to post them here or find us on IRC or Discord (there are #rustdoc channels on both).

bors added a commit that referenced this issue Nov 4, 2018
rustdoc: Replaces fn main search and extern crate search with proper parsing during doctests.

Fixes #21299.
Fixes #33731.

Let me know if there's any additional changes you'd like made!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants