Skip to content

legacy_numeric_constants spans are a bit off, synatx error due to misssing ) #15008

Open
@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::legacy_numeric_constants

this code:

fn foo() {
    assert_eq!(0,-(i32::max_value()));
}

caused the following diagnostics:

    Checking _snippet_151 v0.1.0 (/tmp/icemaker_global_tempdir.VQhomPU3g4RT/icemaker_clippyfix_tempdir.JFZFEVyWdtjO/_snippet_151)
warning: usage of a legacy numeric method
 --> src/lib.rs:2:25
  |
2 |     assert_eq!(0,-(i32::max_value()));
  |                         ^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
  = note: requested on the command line with `--force-warn clippy::legacy-numeric-constants`
help: use the associated constant instead
  |
2 -     assert_eq!(0,-(i32::max_value()));
2 +     assert_eq!(0,-(i32::MAX);
  |

warning: `_snippet_151` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

fn foo() {
    assert_eq!(0,-(i32::MAX);
}

no longer compiled:

    Checking _snippet_151 v0.1.0 (/tmp/icemaker_global_tempdir.VQhomPU3g4RT/icemaker_clippyfix_tempdir.JFZFEVyWdtjO/_snippet_151)
error: mismatched closing delimiter: `}`
 --> src/lib.rs:2:15
  |
1 | fn foo() {
  |          - closing delimiter possibly meant for this
2 |     assert_eq!(0,-(i32::MAX);
  |               ^ unclosed delimiter
3 | }
  | ^ mismatched closing delimiter

error: could not compile `_snippet_151` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_snippet_151` (lib) due to 1 previous error

Version:

rustc 1.89.0-nightly (44f415c1d 2025-06-06)
binary: rustc
commit-hash: 44f415c1d617ebc7b931a243b7b321ef8a6ca47c
commit-date: 2025-06-06
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions