IssueRaiser

Implied bounds on nested references + variance = soundness hole

<!-- homu-ignore:start --> *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/issues/25860)* <!-- homu-ignore:end --> The combination of variance and implied bounds for nested references opens a hole in the current type system: ``` rust 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(&'static &'a (), &'a T) -> &'static T = foo; f(UNIT, x) } ``` This hole has been fixed in #129021 for non-higher-ranked function pointers. The underlying issue still persists. ```rust 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(_, &'a T, &()) -> &'static T = foo; f(UNIT, x, &()) } fn main() {} ```

Posted by aturon on May 28, 2015, 5:37 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.7,000 issues0 comments

github (Sysadmin)

Implied bounds on nested references + variance = soundness hole

aturonMay 28, 2015, 5:37 PM

<!-- homu-ignore:start --> *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/issues/25860)* <!-- homu-ignore:end --> The combination of variance and implied bounds for nested references opens a hole in the current type system: ``` rust 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(&'static &'a (), &'a T) -> &'static T = foo; f(UNIT, x) } ``` This hole has been fixed in #129021 for non-higher-ranked function pointers. The underlying issue still persists. ```rust 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(_, &'a T, &()) -> &'static T = foo; f(UNIT, x, &()) } fn main() {} ```

Comments (0)

No comments yet. Start the discussion.

Comment on this issue