rust-lang / rust-lang/rust

Detect different borrowing in different sub-expressions the same expression and suggest borrowing when applicable

Open
#134,219 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

error[E0308]: mismatched types
    --> compiler/rustc_middle/src/ty/context.rs:3212:73
     |
3210 |         match expr.kind {
     |               --------- this expression has type `rustc_hir::ExprKind<'_>`
3211 |             hir::ExprKind::Path(qpath)
     |                                 ----- first introduced with type `rustc_hir::QPath<'_>` here
3212 |             | hir::ExprKind::Call(hir::Expr { kind: hir::ExprKind::Path(qpath), .. }, []) => {
     |                                                                         ^^^^^ expected `QPath<'_>`, found `&QPath<'_>`
     |
     = note: in the same arm, a binding must have the same type in all alternatives

The above should suggest match &expr.kind.

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 at compiler/rustc_middle/src/ty/context.rs:3212 and inspect the match over expr.kind shown in the E0308 report. Use the reported example to verify the completed behavior: the compiler suggests matching on &expr.kind when alternatives bind different borrowing levels.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.