Skip to content

implied bound related unsoundness #157316

Description

@cushionbadak

This is almost identical to the unsound example test case for issue-25860. The difference is that this variant only began compiling successfully since nightly-2020-06-24, whereas the existing known unsoundness already compiles since nightly-2015-02-18 (rustc 1.0.0).

I tried this code:

static UNIT: &'static &'static () = &&();

fn foo<'a, 'b, T>(_: &'a &'b (), v: &'b T) -> &'a T { v }

fn bad<'a, T>(x: &'a T) -> &'static T {
    let f: fn(_, &T) -> &'static T = foo;
    f(UNIT, x)
}

fn main() {
    let r: &'static String;
    {
        let s = String::from("temporary");
        r = bad(&s);
        println!("while alive: {}", r);
    }
    println!("use-after-free reads: {}", r);
}

The only difference from that test case is the number of parameters and arguments in foo.
For reference:

fn foo<'a, 'b, T>(_: &'a &'b (), v: &'b T, _: &()) -> &'a T { v }
fn bad<'a, T>(x: &'a T) -> &'static T {
let f: fn(_, &'a T, &()) -> &'static T = foo;
f(UNIT, x, &())
}

I expected to see this happen: compilation should fail

Instead, this happened: the program compiled and produced the following use-after-free output:

while alive: temporary
use-after-free reads: j��;g

Meta

rustc --version --verbose:

rustc 1.98.0-nightly (6bdf43094 2026-06-01)
binary: rustc
commit-hash: 6bdf43094fae65d298bc430362f116176cd25a3c
commit-date: 2026-06-01
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6

Bisection Results

Command: cargo bisect-rustc --start=2018-01-01 --end=2020-06-30 --regress=success --preserve --script rustc -- bug.rs

Regression in: nightly-2020-06-24.

Log

searched toolchains nightly-2018-01-01 through nightly-2020-06-30


********************************************************************************
Regression in nightly-2020-06-24
********************************************************************************

fetching https://static.rust-lang.org/dist/2020-06-23/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2020-06-23: 40 B / 40 B [==============================================================================================================================================] 100.00 % 1.40 MB/s converted 2020-06-23 to 6bb3dbfc6c6d8992d08431f320ba296a0c2f7498
fetching https://static.rust-lang.org/dist/2020-06-24/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2020-06-24: 40 B / 40 B [==============================================================================================================================================] 100.00 % 2.07 MB/s converted 2020-06-24 to ff5b446d2fdbd898bc97a751f2f72858de185cf1
looking for regression commit between 2020-06-23 and 2020-06-24
fetching (via remote github) commits from max(6bb3dbfc6c6d8992d08431f320ba296a0c2f7498, 2020-06-21) to ff5b446d2fdbd898bc97a751f2f72858de185cf1
ending github query because we found starting sha: 6bb3dbfc6c6d8992d08431f320ba296a0c2f7498
get_commits_between returning commits, len: 6
  commit[0] 2020-06-22: Auto merge of #73415 - ehuss:update-cargo, r=ehuss
  commit[1] 2020-06-22: Auto merge of #73594 - Aaron1011:revert/move-fn-self-msg, r=Manishearth
  commit[2] 2020-06-23: Auto merge of #73007 - yoshuawuyts:socketaddr-from-string-u16, r=sfackler
  commit[3] 2020-06-23: Auto merge of #73635 - Dylan-DPC:rollup-b4wbp42, r=Dylan-DPC
  commit[4] 2020-06-23: Auto merge of #73643 - Manishearth:rollup-68dr8fz, r=Manishearth
  commit[5] 2020-06-23: Auto merge of #73644 - ollie27:rustdoc_alias_filter, r=GuillaumeGomez
ERROR: no CI builds available between 6bb3dbfc6c6d8992d08431f320ba296a0c2f7498 and ff5b446d2fdbd898bc97a751f2f72858de185cf1 within last 167 days

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-implied-boundsArea: Implied bounds / inferred outlives-boundsA-type-systemArea: Type systemC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions