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

wrap_comments sometimes breaks code blocks in lists #5746

Open
wackbyte opened this issue Apr 11, 2023 · 2 comments
Open

wrap_comments sometimes breaks code blocks in lists #5746

wackbyte opened this issue Apr 11, 2023 · 2 comments
Labels
a-comments a-markdown markdown formatting in doc comments only-with-option requires a non-default option value to reproduce p-low

Comments

@wackbyte
Copy link

wackbyte commented Apr 11, 2023

With rustfmt 1.5.2-nightly (88fb1b92 2023-04-10):

Input code

Snippet from some internal documentation I'm writing:

//! - References?
//!   - Unsound. See this example:
//!     ```compile_fail
//!     # use core::mem::MaybeUninit;
//!     let mut a = 0;
//!     let b = maybe_uninit_ext::new::<&mut MaybeUninit<u8>>(&mut a);
//!     *b = maybe_uninit_ext::uninit();
//!     assert_eq!(a, 0); // undefined behavior! a is uninitialized.
//!     ```
//!     Due to interior mutability, this is an issue for immutable references
//!     as well.

Actual result

//! - References?
//!   - Unsound. See this example: ```compile_fail # use core::mem::MaybeUninit;
//!     let mut a = 0; let b = maybe_uninit_ext::new::<&mut
//!     MaybeUninit<u8>>(&mut a); *b = maybe_uninit_ext::uninit(); assert_eq!(a,
//!     0); // undefined behavior! a is uninitialized. ``` Due to interior
//!     mutability, this is an issue for immutable references as well.

Expected result

The code block should be preserved.

@ytmimi
Copy link
Contributor

ytmimi commented Apr 11, 2023

Thanks for reaching out.

This is a limitation of how rustfmt handles markdown. rustfmt has an extremely basic understanding of markdown constructs like headers, lists, blockquotes, and code blocks.

Once rustfmt identifies that it's formatting a bulleted list it considers everything else to be text and is no longer searching for code blocks to format.

@ytmimi ytmimi added a-comments only-with-option requires a non-default option value to reproduce p-low labels Apr 11, 2023
@ytmimi
Copy link
Contributor

ytmimi commented Apr 11, 2023

Linking tracking issue for wrap_comments (#3347)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-markdown markdown formatting in doc comments only-with-option requires a non-default option value to reproduce p-low
Projects
None yet
Development

No branches or pull requests

2 participants