Repository navigation
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessNLL-poloniusIssues related for using Polonius in the borrow checkerIssues related for using Polonius in the borrow checkerS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: 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.Relevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
The following code was created based on #160979 with trial and error. It compiles in nightly and segfaults. It doesn't compile with -Zpolonius=off.
type Payload = Box<i32>;
trait Produce<'a> {
fn produce(self) -> &'a &'a Payload;
}
impl<'a> Produce<'a> for &'a &'a Payload {
fn produce(self) -> &'a &'a Payload {
self
}
}
trait Outlives<'a, 'b> {
fn shorten(x: impl Produce<'a> + 'a) -> impl Produce<'a> + 'b;
}
impl<'a: 'b, 'b> Outlives<'a, 'b> for () {
fn shorten(x: impl Produce<'a> + 'a) -> impl Produce<'a> + 'b {
x
}
}
fn make_producer<'a, 'b>(payload: &'a &'b Payload) -> impl Produce<'a> + 'b + use<'a, 'b>
where
(): Outlives<'a, 'b>,
{
<()>::shorten(payload)
}
fn main() {
let wrong: &&Payload;
let a = Box::new(1);
{
let mut r: &Payload = &a;
let x: &&Payload = &r;
wrong = make_producer(x).produce();
r = &*Box::new(Box::new(2));
}
println!("{wrong}");
}Meta
Reproducible on the playground with version 1.99.0-nightly (2026-08-12 c98d0cb27cc63afdd626)
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessNLL-poloniusIssues related for using Polonius in the borrow checkerIssues related for using Polonius in the borrow checkerS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: 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.Relevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
theemathas commentedon Aug 13, 2026
Simplified a bit:
theemathas commentedon Aug 13, 2026
Surprisingly, annotating the type in the above code as
let wrong: &'static Payloadstill results in code that compiles. Despite this, using a turbofish likemake_producer::<'static, '_>ormake_producer::<'_, 'static>results in a compile error.theemathas commentedon Aug 21, 2026
There are a few more ways to cause unsoundness found at #t-types/polonius > Reporting a few Polonius bugs @ 💬 (listed as "bug 2" through "bug 7"), which might or might not have the same root cause.
Rollup merge of rust-lang#164168 - jackh726:alias-liveness-unsoundnes…
Rollup merge of rust-lang#164168 - jackh726:alias-liveness-unsoundnes…
Rollup merge of rust-lang#164168 - jackh726:alias-liveness-unsoundnes…
Don't test a type argument for alias liveness
Rollup merge of rust-lang#164168 - jackh726:alias-liveness-unsoundnes…
Unrolled build for #164168 in rollup 165023
Rollup merge of #164168 - jackh726:alias-liveness-unsoundness-tests, …