rust-lang/rustfmt

Merge `.. .` tokens producing invalid syntax

已关闭

#7,011 创建于 2026年8月4日

 (5 条评论) (1 个反应) (0 位负责人)Rust (760 个派生)batch import
A-closuresC-bugI-invalid-codegood first issue

仓库指标

星标
 (4,893 个星标)
PR 合并指标
 (平均合并 67天) (30 天内合并 5 个 PR)

描述

Summary

Rustfmt produces syntactically valid, but not semantically equivalent to the original code, wrapping to parens.

There is two cases actually. In second case (field) rustfmt produces invalid syntax.

I tried to format this code:

See details in rust-analyzer/23004.

fn foo() {
    || 1.. .method();
    || 1.. .field;
}

From here on, this example is used without the function signature.

Expected behavior

I expected to see this happen, two possible options:

  1. no changes
  2. range wrappend in parens:
    || (1..).method();
    || (1..).field;
    

Actual behavior

Instead, this happened:

(|| 1..).method(); // semantically defferent: `method()` should be "method of the range"
|| 1...field;      // invalid token: `...`

Reproduction Steps

  1. rustfmt ./file-with-foo-fn-from-summary.rs

Meta

rustfmt --version:

rustfmt 1.10.0-nightly (11177f2235 2026-08-02)

贡献者指南