rust-lang / rust-lang/rust

expectations from fudging are a mess

Open
#149,379 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-technical-debt C-cleanup T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

At its core we use fudging for the following pattern

fn foo<T>(x: T) -> Box<T> { Box::new(x) }
fn main() {
    let _: Box<dyn Fn(&str) -> usize> = foo(|s| s.len());
}

We end up with the expectation that foos argument is dyn Fn(&str) -> usize even though that type is not Sized. This is why fudge_inference_if_ok exists and why it's used for function calls when checkig their arguments.

We try to deal with this by weakening the expectation in case it's not sized

https://github.com/rust-lang/rust/blob/7b9905edb4df3aeaabd0d6cd0d4c09b183d7d965/compiler/rustc_hir_typeck/src/expectation.rs#L77-L89

This is widely insufficient for multiple reasons

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 compiler/rustc_hir_typeck/src/expectation.rs around lines 77–89, then inspect fudge_inference_if_ok and its use when checking function-call arguments. Reproduce the generic function example from the issue and trace how the unsized dyn Fn expectation is formed. The issue does not yet define the remaining cases or a concrete completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.