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 breaks method call on || .. #4808

Closed
dtolnay opened this issue Apr 21, 2021 · 1 comment · Fixed by #5842
Closed

Rustfmt breaks method call on || .. #4808

dtolnay opened this issue Apr 21, 2021 · 1 comment · Fixed by #5842
Labels
a-chains a-closures bug Panic, non-idempotency, invalid code, etc. p-low

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 21, 2021

Describe the bug

Working input code:

trait Trait {
    fn method(&self);
}

impl<F: Fn() -> T, T> Trait for F {
    fn method(&self) {}
}

fn main() {
    || .. .method();
}

Rustfmt diff as of current master (292c0cc):

-     || .. .method();
+     || ...method();

The transformed code produced by rustfmt fails to compile.

error: unexpected token: `...`
  --> src/main.rs:10:8
   |
10 |     || ...method();
   |        ^^^
   |
help: use `..` for an exclusive range
   |
10 |     || ..method();
   |        ^^
help: or `..=` for an inclusive range
   |
10 |     || ..=method();
   |        ^^^

error[E0425]: cannot find function `method` in this scope
  --> src/main.rs:10:11
   |
10 |     || ...method();
   |           ^^^^^^ not found in this scope

To Reproduce

Run rustfmt on playground or locally. Try to compile code. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f76a649e0bd1b99cbebc46c711ca9bf5

Expected behavior

I would expect compilable output, either unchanged || .. .method() or parenthesized (|| ..).method().

Meta

  • rustfmt version: rustfmt 2.0.0-rc.2-dev (292c0cc 2021-04-20)
  • From where did you install rustfmt?: built from source
  • How do you run rustfmt: rustfmt src.rs
@dtolnay dtolnay added the bug Panic, non-idempotency, invalid code, etc. label Apr 21, 2021
@heisen-li
Copy link

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-chains a-closures bug Panic, non-idempotency, invalid code, etc. p-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants