-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
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/Soundness
Description
I tried this code:
static I: i32 = 0;
static R: &'static & i32 = &&I;
fn aux<'a, 'b, T>(_: &'a &'b i32, arg: &'b T) -> &'a T
{
return arg;
}
fn foo<'a, T>(arg: &'a T) -> &'static T
{
let f: fn(_, &'a T) -> &'static T = aux;
return f(R, arg);
}
fn bar() -> &'static i32
{
let a: i32 = 0;
return foo(&a);
}
fn main()
{
let res: &i32 = bar();
println!("{0}", *res);
}
I expected to see this happen: 0
Instead, this happened: 32765
Meta
Reproducible on nightly and stable (1.48.0)
Based on Russian discussion on Rust safety: https://habr.com/en/company/pvs-studio/blog/530856/?reply_to=22377206#comment_22376840, example was provided by KanuTaH.
Metadata
Metadata
Assignees
Labels
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/Soundness