Skip to content

Commit ba70527

Browse files
committed
Auto merge of #123108 - matthiaskrgr:rollup-zossklv, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #108675 (Document `adt_const_params` feature in Unstable Book) - #122120 (Suggest associated type bounds on problematic associated equality bounds) - #122589 (Fix diagnostics for async block cloning) - #122835 (Require `DerefMut` and `DerefPure` on `deref!()` patterns when appropriate) - #123049 (In `ConstructCoroutineInClosureShim`, pass receiver by mut ref, not mut pointer) - #123055 (enable cargo miri test doctests) - #123057 (unix fs: Make hurd using explicit new rather than From) - #123087 (Change `f16` and `f128` clippy stubs to be nonpanicking) - #123103 (Rename `Inherited` -> `TypeckRootCtxt`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3643dc4 + bcf48de commit ba70527

File tree

6 files changed

+79
-17
lines changed

6 files changed

+79
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ binaries, and as such worth documenting:
505505
* `MIRI_LOCAL_CRATES` is set by `cargo-miri` to tell the Miri driver which
506506
crates should be given special treatment in diagnostics, in addition to the
507507
crate currently being compiled.
508+
* `MIRI_ORIG_RUSTDOC` is set and read by different phases of `cargo-miri` to remember the
509+
value of `RUSTDOC` from before it was overwritten.
508510
* `MIRI_VERBOSE` when set to any value tells the various `cargo-miri` phases to
509511
perform verbose logging.
510512
* `MIRI_HOST_SYSROOT` is set by bootstrap to tell `cargo-miri` which sysroot to use for *host*

cargo-miri/src/phases.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
202202
cmd.env("MIRI_BE_RUSTC", "target"); // we better remember to *unset* this in the other phases!
203203

204204
// Set rustdoc to us as well, so we can run doctests.
205+
if let Some(orig_rustdoc) = env::var_os("RUSTDOC") {
206+
cmd.env("MIRI_ORIG_RUSTDOC", orig_rustdoc);
207+
}
205208
cmd.env("RUSTDOC", &cargo_miri_path);
206209

207210
cmd.env("MIRI_LOCAL_CRATES", local_crates(&metadata));
@@ -581,9 +584,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
581584
let verbose = std::env::var("MIRI_VERBOSE")
582585
.map_or(0, |verbose| verbose.parse().expect("verbosity flag must be an integer"));
583586

584-
// phase_cargo_miri sets the RUSTDOC env var to ourselves, so we can't use that here;
585-
// just default to a straight-forward invocation for now:
586-
let mut cmd = Command::new("rustdoc");
587+
// phase_cargo_miri sets the RUSTDOC env var to ourselves, and puts a backup
588+
// of the old value into MIRI_ORIG_RUSTDOC. So that's what we have to invoke now.
589+
let rustdoc = env::var("MIRI_ORIG_RUSTDOC").unwrap_or("rustdoc".to_string());
590+
let mut cmd = Command::new(rustdoc);
587591

588592
let extern_flag = "--extern";
589593
let runtool_flag = "--runtool";

tests/pass/async-closure-drop.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![feature(async_closure, noop_waker, async_fn_traits)]
2+
3+
use std::future::Future;
4+
use std::pin::pin;
5+
use std::task::*;
6+
7+
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
8+
let mut fut = pin!(fut);
9+
let ctx = &mut Context::from_waker(Waker::noop());
10+
11+
loop {
12+
match fut.as_mut().poll(ctx) {
13+
Poll::Pending => {}
14+
Poll::Ready(t) => break t,
15+
}
16+
}
17+
}
18+
19+
async fn call_once(f: impl async FnOnce(DropMe)) {
20+
f(DropMe("world")).await;
21+
}
22+
23+
#[derive(Debug)]
24+
struct DropMe(&'static str);
25+
26+
impl Drop for DropMe {
27+
fn drop(&mut self) {
28+
println!("{}", self.0);
29+
}
30+
}
31+
32+
pub fn main() {
33+
block_on(async {
34+
let b = DropMe("hello");
35+
let async_closure = async move |a: DropMe| {
36+
println!("{a:?} {b:?}");
37+
};
38+
call_once(async_closure).await;
39+
});
40+
}

tests/pass/async-closure-drop.stdout

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DropMe("world") DropMe("hello")
2+
world
3+
hello

tests/pass/async-closure.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(async_closure, noop_waker, async_fn_traits)]
22

33
use std::future::Future;
4+
use std::ops::{AsyncFnMut, AsyncFnOnce};
45
use std::pin::pin;
56
use std::task::*;
67

@@ -16,25 +17,36 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
1617
}
1718
}
1819

19-
async fn call_once(f: impl async FnOnce(DropMe)) {
20-
f(DropMe("world")).await;
20+
async fn call_mut(f: &mut impl AsyncFnMut(i32)) {
21+
f(0).await;
2122
}
2223

23-
#[derive(Debug)]
24-
struct DropMe(&'static str);
24+
async fn call_once(f: impl AsyncFnOnce(i32)) {
25+
f(1).await;
26+
}
2527

26-
impl Drop for DropMe {
27-
fn drop(&mut self) {
28-
println!("{}", self.0);
29-
}
28+
async fn call_normal<F: Future<Output = ()>>(f: &impl Fn(i32) -> F) {
29+
f(0).await;
30+
}
31+
32+
async fn call_normal_once<F: Future<Output = ()>>(f: impl FnOnce(i32) -> F) {
33+
f(1).await;
3034
}
3135

3236
pub fn main() {
3337
block_on(async {
34-
let b = DropMe("hello");
35-
let async_closure = async move |a: DropMe| {
36-
println!("{a:?} {b:?}");
38+
let b = 2i32;
39+
let mut async_closure = async move |a: i32| {
40+
println!("{a} {b}");
3741
};
42+
call_mut(&mut async_closure).await;
3843
call_once(async_closure).await;
44+
45+
// No-capture closures implement `Fn`.
46+
let async_closure = async move |a: i32| {
47+
println!("{a}");
48+
};
49+
call_normal(&async_closure).await;
50+
call_normal_once(async_closure).await;
3951
});
4052
}

tests/pass/async-closure.stdout

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
DropMe("world") DropMe("hello")
2-
world
3-
hello
1+
0 2
2+
1 2
3+
0
4+
1

0 commit comments

Comments
 (0)