rust-lang / rust-lang/rust

mimatched type when using a `let` binding with the same name as a struct

Open
#125,402 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics C-bug D-confusing S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

use std::marker::*;

fn main() {
    let PhantomData = ();
}

I expected to see this happen: success! Or at least a better diagnostic message.

Instead, this happened: failure:

error[E0308]: mismatched types
 --> src/main.rs:4:9
  |
4 |     let PhantomData = ();
  |         ^^^^^^^^^^^   -- this expression has type `()`
  |         |
  |         expected `()`, found `PhantomData<_>`
  |
  = note: expected unit type `()`
                found struct `std::marker::PhantomData<_>`

Playground

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (791adf759 2024-05-21)
binary: rustc
commit-hash: 791adf759cc065316f054961875052d5bc03e16c
commit-date: 2024-05-21
host: x86_64-pc-windows-msvc
release: 1.80.0-nightly
LLVM version: 18.1.6

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 reproducing the PhantomData example with the provided nightly rustc version or Playground link, then trace how the let binding is interpreted when it shares a name with the struct. Done means the example either compiles as expected or produces a more accurate diagnostic than the reported mismatched-types error.

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.