rust-lang / rust-lang/rust

Evaluate caches stack-dependent results

Open
#123,403 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system fixed-by-next-solver T-types
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

struct W<T: ?Sized>(*const T);
trait Foo {}
trait Bar {}

impl<T: Bar + NotImplemented> Foo for T {}
impl Foo for W<u32> {}

impl<T: Foo + AssertInferenceConstraintsApplied> Bar for T {}
trait AssertInferenceConstraintsApplied {}
trait GuideFromEnv {}
trait ErrOnGuidance {}
impl<T: GuideFromEnv + ErrOnGuidance> AssertInferenceConstraintsApplied for T {}
impl<T> GuideFromEnv for T {}
impl ErrOnGuidance for W<u32> {}

impl<T> Bar for T
where
    W<T>: NotImplemented {}
trait NotImplemented {}

fn impls_foo<T: Foo>() {}
fn impls_bar<T: Bar>() {}

fn with_bound()
where
    W<u64>: GuideFromEnv,
{
    impls_foo::<W<_>>(); // commenting this line changes the next one to OK
    impls_bar::<W<_>>(); // ERROR
}

fn main() {
    with_bound();
}

cc @compiler-errors #123303 this should be broken even after https://github.com/rust-lang/rust/pull/122791

THe idea is from https://github.com/rust-lang/rust/issues/123303#issuecomment-2030904635

  • GoalA
    • CandA1
      • GoalB
        • CandB1
          • GoalA (inductive cycle -> ambig)
          • AssertInferenceConstraintsApplied (fails due to incompleteness if the inference constraints from CandA2 have not yet been applied)
        • CandB2
          • Impossible (necessary to evaluate nested goals of CandB1 during selection)
    • CandA2
      • guide inference ~> Ok, but inference constraints

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 supplied Rust reproducer and compare the result with and without the impls_foo call. Read issue #123303 and PR #122791 for the related trait-solver behavior and inference-constraint context; done means the stack-dependent result is reproduced, understood, and covered by a compiler regression test.

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
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.