Skip to content

Rollup of 4 pull requests #100662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
12 changes: 10 additions & 2 deletions compiler/rustc_typeck/src/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
}

#[derive(Default)]
pub struct SuspendCheckData<'a, 'tcx> {
struct SuspendCheckData<'a, 'tcx> {
expr: Option<&'tcx Expr<'tcx>>,
source_span: Span,
yield_span: Span,
Expand All @@ -472,7 +472,7 @@ pub struct SuspendCheckData<'a, 'tcx> {
//
// Note that this technique was chosen over things like a `Suspend` marker trait
// as it is simpler and has precedent in the compiler
pub fn check_must_not_suspend_ty<'tcx>(
fn check_must_not_suspend_ty<'tcx>(
fcx: &FnCtxt<'_, 'tcx>,
ty: Ty<'tcx>,
hir_id: HirId,
Expand All @@ -489,6 +489,8 @@ pub fn check_must_not_suspend_ty<'tcx>(

let plural_suffix = pluralize!(data.plural_len);

debug!("Checking must_not_suspend for {}", ty);

match *ty.kind() {
ty::Adt(..) if ty.is_box() => {
let boxed_ty = ty.boxed_ty();
Expand Down Expand Up @@ -580,6 +582,12 @@ pub fn check_must_not_suspend_ty<'tcx>(
},
)
}
// If drop tracking is enabled, we want to look through references, since the referrent
// may not be considered live across the await point.
ty::Ref(_region, ty, _mutability) if fcx.sess().opts.unstable_opts.drop_tracking => {
let descr_pre = &format!("{}reference{} to ", data.descr_pre, plural_suffix);
check_must_not_suspend_ty(fcx, ty, hir_id, SuspendCheckData { descr_pre, ..data })
}
_ => false,
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl f32 {

/// Not a Number (NaN).
///
/// Note that IEEE-745 doesn't define just a single NaN value;
/// Note that IEEE-754 doesn't define just a single NaN value;
/// a plethora of bit patterns are considered to be NaN.
/// Furthermore, the standard makes a difference
/// between a "signaling" and a "quiet" NaN,
Expand Down Expand Up @@ -632,7 +632,7 @@ impl f32 {
}

/// Returns `true` if `self` has a positive sign, including `+0.0`, NaNs with
/// positive sign bit and positive infinity. Note that IEEE-745 doesn't assign any
/// positive sign bit and positive infinity. Note that IEEE-754 doesn't assign any
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
Expand All @@ -654,7 +654,7 @@ impl f32 {
}

/// Returns `true` if `self` has a negative sign, including `-0.0`, NaNs with
/// negative sign bit and negative infinity. Note that IEEE-745 doesn't assign any
/// negative sign bit and negative infinity. Note that IEEE-754 doesn't assign any
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl f64 {

/// Not a Number (NaN).
///
/// Note that IEEE-745 doesn't define just a single NaN value;
/// Note that IEEE-754 doesn't define just a single NaN value;
/// a plethora of bit patterns are considered to be NaN.
/// Furthermore, the standard makes a difference
/// between a "signaling" and a "quiet" NaN,
Expand Down Expand Up @@ -624,7 +624,7 @@ impl f64 {
}

/// Returns `true` if `self` has a positive sign, including `+0.0`, NaNs with
/// positive sign bit and positive infinity. Note that IEEE-745 doesn't assign any
/// positive sign bit and positive infinity. Note that IEEE-754 doesn't assign any
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
Expand Down Expand Up @@ -655,7 +655,7 @@ impl f64 {
}

/// Returns `true` if `self` has a negative sign, including `-0.0`, NaNs with
/// negative sign bit and negative infinity. Note that IEEE-745 doesn't assign any
/// negative sign bit and negative infinity. Note that IEEE-754 doesn't assign any
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
Expand Down
8 changes: 7 additions & 1 deletion library/unwind/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ use std::env;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET").expect("TARGET was not set");
println!("cargo:rerun-if-env-changed=CARGO_CFG_MIRI");

if env::var_os("CARGO_CFG_MIRI").is_some() {
// Miri doesn't need the linker flags or a libunwind build.
return;
}

let target = env::var("TARGET").expect("TARGET was not set");
if target.contains("android") {
let build = cc::Build::new();

Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/lint/must_not_suspend/ref-drop-tracking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// edition:2018
// compile-flags: -Zdrop-tracking
#![feature(must_not_suspend)]
#![deny(must_not_suspend)]

#[must_not_suspend = "You gotta use Umm's, ya know?"]
struct Umm {
i: i64
}

struct Bar {
u: Umm,
}

async fn other() {}

impl Bar {
async fn uhoh(&mut self) {
let guard = &mut self.u; //~ ERROR `Umm` held across

other().await;

*guard = Umm {
i: 2
}
}
}

fn main() {
}
27 changes: 27 additions & 0 deletions src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error: reference to `Umm` held across a suspend point, but should not be
--> $DIR/ref-drop-tracking.rs:19:13
|
LL | let guard = &mut self.u;
| ^^^^^
LL |
LL | other().await;
| ------ the value is held across this suspend point
|
note: the lint level is defined here
--> $DIR/ref-drop-tracking.rs:4:9
|
LL | #![deny(must_not_suspend)]
| ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/ref-drop-tracking.rs:19:13
|
LL | let guard = &mut self.u;
| ^^^^^
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
--> $DIR/ref-drop-tracking.rs:19:13
|
LL | let guard = &mut self.u;
| ^^^^^

error: aborting due to previous error