rust-lang / rust-lang/rust-clippy

Incorrect `just_underscores_and_digits` warning for this broken code

Open
#9,724 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

With this erroneous code, Clippy says "consider choosing a more descriptive name" while pointing at a part of my program that isn't a name.

Lint Name

just_underscores_and_digits

Reproducer

I tried running clippy-driver on this code:

fn _id(r: u32 -> u32) {
    r
}

fn main(){}

I saw this happen:

error: expected parameter name, found `->`
 --> uxn.rs:1:15
  |
1 | fn _id(r: u32 -> u32) {
  |               ^^ expected parameter name

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `->`
 --> uxn.rs:1:15
  |
1 | fn _id(r: u32 -> u32) {
  |              -^^ expected one of 7 possible tokens
  |              |
  |              help: missing `,`

warning: consider choosing a more descriptive name
 --> uxn.rs:1:11
  |
1 | fn _id(r: u32 -> u32) {
  |           ^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits
  = note: `#[warn(clippy::just_underscores_and_digits)]` on by default

error[E0308]: mismatched types
 --> uxn.rs:2:5
  |
1 | fn _id(r: u32 -> u32) {
  |                       - help: try adding a return type: `-> u32`
2 |     r
  |     ^ expected `()`, found `u32`

error: aborting due to 3 previous errors; 1 warning emitted

I expected to see this happen:

"warning: consider choosing a more descriptive name" should not appear for this input. (Syntax errors are expected.)

Version
rustc 1.66.0-nightly (bed4ad65b 2022-10-25)
binary: rustc
commit-hash: bed4ad65bf7a1cef39e3d66b3670189581b3b073
commit-date: 2022-10-25
host: x86_64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running clippy-driver on the Rust reproducer for the just_underscores_and_digits lint and inspect the lint's handling of syntax-error spans. The fix is complete when this broken input still reports its syntax errors but no longer emits the descriptive-name warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.