generator layout: ignore fake borrows
This commit is contained in:
parent
bf360d407e
commit
a42eca42df
@ -5,7 +5,8 @@ use rustc_middle::mir::*;
|
|||||||
use crate::{AnalysisDomain, GenKill, GenKillAnalysis};
|
use crate::{AnalysisDomain, GenKill, GenKillAnalysis};
|
||||||
|
|
||||||
/// A dataflow analysis that tracks whether a pointer or reference could possibly exist that points
|
/// A dataflow analysis that tracks whether a pointer or reference could possibly exist that points
|
||||||
/// to a given local.
|
/// to a given local. This analysis ignores fake borrows, so it should not be used by
|
||||||
|
/// borrowck.
|
||||||
///
|
///
|
||||||
/// At present, this is used as a very limited form of alias analysis. For example,
|
/// At present, this is used as a very limited form of alias analysis. For example,
|
||||||
/// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for
|
/// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for
|
||||||
@ -91,13 +92,17 @@ where
|
|||||||
self.super_rvalue(rvalue, location);
|
self.super_rvalue(rvalue, location);
|
||||||
|
|
||||||
match rvalue {
|
match rvalue {
|
||||||
Rvalue::AddressOf(_, borrowed_place) | Rvalue::Ref(_, _, borrowed_place) => {
|
// We ignore fake borrows as these get removed after analysis and shouldn't effect
|
||||||
|
// the layout of generators.
|
||||||
|
Rvalue::AddressOf(_, borrowed_place)
|
||||||
|
| Rvalue::Ref(_, BorrowKind::Mut { .. } | BorrowKind::Shared, borrowed_place) => {
|
||||||
if !borrowed_place.is_indirect() {
|
if !borrowed_place.is_indirect() {
|
||||||
self.trans.gen(borrowed_place.local);
|
self.trans.gen(borrowed_place.local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::Cast(..)
|
Rvalue::Cast(..)
|
||||||
|
| Rvalue::Ref(_, BorrowKind::Shallow, _)
|
||||||
| Rvalue::ShallowInitBox(..)
|
| Rvalue::ShallowInitBox(..)
|
||||||
| Rvalue::Use(..)
|
| Rvalue::Use(..)
|
||||||
| Rvalue::ThreadLocalRef(..)
|
| Rvalue::ThreadLocalRef(..)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
//!
|
//!
|
||||||
//! - [`AscribeUserType`]
|
//! - [`AscribeUserType`]
|
||||||
//! - [`FakeRead`]
|
//! - [`FakeRead`]
|
||||||
//! - [`Assign`] statements with a [`Shallow`] borrow
|
//! - [`Assign`] statements with a [`Fake`] borrow
|
||||||
//!
|
//!
|
||||||
//! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType
|
//! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType
|
||||||
//! [`Assign`]: rustc_middle::mir::StatementKind::Assign
|
//! [`Assign`]: rustc_middle::mir::StatementKind::Assign
|
||||||
|
34
tests/ui/coroutine/witness-ignore-fake-reads.rs
Normal file
34
tests/ui/coroutine/witness-ignore-fake-reads.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// check-pass
|
||||||
|
// edition: 2021
|
||||||
|
|
||||||
|
// regression test for #117059
|
||||||
|
struct SendNotSync(*const ());
|
||||||
|
unsafe impl Send for SendNotSync {}
|
||||||
|
// impl !Sync for SendNotSync {} // automatically disabled
|
||||||
|
|
||||||
|
struct Inner {
|
||||||
|
stream: SendNotSync,
|
||||||
|
state: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SendSync;
|
||||||
|
impl std::ops::Deref for SendSync {
|
||||||
|
type Target = Inner;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn next() {
|
||||||
|
let inner = SendSync;
|
||||||
|
match inner.state {
|
||||||
|
true if false => {}
|
||||||
|
false => async {}.await,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_send<T: Send>(_: T) {}
|
||||||
|
fn main() {
|
||||||
|
is_send(next())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user