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

refactor(embedded): Switch to syn for parsing doc comments #12258

Merged
merged 1 commit into from
Jun 17, 2023

Conversation

epage
Copy link
Contributor

@epage epage commented Jun 13, 2023

This is a follow up to #12245 which is working to resolve #12207

The hope is this will result in more resilient comment handling, being more consistent with rustdoc.

I also hoped for less code but syn is doing less than I had expected, requiring us to copy code over from other parts of rust. It seems every proc macro has to do this but there is no guide to it, so they all do it differently, only covering the cases they thought to test for.

See https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.E2.9C.94.20Stripping.20of.20doc-comment.20leading.20characters for some technical conversation on using syn and the gap between syn and what rustc does.

Note that this still won't support include_str!().

@rustbot
Copy link
Collaborator

rustbot commented Jun 13, 2023

r? @weihanglo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2023
The hope is this will result in more resilient comment handling, being
more consistent with rustdoc.

I also hoped for less code but `syn` is doing less than I had expected,
requiring us to copy code over from other parts of rust.  It seems every
proc macro has to do this but there is no guide to it, so they all do it
differently, only covering the cases they thought to test for.

Note that this still won't support `include_str!()`.
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have some more test cases:

  • A mix of normal and inner comment. This didn't work for the clap example
    with the regex implementation, but with syn it works. For example,
    // I am a normal comment
    //! ```cargo
    //! ...
    
  • A mix of multi single and multi-line docs. For example rustdoc allows this:
    /// ```
    /// assert!(true);
    
    /**
     * assert!(false, "you shall not pass");
     * ```
     */
  • Should we add tests for raw #[doc] attirbutes? Not really a blocker though.

src/cargo/util/toml/embedded.rs Outdated Show resolved Hide resolved
src/cargo/util/toml/embedded.rs Show resolved Hide resolved
src/cargo/util/toml/embedded.rs Show resolved Hide resolved
src/cargo/util/toml/embedded.rs Show resolved Hide resolved
@epage epage force-pushed the syn branch 2 times, most recently from d40ffa4 to bae8b9d Compare June 17, 2023 01:14
@weihanglo weihanglo added the Z-script Nightly: cargo script label Jun 17, 2023
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding those tests. Looks good to me.

@weihanglo
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 17, 2023

📌 Commit 4e0ac38 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2023
@bors
Copy link
Contributor

bors commented Jun 17, 2023

⌛ Testing commit 4e0ac38 with merge 652f608...

bors added a commit that referenced this pull request Jun 17, 2023
refactor(embedded): Switch to `syn` for parsing doc comments

This is a follow up to #12245 which is working to resolve #12207

The hope is this will result in more resilient comment handling, being more consistent with rustdoc.

I also hoped for less code but `syn` is doing less than I had expected, requiring us to copy code over from other parts of rust.  It seems every proc macro has to do this but there is no guide to it, so they all do it differently, only covering the cases they thought to test for.

Note that this still won't support `include_str!()`.
@bors
Copy link
Contributor

bors commented Jun 17, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 17, 2023
@weihanglo
Copy link
Member

Run rustup update nightly && rustup default nightly
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: update not yet available, sorry! try again later
error: toolchain 'nightly-x86_64-unknown-linux-gnu' is not installable

Spurious I guess?

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2023
@bors
Copy link
Contributor

bors commented Jun 17, 2023

⌛ Testing commit 4e0ac38 with merge a581ca2...

@bors
Copy link
Contributor

bors commented Jun 17, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing a581ca2 to master...

@bors bors merged commit a581ca2 into rust-lang:master Jun 17, 2023
@epage epage deleted the syn branch June 17, 2023 11:37
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2023
Update cargo

12 commits in 0c14026aa84ee2ec4c67460c0a18abc8519ca6b2..dead4b8740c4b6a8ed5211e37c99cf81d01c3b1c
2023-06-14 18:43:05 +0000 to 2023-06-20 20:07:17 +0000
- Convert valid feature name warning to an error. (rust-lang/cargo#12291)
- fix(embedded): Don't pollute script dir with lockfile (rust-lang/cargo#12284)
- fix: remove `-Zjobserver-per-rustc` again (rust-lang/cargo#12285)
- docs: some tweaks around `cargo test` (rust-lang/cargo#12288)
- Enable `doctest-in-workspace` by default (rust-lang/cargo#12221)
- fix(embedded): Don't auto-discover build.rs files (rust-lang/cargo#12283)
- fix(embeded): Don't pollute the scripts dir with `target/` (rust-lang/cargo#12282)
- feat: prepare for the next lockfile bump (rust-lang/cargo#12279)
- fix(embedded): Don't create an intermediate manifest (rust-lang/cargo#12268)
- refactor(embedded): Switch to `syn` for parsing doc comments (rust-lang/cargo#12258)
- fix(embedded): Align package name sanitization with cargo-new (rust-lang/cargo#12255)
- Clarify the default behavior of cargo-install. (rust-lang/cargo#12276)

r? `@ghost`
@ehuss ehuss added this to the 1.72.0 milestone Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. Z-script Nightly: cargo script
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking Issue for cargo-script RFC 3424
5 participants