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

rustfmt incorrectly fixes parens in template constraints #2630

Closed
medwards opened this issue Apr 18, 2018 · 1 comment
Closed

rustfmt incorrectly fixes parens in template constraints #2630

medwards opened this issue Apr 18, 2018 · 1 comment
Labels
bug Panic, non-idempotency, invalid code, etc. poor-formatting

Comments

@medwards
Copy link

In the following example rustfmt removes the leading parenthesis in F: (Fn(&T) -> String) but doesn't remove the closing parenthesis (but does add some spacing).

fn make_map<T, F: (Fn(&T) -> String)>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {
    records
        .iter()
        .enumerate()
        .map(|(index, record)| (key_fn(record), index))
        .collect()
}
@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. poor-formatting labels Apr 18, 2018
@topecongiro
Copy link
Contributor

The problem here is that the AST node of TyParamBound does not hold information about parenthesis in its field nor span, and rustfmt incorrectly assumes that the closing parenthesis is some kind of comments.

bors added a commit to rust-lang/rust that referenced this issue Jun 10, 2018
…r=petrochenkov

Include parens to type parameter

The motivation of this PR is to fix a bug in rustfmt (cc rust-lang/rustfmt#2630).
bors added a commit to rust-lang/rust that referenced this issue Jun 10, 2018
…r=petrochenkov

Include parens to type parameter

The motivation of this PR is to fix a bug in rustfmt (cc rust-lang/rustfmt#2630).
topecongiro added a commit to topecongiro/rustfmt that referenced this issue Jun 13, 2018
@nrc nrc closed this as completed in #2784 Jun 13, 2018
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. poor-formatting
Projects
None yet
Development

No branches or pull requests

2 participants