rust-lang / rust-lang/rust

Type checking bug. Trait appears to use inferred type from bounds rather than specified associated type

Open
#129,138 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9b8e4a4b196fdb3320c694d180649731

I expected to see this happen: borrow should be known to return (), as it is specified to return an associated type that is specified just three lines earlier.

Instead, this happened: A compiler error citing an equivalent type saying it isn't known to be ().

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (6e2780775 2024-07-05)
binary: rustc
commit-hash: 6e2780775f5cea9328d37f4b8d0ee79db0056267
commit-date: 2024-07-05
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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 the linked Rust Playground reproduction on the stable or nightly compiler and compare the diagnostic with the stated expectation for the associated type. Trace the compiler's type-checking path for the trait and its bounds; done means the example recognizes the specified return type without the reported error and has a regression test.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.