rust-lang / rust-lang/rust

`Freeze` check ignores lifetimes

Open
#161,845 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval A-constant-promotion A-lifetimes A-temporary-lifetime-extension C-bug F-freeze needs-triage T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This issue is similar to #156694 and #156770.

#![feature(freeze)]

use std::marker::Freeze;

trait Super<'a> {
    type Assoc: 'a;
    const C: Self::Assoc;
}

trait Sub<'a>: Super<'a> {
    const D: &'a Self::Assoc;
}

impl<'a, T: for<'b> Super<'b>> Sub<'a> for T
where
    <T as Super<'static>>::Assoc: Freeze,
{
    const D: &'a <Self as Super<'a>>::Assoc = &<T as Super<'a>>::C;
}

The above code compiles without errors. Note that a value of type <Self as Super<'a>>::Assoc is constant-promoted and/or lifetime-extended into a static-like thing. This is supposed to require the type to implement Freeze. However, I have only wrote the bound <T as Super<'static>>::Assoc: Freeze, which is for a different lifetime. So, this code probably shouldn't compile.

Meta

Reproducible on the playground with version version: 1.100.0-nightly (2026-08-25 787af2b8c80638c51a4f)

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 supplied code on the Rust Playground with the reported nightly version 1.100.0-nightly. Investigate the compiler's Freeze checking and lifetime handling for the associated type; done means the example is rejected because the Freeze bound applies to a different lifetime, with a regression test covering the case.

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
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.