rust-lang / rust-lang/rust

Leverage `rustc_confusables`/`doc(alias)` for operators

Open
#159,478 1 comment 0 reactions 1 assignee View on GitHub

@shivampipalwa is already working on this.

Since Jul 28, 2026.

A-diagnostics D-lack-of-suggestion D-newcomer-roadblock D-papercut T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn main() {
    let left = vec![1, 2];
    let right = vec![3, 4];
    let _ = left + right;
    //~^ ERROR cannot add `Vec<{integer}>` to `Vec<{integer}>`
}
Current output
error[E0369]: cannot add `Vec<{integer}>` to `Vec<{integer}>`
  --> $DIR/add-two-vecs-beginner.rs:11:23
   |
LL |     let joined = left + right;
   |                  ---- ^ ----- Vec<{integer}>
   |                  |
   |                  Vec<{integer}>
   |
note: `Vec<{integer}>` does not implement `Add<Vec<{integer}>>`
  --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
   |
   = note: `Vec<{integer}>` is defined in another crate
Desired output
error[E0369]: cannot add `Vec<{integer}>` to `Vec<{integer}>`
  --> $DIR/add-two-vecs-beginner.rs:11:23
   |
LL |     let joined = left + right;
   |                  ---- ^ ----- Vec<{integer}>
   |                  |
   |                  Vec<{integer}>
   |
note: `Vec<{integer}>` does not implement `Add<Vec<{integer}>>`
  --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
   |
   = note: `Vec<{integer}>` is defined in another crate
help: to join two `Vec`s together, use `Vec::extend`
   |
LL -     let joined = left.extend(right);
LL +     let joined = left.clone;
LL +     left.extend(right);
   |
Rationale and extra context

We already use doc(alias) and rustc_confusables to provide suggestions, like when using append when the intended method should have been push. We should be using the same machinery for intrinsic operators, suggesting left.extend(right) instead of left + right.

Other cases

Rust Version
1.97
Anything else?

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.