Skip to content

Conversation

@topecongiro
Copy link
Contributor

format_code_block formats the given code_snippet by enclosing it inside
fn main block. Previously we did not add indentation to the code_snippet
before formatting it. This works fine as long as we can format the given
code_snippet, but when the code block has unformattable macro, they gets
unindented. This PR fixes it by adding proper indentation before formatting
the code_snippet.

For example, when formatting the following code block,

some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});

previously we enclosed it like this:

fn main() {
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
}

with this PR, we will enclose it like this:

fn main() {
    some_macro!(pub fn foo() {
        println!("Don't unindent me!");
    });
}

Closes #2523.

`format_code_block` formats the given `code_snippet` by enclosing it inside
`fn main` block. Previously we did not add indentation to the `code_snippet`
before formatting it. This works fine as long as we can format the given
`code_snippet`, but when the code block has unformattable macro, they gets
unindented. This commit fixes it by adding proper indentation before formatting
the `code_snippet`.

For example, when formatting the following code block,

```rust
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
```

previously we enclosed it like this:

```rust
fn main() {
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
}
```

with this PR, we will enclose it like this:

```rust
fn main() {
    some_macro!(pub fn foo() {
        println!("Don't unindent me!");
    });
}
```

Closes rust-lang#2523.
@topecongiro topecongiro changed the title Issue 2523 Do not unindent code block in comments with unformattable macro Mar 9, 2018
@nrc nrc merged commit af5d3cc into rust-lang:master Mar 11, 2018
@nrc
Copy link
Member

nrc commented Mar 11, 2018

Thank you!

@topecongiro topecongiro deleted the issue-2523 branch July 21, 2019 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removes indentation from documentation code blocks when normalize_commets = true

2 participants