rust-lang / rust-lang/rust

Please lint on `a.eq(b.into())` if `a.eq(b)` would work

Open
#135,201 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

In the course of investigating crater breakage, I discovered many instances of a pattern that reduces to this:

fn main() {
    let s = String::from("hello");
    assert!(s.eq("hello".into()));
}

This compiles, presumably because "hello".into() has only one possible impl that would work. It breaks if another From impl is brought into scope. For instance, cargo add bstr and add use bstr as _; to the top of that example, and it breaks.

Could we lint against this?

cc @estebank; this is in the same spirit as https://github.com/rust-lang/rust/pull/129249/ .

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 with the provided fn main example and reproduce the behavior, including adding bstr and use bstr as _;. Read the linked PR for the intended linting precedent. Done means the problematic form is diagnosed while the direct a.eq(b) form remains accepted, with regression coverage for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.