Skip to content

Rustfmt breaks method call on || .. #4808

Closed
@dtolnay

Description

@dtolnay

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

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