Skip to content

Documentation code is not formatted when format_code_in_doc_comments is enabled. #3751

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

Closed
olson-sean-k opened this issue Aug 20, 2019 · 3 comments · Fixed by #3818
Closed
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@olson-sean-k
Copy link
Contributor

I'm using nightly build 1.4.4-nightly (0462008 2019-08-06) of rustfmt with the following rustfmt.toml:

control_brace_style = "ClosingNextLine"
format_code_in_doc_comments = true

When invoked with cargo +nightly fmt using this configuration, rustfmt does not format code in documentation comments. This doesn't seem to agree with the documentation for the format_code_in_doc_comments setting. Could this be a bug?

@olson-sean-k olson-sean-k changed the title rustfmt does not format documentation code when format_code_in_doc_comments is enabled. Documentation code is not formatted when format_code_in_doc_comments is enabled. Aug 20, 2019
@topecongiro
Copy link
Contributor

Thank you for reporting an issue. Would you mind providing us with some examples? That would be helpful to track down the bug.

@topecongiro topecongiro added the only-with-option requires a non-default option value to reproduce label Aug 21, 2019
@olson-sean-k
Copy link
Contributor Author

This happens against this repository at this commit. If I intentionally "scramble" the examples, rustfmt does not reformat them as expected.

For example, this altered comment (originally from here) is left unchanged after running cargo +nightly fmt:

//! # Examples
//!
//! Indexing data for a cube to create raw buffers and a `MeshBuffer`:
//!
//! ```rust
//! # extern crate decorum;
//! # extern crate nalgebra;
//! # extern crate plexus;
//! #
//! use nalgebra::Point3;
//! use plexus::buffer::MeshBuffer3;
//! use plexus::index::{Flat3, HashIndexer};
//! use plexus::prelude::*;
//! use plexus::primitive::cube::Cube;
//! use plexus::primitive::generate::Position;
//! use decorum::N64;
//!
//! # fn main() {
//! let (indices,     positions) = Cube::new().polygons::<Position<Point3<N64>>>()
//!
//! .triangulate()
//!     .index_vertices::<Flat3, _>(HashIndexer::default())
//! ;
//! let buffer = 
//! MeshBuffer3::<u32, _>::
//! from_raw_buffers(indices, positions).unwrap();
//! # }
//! ```

I noticed this when I wrote some new documentation code. I expected rustfmt to make some changes but nothing happened. When I intentionally introduced formatting errors it still did nothing.

@topecongiro
Copy link
Contributor

Thanks! It looks like rustfmt fails to format the doc comment when it contains a line with # but without any content. A minimal working example:

//! ```rust
//! #
//! # fn main() {
//!  foo ( )  ;
//! # }
//! ```

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Aug 22, 2019
olson-sean-k added a commit to olson-sean-k/theon that referenced this issue Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants