Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implied bounds on nested references + variance = soundness hole #25860

Open
Labels
A-type-systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium 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.
@aturon

Description

@aturon

The combination of variance and implied bounds for nested references opens a hole in the current type system:

staticUNIT:&'static&'static() =&&();fnfoo<'a,'b,T>(_:&'a&'b(),v:&'bT) ->&'aT{ v}fnbad<'a,T>(x:&'aT) ->&'staticT{let f:fn(&'static&'a(),&'aT) ->&'staticT = foo;f(UNIT, x)}

This hole has been fixed in#129021 for non-higher-ranked function pointers. The underlying issue still persists.

staticUNIT:&'static&'static() =&&();fnfoo<'a,'b,T>(_:&'a&'b(),v:&'bT, _:&()) ->&'aT{ v}fnbad<'a,T>(x:&'aT) ->&'staticT{let f:fn(_,&'aT,&()) ->&'staticT = foo;f(UNIT, x,&())}fnmain(){}

Update from@pnkfelix :

While the test as written above is rejected by Rust today (with the error message for line 6 saying "in type&'static &'a (), reference has a longer lifetime than the data it references"), that is just an artifact of the original source code (with its explicit type signature) running up againstone new WF-check.

The fundamental issue persists, since one can today write instead:

staticUNIT:&'static&'static() =&&();fnfoo<'a,'b,T>(_:&'a&'b(),v:&'bT) ->&'aT{ v}fnbad<'a,T>(x:&'aT) ->&'staticT{let f:fn(_,&'aT) ->&'staticT = foo;f(UNIT, x)}

(and this way, still get the bad behavingfn bad, by just side-stepping one of the explicit type declarations.)


Update from@lcnr :

While the test as written above is rejected by Rust today, that is just an artifact of the original source code (with its lack of higher ranked regions) running up againstone new WF-check ✨

The fundamental issue persists, since one can today write instead:

staticUNIT:&'static&'static() =&&();fnfoo<'a,'b,T>(_:&'a&'b(),v:&'bT, _:&()) ->&'aT{ v}fnbad<'a,T>(x:&'aT) ->&'staticT{let f:fn(_,&'aT,&()) ->&'staticT = foo;//                  ^ note the additional higher-ranked region heref(UNIT, x,&())}

All the non-higher ranked variants of this issue have been fixed by#129021.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium 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.

    Type

    No type

    Projects

    Status

    new solver everywhere

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp