Skip to content

Commit

Permalink
Auto merge of #3513 - rust-lang:rustup-2024-04-25, r=RalfJung
Browse files Browse the repository at this point in the history
Automatic Rustup
  • Loading branch information
bors committed Apr 25, 2024
2 parents c2c7072 + 15b04db commit 0893456
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 88 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c1feb3eceef7d5f0126c309a87062cf413fe0a25
cb3752d20e0f5d24348062211102a08d46fbecff
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#![feature(let_chains)]
#![feature(lint_reasons)]
#![feature(trait_upcasting)]
#![feature(absolute_path)]
// Configure clippy and other lints
#![allow(
clippy::collapsible_else_if,
Expand Down
3 changes: 2 additions & 1 deletion tests/fail/coroutine-pinned-moved.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
#![feature(coroutines, coroutine_trait)]
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]

use std::{
ops::{Coroutine, CoroutineState},
pin::Pin,
};

fn firstn() -> impl Coroutine<Yield = u64, Return = ()> {
#[coroutine]
static move || {
let mut num = 0;
let num = &mut num;
Expand Down
225 changes: 146 additions & 79 deletions tests/pass/coroutine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
#![feature(coroutines, coroutine_trait, never_type)]
#![feature(coroutines, coroutine_trait, never_type, stmt_expr_attributes)]

use std::fmt::Debug;
use std::mem::ManuallyDrop;
Expand Down Expand Up @@ -43,94 +43,144 @@ fn basic() {
panic!()
}

finish(1, false, || yield 1);
finish(
1,
false,
#[coroutine]
|| yield 1,
);

finish(3, false, || {
let mut x = 0;
yield 1;
x += 1;
yield 1;
x += 1;
yield 1;
assert_eq!(x, 2);
});
finish(
3,
false,
#[coroutine]
|| {
let mut x = 0;
yield 1;
x += 1;
yield 1;
x += 1;
yield 1;
assert_eq!(x, 2);
},
);

finish(7 * 8 / 2, false, || {
for i in 0..8 {
yield i;
}
});
finish(
7 * 8 / 2,
false,
#[coroutine]
|| {
for i in 0..8 {
yield i;
}
},
);

finish(1, false, || {
if true {
yield 1;
} else {
}
});
finish(
1,
false,
#[coroutine]
|| {
if true {
yield 1;
} else {
}
},
);

finish(1, false, || {
if false {
} else {
yield 1;
}
});
finish(
1,
false,
#[coroutine]
|| {
if false {
} else {
yield 1;
}
},
);

finish(2, false, || {
if {
yield 1;
false
} {
finish(
2,
false,
#[coroutine]
|| {
if {
yield 1;
false
} {
yield 1;
panic!()
}
yield 1;
panic!()
}
yield 1;
});
},
);

// also test self-referential coroutines
assert_eq!(
finish(5, true, static || {
let mut x = 5;
let y = &mut x;
*y = 5;
yield *y;
*y = 10;
x
}),
finish(
5,
true,
#[coroutine]
static || {
let mut x = 5;
let y = &mut x;
*y = 5;
yield *y;
*y = 10;
x
}
),
10
);
assert_eq!(
finish(5, true, || {
let mut x = Box::new(5);
let y = &mut *x;
*y = 5;
yield *y;
*y = 10;
*x
}),
finish(
5,
true,
#[coroutine]
|| {
let mut x = Box::new(5);
let y = &mut *x;
*y = 5;
yield *y;
*y = 10;
*x
}
),
10
);

let b = true;
finish(1, false, || {
yield 1;
if b {
return;
}
#[allow(unused)]
let x = never();
#[allow(unreachable_code)]
yield 2;
drop(x);
});

finish(3, false, || {
yield 1;
#[allow(unreachable_code)]
let _x: (String, !) = (String::new(), {
finish(
1,
false,
#[coroutine]
|| {
yield 1;
if b {
return;
}
#[allow(unused)]
let x = never();
#[allow(unreachable_code)]
yield 2;
return;
});
});
drop(x);
},
);

finish(
3,
false,
#[coroutine]
|| {
yield 1;
#[allow(unreachable_code)]
let _x: (String, !) = (String::new(), {
yield 2;
return;
});
},
);
}

fn smoke_resume_arg() {
Expand Down Expand Up @@ -172,7 +222,8 @@ fn smoke_resume_arg() {
}

drain(
&mut |mut b| {
&mut #[coroutine]
|mut b| {
while b != 0 {
b = yield (b + 1);
}
Expand All @@ -181,21 +232,35 @@ fn smoke_resume_arg() {
vec![(1, Yielded(2)), (-45, Yielded(-44)), (500, Yielded(501)), (0, Complete(-1))],
);

expect_drops(2, || drain(&mut |a| yield a, vec![(DropMe, Yielded(DropMe))]));
expect_drops(2, || {
drain(
&mut #[coroutine]
|a| yield a,
vec![(DropMe, Yielded(DropMe))],
)
});

expect_drops(6, || {
drain(
&mut |a| yield yield a,
&mut #[coroutine]
|a| yield yield a,
vec![(DropMe, Yielded(DropMe)), (DropMe, Yielded(DropMe)), (DropMe, Complete(DropMe))],
)
});

#[allow(unreachable_code)]
expect_drops(2, || drain(&mut |a| yield return a, vec![(DropMe, Complete(DropMe))]));
expect_drops(2, || {
drain(
&mut #[coroutine]
|a| yield return a,
vec![(DropMe, Complete(DropMe))],
)
});

expect_drops(2, || {
drain(
&mut |a: DropMe| {
&mut #[coroutine]
|a: DropMe| {
if false { yield () } else { a }
},
vec![(DropMe, Complete(DropMe))],
Expand All @@ -205,7 +270,8 @@ fn smoke_resume_arg() {
expect_drops(4, || {
drain(
#[allow(unused_assignments, unused_variables)]
&mut |mut a: DropMe| {
&mut #[coroutine]
|mut a: DropMe| {
a = yield;
a = yield;
a = yield;
Expand All @@ -228,7 +294,8 @@ fn uninit_fields() {
}

fn run<T>(x: bool, y: bool) {
let mut c = || {
let mut c = #[coroutine]
|| {
if x {
let _a: T;
if y {
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/portable-simd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@compile-flags: -Zmiri-strict-provenance
#![feature(portable_simd, adt_const_params, inline_const, core_intrinsics)]
#![feature(portable_simd, adt_const_params, core_intrinsics)]
#![allow(incomplete_features, internal_features)]
use std::intrinsics::simd as intrinsics;
use std::ptr;
Expand Down
1 change: 0 additions & 1 deletion tests/pass/shims/path.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@compile-flags: -Zmiri-disable-isolation
#![feature(absolute_path)]
use std::path::{absolute, Path};

#[track_caller]
Expand Down
3 changes: 2 additions & 1 deletion tests/pass/stacked-borrows/coroutine-self-referential.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// See https://github.com/rust-lang/unsafe-code-guidelines/issues/148:
// this fails when Stacked Borrows is strictly applied even to `!Unpin` types.
#![feature(coroutines, coroutine_trait)]
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]

use std::{
ops::{Coroutine, CoroutineState},
pin::Pin,
};

fn firstn() -> impl Coroutine<Yield = u64, Return = ()> {
#[coroutine]
static move || {
let mut num = 0;
let num = &mut num;
Expand Down
6 changes: 3 additions & 3 deletions tests/pass/track-caller-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn test_coroutine() {
}

#[rustfmt::skip]
let coroutine = #[track_caller] |arg: String| {
let coroutine = #[track_caller] #[coroutine] |arg: String| {
yield ("first", arg.clone(), Location::caller());
yield ("second", arg.clone(), Location::caller());
};
Expand All @@ -255,15 +255,15 @@ fn test_coroutine() {
assert_eq!(mono_loc.column(), 42);

#[rustfmt::skip]
let non_tracked_coroutine = || { yield Location::caller(); };
let non_tracked_coroutine = #[coroutine] || { yield Location::caller(); };
let non_tracked_line = line!() - 1; // This is the line of the coroutine, not its caller
let non_tracked_loc = match Box::pin(non_tracked_coroutine).as_mut().resume(()) {
CoroutineState::Yielded(val) => val,
_ => unreachable!(),
};
assert_eq!(non_tracked_loc.file(), file!());
assert_eq!(non_tracked_loc.line(), non_tracked_line);
assert_eq!(non_tracked_loc.column(), 44);
assert_eq!(non_tracked_loc.column(), 57);
}

fn main() {
Expand Down

0 comments on commit 0893456

Please sign in to comment.