-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustdoc: look for comments when scraping attributes/crates from doctests #56793
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @rust-lang/rustdoc |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustdoc/test.rs
Outdated
trimline.chars().all(|c| c.is_whitespace()) || | ||
(trimline.starts_with("//") && !trimline.starts_with("///")) | ||
{ | ||
state = PartitionState::Attrs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead if setting the value everytime, why not going into a more functional way? Like:
state = if trimline.starts_with("#![") ||
trimline.chars().all(|c| c.is_whitespace()) ||
(trimline.starts_with("//") && !trimline.starts_with("///"))
{
PartitionState::Attrs
} else if trimline.starts_with("extern crate") ||
trimline.starts_with("#[macro_use] extern crate")
{
PartitionState::Crates
} else {
PartitionState::Other
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems no different to me, but i'll make the change when i fix the tests.
src/librustdoc/test.rs
Outdated
trimline.chars().all(|c| c.is_whitespace()) || | ||
(trimline.starts_with("//") && !trimline.starts_with("///")) | ||
{ | ||
state = PartitionState::Crates; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
// https://github.com/rust-lang/rust/issues/56727 | ||
|
||
//! ``` | ||
//! // crate: proc-macro-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment. What is it for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to copy the reduced example in #56727 as closely as i could without actually bringing in the stm32f30x
crate. The comment is important because that's what breaks the parser right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see.
dc409fc
to
8faaef6
Compare
Updated. |
Thanks! @bors: r+ |
📌 Commit 8faaef6 has been approved by |
…GuillaumeGomez rustdoc: look for comments when scraping attributes/crates from doctests Fixes rust-lang#56727 When scraping out crate-level attributes and `extern crate` statements, we wouldn't look for comments, so any presence of comments would shunt it and everything after it into "everything else". This could cause parsing issues when looking for `fn main` and `extern crate my_crate` later on, which would in turn cause rustdoc to incorrectly wrap a test with `fn main` when it already had one declared. I took the opportunity to clean up the logic a little bit, but it would still benefit from a libsyntax-based loop like the `fn main` detection.
Rollup of 20 pull requests Successful merges: - #53506 (Documentation for impl From for AtomicBool and other Atomic types) - #56343 (Remove not used mod) - #56439 (Clearer error message for dead assign) - #56640 (Add FreeBSD unsigned char platforms to std::os::raw) - #56648 (Fix BTreeMap UB) - #56672 (Document time of back operations of a Linked List) - #56706 (Make `const unsafe fn` bodies `unsafe`) - #56742 (infer: remove Box from a returned Iterator) - #56761 (Suggest using `.display()` when trying to print a `Path`) - #56781 (Update LLVM submodule) - #56789 (rustc: Add an unstable `simd_select_bitmask` intrinsic) - #56790 (Make RValue::Discriminant a normal Shallow read) - #56793 (rustdoc: look for comments when scraping attributes/crates from doctests) - #56826 (rustc: Add the `cmpxchg16b` target feature on x86/x86_64) - #56832 (std: Use `rustc_demangle` from crates.io) - #56844 (Improve CSS rule) - #56850 (Fixed issue with using `Self` ctor in typedefs) - #56855 (Remove u8 cttz hack) - #56857 (Fix a small mistake regarding NaNs in a deprecation message) - #56858 (Fix doc of `std::fs::canonicalize`) Failed merges: - #56741 (treat ref-to-raw cast like a reborrow: do a special kind of retag) r? @ghost
Nominating for backporting to stable if a point release to 1.32.0 happens for another reason, see #57767. Probably not worth backporting and releasing on its own. This fix is in 1.33.0-beta.1 so 🤷♀️ |
I don't know how common that issue is, but since it's happening to the Book, it's probably worth considering. I'm willing to sign off on the backport, but this is my PR, so i'd rather someone else from @rust-lang/rustdoc be the one to add the label. (But i also feel the same that it's probably not worth including unless there are other things that need a stable backport.) |
Adding the |
Fixes #56727
When scraping out crate-level attributes and
extern crate
statements, we wouldn't look for comments, so any presence of comments would shunt it and everything after it into "everything else". This could cause parsing issues when looking forfn main
andextern crate my_crate
later on, which would in turn cause rustdoc to incorrectly wrap a test withfn main
when it already had one declared.I took the opportunity to clean up the logic a little bit, but it would still benefit from a libsyntax-based loop like the
fn main
detection.