Skip to content

impl Trait bounds incorrectly assumed to be not-live #163886

Description

@jackh726

The current alias liveness code find the parameters that must be considered live given all the bounds. For cases where there are multiple bounds but not set of parameters that outlive all, I incorrectly thought that "nothing can be captured". This is (now very obviously) wrong.

Code

use std::fmt::Debug;

trait Tr {
    type Assoc: Debug;
    fn get(self) -> Self::Assoc;
}
impl<'q> Tr for &'q u8 {
    type Assoc = &'q u8;
    fn get(self) -> &'q u8 {
        self
    }
}

fn make<'a, 'b, T: Tr>(t: T) -> impl Debug + 'a + 'b
where
    T::Assoc: 'a + 'b,
{
    t.get()
}

fn show<T: Debug>(t: T, r: &Vec<u8>) {
    println!("escaped = {t:?}, reused = {r:?}");
}

fn main() {
    let escaped;
    {
        let v: Vec<u8> = vec![42];
        escaped = make(&v[0]);
        //~^ ERROR `v` does not live long enough
    }
    let reused: Vec<u8> = vec![7];
    show(escaped, &reused);
}

playground

Version with regression

Regression from #156027, with both NLL and Polonius Alpha. It has made it to stable 1.99.

Activity

  1. self-assigned this
    on Oct 6, 2026
  2. added
    regression-from-stable-to-stable
    I-unsound
    C-bug
    on Oct 6, 2026
  3. added
    needs-triage
    I-prioritize
    on Oct 6, 2026
  4. jackh726 commented on Oct 6, 2026

    @jackh726
    MemberAuthor

    Disclosure: An LLM found this test

  5. added
    A-borrow-checker
    A-impl-trait
    T-types
    and removed
    needs-triage
    on Oct 6, 2026
  6. removed
    I-prioritize
    on Oct 6, 2026
  7. rustbot commented on Oct 6, 2026

    @rustbot
    Collaborator

    Assigning P-high (discussion on Zulip).

  8. added
    P-high
    on Oct 6, 2026
  9. cuviper commented on Oct 12, 2026

    @cuviper
    Member

    Regression from #156027, with both NLL and Polonius Alpha. It has made it to stable 1.99.

    @jackh726 Does this warrant a revert for stable, since there's no fix yet?
    (edit: a direct naive revert has lots of conflicts though)

    I am currently gathering 1.99.1, but I'm not sure what (if anything) to do for this issue.

  10. added 3 commits that reference this issue on Oct 27, 2026
  11. added a commit that references this issue on Oct 27, 2026
  12. added a commit that references this issue on Oct 27, 2026
  13. added
    S-bug-has-test
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-borrow-checkerA-impl-traitC-bugI-unsoundP-highS-bug-has-testT-typesregression-from-stable-to-stable

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions