forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#75213 - dingxiangfei2009:yield-point-in-match…
…-guard, r=tmandry [generator] Special cases for match guard when analyzing interior types in generators Fix rust-lang#72651 This proposes one of ways to fix the mentioned issue. One cause of rust-lang#72651 is that the interior type analysis misses out types of match pattern locals. Those locals are manifested as temporary borrows in the scopes of match arm guards. If uses of these locals appear after yield points, the borrows from them were not considered live across the yield points. However, this is not the case since the borrowing always happens at the very beginning of the match guard. This calls for special treatment to analysis of types appearing in the match guard. Those borrows are recorded as the HIR tree is walked by `InteriorVisitor` and their uses are recorded whenever a yield point is crossed.
- Loading branch information
Showing
4 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
// This test is derived from | ||
// https://github.com/rust-lang/rust/issues/72651#issuecomment-668720468 | ||
|
||
// This test demonstrates that, in `async fn g()`, | ||
// indeed a temporary borrow `y` from `x` is live | ||
// while `f().await` is being evaluated. | ||
// Thus, `&'_ u8` should be included in type signature | ||
// of the underlying generator. | ||
|
||
async fn f() -> u8 { 1 } | ||
|
||
pub async fn g(x: u8) { | ||
match x { | ||
y if f().await == y => (), | ||
_ => (), | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = g(10); | ||
} |