Skip to content

format_code_in_doc_comments not applied when containing macros which takes an abstract stream of tokens #6454

Open
@sorairolake

Description

@sorairolake

The following doctest has no space after the comma on line 4:

/// ```
/// use time::{macros::datetime, OffsetDateTime};
///
/// assert_eq!(datetime!(1970-01-01 00:00 UTC),OffsetDateTime::UNIX_EPOCH);
/// ```

I ran cargo fmt with the format_code_in_doc_comments option set to true to format this doctest, but this doctest was not formatted.

The expected result is:

/// ```
/// use time::{macros::datetime, OffsetDateTime};
///
-/// assert_eq!(datetime!(1970-01-01 00:00 UTC),OffsetDateTime::UNIX_EPOCH);
+/// assert_eq!(datetime!(1970-01-01 00:00 UTC), OffsetDateTime::UNIX_EPOCH);
/// ```

Note that Rust code other than doctests, such as unit tests, was formatted as expected.

#[cfg(test)]
mod tests {
    use time::{macros::datetime, OffsetDateTime};

    use super::*;

    #[test]
    fn it_works() {
        assert_eq!(datetime!(1970-01-01 00:00 UTC),OffsetDateTime::UNIX_EPOCH);
    }
}

The above unit test was formatted as expected as follows:

#[cfg(test)]
mod tests {
    use time::{macros::datetime, OffsetDateTime};

    use super::*;

    #[test]
    fn it_works() {
        assert_eq!(datetime!(1970-01-01 00:00 UTC), OffsetDateTime::UNIX_EPOCH);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions