rust-lang / rust-lang/rust

higher-ranked `dyn Trait`, fn pointers, and closures allow normalizing to non-wf type

Open
#152,489 14 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-closures A-dyn-trait A-higher-ranked A-implied-bounds A-rust-for-linux A-trait-system C-bug I-ICE I-unsound P-medium T-types
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

trait Trait<'hr> {
    type Assoc;
}

struct W<T, U>(T, U);
trait Extend<'a, 'b> {
    fn extend(x: &'b str) -> &'a str;
}
impl<'a, 'hr, 'b> Extend<'a, 'b> for W<&'a &'hr (), &'hr &'b ()> {
    fn extend(x: &'b str) -> &'a str {
        x
    }
}

fn extend_via_dyn<'a, 'b, T: for<'hr> Trait<'hr, Assoc: Extend<'a, 'b>> + ?Sized>(x: &'b str) -> &'a str {
    T::Assoc::extend(x)
}

fn extend<'b>(x: &'b str) -> &'static str {
    extend_via_dyn::<dyn for<'hr> Trait<'hr, Assoc = W<&'static &'hr (), &'hr &'b ()>>>(x)
}

fn main() {
    let x = extend(String::from("temp").as_str());
    println!("{x}");
}

The underlying issue has been discovered by @theemathas in https://github.com/rust-lang/rust/issues/152467#issuecomment-3882205618.

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 compiling the reproducer in the issue and reading the discussion in issue #152467. Investigate how higher-ranked dyn Trait associated-type normalization interacts with function pointers and closures. Done means the compiler no longer permits the shown program to normalize to a non-well-formed type.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.