rust-lang / rust-lang/rust

Lint on (nearly) all `{integer}`/`{float}` fallback

Open
#152,589 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Note: this is currently at the phase of a lang vibe check, not an approved proposal. I personally currently think I like it, but if you're interested in working on it beware that the answer might end up being "no, we don't want a lint for that".

The integer fallback to i32 and float fallback to f64 is very important for beginner friendliness. We absolutely want a simple thing like

println!("{}", 123.456);

or

for x in 0..10 {
    println!("{}", x);
}

to compile, because we don't want to add extra friction to the "my first rust program" examples.

That said, it's not obvious that fallback is what you want in "real" code, and you'd much prefer it be unified to something the vast majority of the time. Like for i in 0..10 { a[i] = 0; } ends up constrained by the indexing, and similar. And any time something is derived from an argument or returned that unifies the integer/float type as well.

See for example #139087 where there's no type to unify with, just a trait bound, and not having the type annotation causes evolution problems.

We'll probably find some examples where it turns out that we need to allow it -- maybe x << 4 for example will need to continue to allow fallback, for example, since it's a heterogeneous RHS -- but what would people think about this general direction?

(It feels like at very least it should exist for the "I'm a popular crate who really wants to make sure I'm not broken by updates to things" group we keep talking about.)

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

No files, tests, or compiler entry points are named. Begin by reviewing the fallback examples and the discussion in #139087, then determine whether a general lint is wanted and which cases must remain allowed; the issue has no settled acceptance criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.