Skip to content

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

Open

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-stablePerformance or correctness regression from one stable version to another.
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    C-bugCategory: This is a bug.
    on Oct 6, 2026
  3. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 6, 2026
  4. jackh726 commented on Oct 6, 2026

    @jackh726
    MemberAuthor

    Disclosure: An LLM found this test

  5. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 6, 2026
  6. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 6, 2026
  7. rustbot commented on Oct 6, 2026

    @rustbot
    Collaborator

    Assigning P-high (discussion on Zulip).

  8. 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.

  9. added 3 commits that reference this issue on Oct 27, 2026
  10. added a commit that references this issue on Oct 27, 2026
  11. added a commit that references this issue on Oct 27, 2026
  12. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` 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-checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions