Skip to content

Commit adf2fa3

Browse files
authored
Merge pull request #1159 from rust-lang/poking
Minor cleanups from re-reading code
2 parents 8323bab + d7606d1 commit adf2fa3

File tree

5 files changed

+124
-118
lines changed

5 files changed

+124
-118
lines changed

compiler/base/orchestrator/src/coordinator.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ where
947947
use versions_error::*;
948948

949949
let [stable, beta, nightly] =
950-
[Channel::Stable, Channel::Beta, Channel::Nightly].map(|c| async move {
950+
[Channel::Stable, Channel::Beta, Channel::Nightly].map(async |c| {
951951
let c = self.select_channel(c).await?;
952952
c.versions().await.map_err(VersionsChannelError::from)
953953
});
@@ -1144,11 +1144,9 @@ where
11441144
let token = mem::take(token);
11451145
token.cancel();
11461146

1147-
let channels = [stable, beta, nightly].map(|c| async {
1148-
match c.take() {
1149-
Some(c) => c.shutdown().await,
1150-
_ => Ok(()),
1151-
}
1147+
let channels = [stable, beta, nightly].map(async |c| match c.take() {
1148+
Some(c) => c.shutdown().await,
1149+
_ => Ok(()),
11521150
});
11531151

11541152
let [stable, beta, nightly] = channels;
@@ -2987,7 +2985,7 @@ mod tests {
29872985
}
29882986
}
29892987

2990-
const MAX_CONCURRENT_TESTS: LazyLock<usize> = LazyLock::new(|| {
2988+
static MAX_CONCURRENT_TESTS: LazyLock<usize> = LazyLock::new(|| {
29912989
env::var("TESTS_MAX_CONCURRENCY")
29922990
.ok()
29932991
.and_then(|v| v.parse().ok())
@@ -3081,7 +3079,7 @@ mod tests {
30813079
(Mode::Release, "[optimized]"),
30823080
];
30833081

3084-
let tests = params.into_iter().map(|(mode, expected)| async move {
3082+
let tests = params.into_iter().map(async |(mode, expected)| {
30853083
let coordinator = new_coordinator();
30863084

30873085
let request = ExecuteRequest {
@@ -3116,8 +3114,10 @@ mod tests {
31163114
];
31173115

31183116
let tests = params.into_iter().flat_map(|(code, works_in)| {
3119-
Edition::ALL.into_iter().zip(works_in).map(
3120-
move |(edition, expected_to_work)| async move {
3117+
Edition::ALL
3118+
.into_iter()
3119+
.zip(works_in)
3120+
.map(async |(edition, expected_to_work)| {
31213121
let coordinator = new_coordinator();
31223122

31233123
let request = ExecuteRequest {
@@ -3137,8 +3137,7 @@ mod tests {
31373137
coordinator.shutdown().await?;
31383138

31393139
Ok::<_, Error>(())
3140-
},
3141-
)
3140+
})
31423141
});
31433142

31443143
try_join_all(tests).with_timeout().await?;
@@ -3157,7 +3156,7 @@ mod tests {
31573156
),
31583157
];
31593158

3160-
let tests = params.into_iter().map(|(crate_type, expected)| async move {
3159+
let tests = params.into_iter().map(async |(crate_type, expected)| {
31613160
let coordinator = new_coordinator();
31623161

31633162
let request = ExecuteRequest {
@@ -3190,7 +3189,7 @@ mod tests {
31903189

31913190
let params = [(false, "Running `"), (true, "Running unittests")];
31923191

3193-
let tests = params.into_iter().map(|(tests, expected)| async move {
3192+
let tests = params.into_iter().map(async |(tests, expected)| {
31943193
let coordinator = new_coordinator();
31953194

31963195
let request = ExecuteRequest {
@@ -3223,7 +3222,7 @@ mod tests {
32233222
(true, "stack backtrace:"),
32243223
];
32253224

3226-
let tests = params.into_iter().map(|(backtrace, expected)| async move {
3225+
let tests = params.into_iter().map(async |(backtrace, expected)| {
32273226
let coordinator = new_coordinator();
32283227

32293228
let request = ExecuteRequest {
@@ -3539,7 +3538,7 @@ mod tests {
35393538
.await
35403539
.unwrap();
35413540

3542-
assert!(response.success, "stderr: {}", stderr);
3541+
assert!(response.success, "stderr: {stderr}");
35433542
assert_contains!(stderr, "Compiling");
35443543
assert_contains!(stderr, "Finished");
35453544

compiler/base/orchestrator/src/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ mod test {
11721172
let next_result = this.0.pop_front().expect("FixedAsyncRead ran out of input");
11731173

11741174
if let Ok(v) = &next_result {
1175-
buf.put_slice(&v);
1175+
buf.put_slice(v);
11761176
}
11771177

11781178
Poll::Ready(next_result.map(drop))

ui/src/gist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl From<octocrab::models::gists::Gist> for Gist {
2323
0 | 1 => files.into_iter().map(|(_, content)| content).collect(),
2424
_ => files
2525
.into_iter()
26-
.map(|(name, content)| format!("// {}\n{}\n\n", name, content))
26+
.map(|(name, content)| format!("// {name}\n{content}\n\n"))
2727
.collect(),
2828
};
2929

ui/src/server_axum.rs

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ use axum_extra::{
2424
headers::{authorization::Bearer, Authorization, CacheControl, ETag, IfNoneMatch},
2525
TypedHeader,
2626
};
27-
use futures::{future::BoxFuture, FutureExt, TryFutureExt};
27+
use futures::{FutureExt, TryFutureExt};
2828
use orchestrator::coordinator::{self, CoordinatorFactory, DockerBackend, TRACKED_CONTAINERS};
2929
use snafu::prelude::*;
3030
use std::{
3131
convert::TryInto,
32-
future::Future,
3332
mem, path,
3433
str::FromStr,
3534
sync::{Arc, LazyLock},
@@ -134,7 +133,8 @@ pub(crate) async fn serve(config: Config) {
134133
let x_request_id = HeaderName::from_static("x-request-id");
135134

136135
// Basic access logging
137-
app = app.layer(
136+
app = app.layer({
137+
let x_request_id = x_request_id.clone();
138138
TraceLayer::new_for_http().make_span_with(move |req: &Request<_>| {
139139
const REQUEST_ID: &str = "request_id";
140140

@@ -152,17 +152,15 @@ pub(crate) async fn serve(config: Config) {
152152
}
153153

154154
span
155-
}),
156-
);
157-
158-
let x_request_id = HeaderName::from_static("x-request-id");
155+
})
156+
});
159157

160158
// propagate `x-request-id` headers from request to response
161159
app = app.layer(PropagateRequestIdLayer::new(x_request_id.clone()));
162160

163161
app = app.layer(SetRequestIdLayer::new(
164162
x_request_id.clone(),
165-
MakeRequestUuid::default(),
163+
MakeRequestUuid,
166164
));
167165

168166
let server_socket_addr = config.server_socket_addr();
@@ -208,16 +206,15 @@ async fn rewrite_help_as_index(
208206
next.run(req).await
209207
}
210208

211-
async fn attempt_record_request<T, RFut, RT, RE>(
209+
async fn attempt_record_request<R, T, E>(
212210
db: Handle,
213-
req: T,
214-
f: impl FnOnce(T) -> RFut,
215-
) -> Result<RT, RE>
211+
req: R,
212+
f: impl AsyncFnOnce(R) -> Result<T, E>,
213+
) -> Result<T, E>
216214
where
217-
T: HasEndpoint + serde::Serialize,
218-
RFut: Future<Output = Result<RT, RE>>,
215+
R: HasEndpoint + serde::Serialize,
219216
{
220-
let category = format!("http.{}", <&str>::from(T::ENDPOINT));
217+
let category = format!("http.{}", <&str>::from(R::ENDPOINT));
221218
let payload = serde_json::to_string(&req).unwrap_or_else(|_| String::from("<invalid JSON>"));
222219
let guard = db.start_with_guard(category, payload).await;
223220

@@ -233,9 +230,9 @@ async fn evaluate(
233230
Extension(db): Extension<Handle>,
234231
Json(req): Json<api::EvaluateRequest>,
235232
) -> Result<Json<api::EvaluateResponse>> {
236-
attempt_record_request(db, req, |req| async {
237-
with_coordinator(&factory.0, req, |c, req| {
238-
c.execute(req).context(EvaluateSnafu).boxed()
233+
attempt_record_request(db, req, async |req| {
234+
with_coordinator(&factory.0, req, async |c, req| {
235+
c.execute(req).context(EvaluateSnafu).await
239236
})
240237
.await
241238
.map(Json)
@@ -248,9 +245,9 @@ async fn compile(
248245
Extension(db): Extension<Handle>,
249246
Json(req): Json<api::CompileRequest>,
250247
) -> Result<Json<api::CompileResponse>> {
251-
attempt_record_request(db, req, |req| async {
252-
with_coordinator(&factory.0, req, |c, req| {
253-
c.compile(req).context(CompileSnafu).boxed()
248+
attempt_record_request(db, req, async |req| {
249+
with_coordinator(&factory.0, req, async |c, req| {
250+
c.compile(req).context(CompileSnafu).await
254251
})
255252
.await
256253
.map(Json)
@@ -263,9 +260,9 @@ async fn execute(
263260
Extension(db): Extension<Handle>,
264261
Json(req): Json<api::ExecuteRequest>,
265262
) -> Result<Json<api::ExecuteResponse>> {
266-
attempt_record_request(db, req, |req| async {
267-
with_coordinator(&factory.0, req, |c, req| {
268-
c.execute(req).context(ExecuteSnafu).boxed()
263+
attempt_record_request(db, req, async |req| {
264+
with_coordinator(&factory.0, req, async |c, req| {
265+
c.execute(req).context(ExecuteSnafu).await
269266
})
270267
.await
271268
.map(Json)
@@ -278,9 +275,9 @@ async fn format(
278275
Extension(db): Extension<Handle>,
279276
Json(req): Json<api::FormatRequest>,
280277
) -> Result<Json<api::FormatResponse>> {
281-
attempt_record_request(db, req, |req| async {
282-
with_coordinator(&factory.0, req, |c, req| {
283-
c.format(req).context(FormatSnafu).boxed()
278+
attempt_record_request(db, req, async |req| {
279+
with_coordinator(&factory.0, req, async |c, req| {
280+
c.format(req).context(FormatSnafu).await
284281
})
285282
.await
286283
.map(Json)
@@ -293,9 +290,9 @@ async fn clippy(
293290
Extension(db): Extension<Handle>,
294291
Json(req): Json<api::ClippyRequest>,
295292
) -> Result<Json<api::ClippyResponse>> {
296-
attempt_record_request(db, req, |req| async {
297-
with_coordinator(&factory.0, req, |c, req| {
298-
c.clippy(req).context(ClippySnafu).boxed()
293+
attempt_record_request(db, req, async |req| {
294+
with_coordinator(&factory.0, req, async |c, req| {
295+
c.clippy(req).context(ClippySnafu).await
299296
})
300297
.await
301298
.map(Json)
@@ -308,9 +305,9 @@ async fn miri(
308305
Extension(db): Extension<Handle>,
309306
Json(req): Json<api::MiriRequest>,
310307
) -> Result<Json<api::MiriResponse>> {
311-
attempt_record_request(db, req, |req| async {
312-
with_coordinator(&factory.0, req, |c, req| {
313-
c.miri(req).context(MiriSnafu).boxed()
308+
attempt_record_request(db, req, async |req| {
309+
with_coordinator(&factory.0, req, async |c, req| {
310+
c.miri(req).context(MiriSnafu).await
314311
})
315312
.await
316313
.map(Json)
@@ -323,9 +320,9 @@ async fn macro_expansion(
323320
Extension(db): Extension<Handle>,
324321
Json(req): Json<api::MacroExpansionRequest>,
325322
) -> Result<Json<api::MacroExpansionResponse>> {
326-
attempt_record_request(db, req, |req| async {
327-
with_coordinator(&factory.0, req, |c, req| {
328-
c.macro_expansion(req).context(MacroExpansionSnafu).boxed()
323+
attempt_record_request(db, req, async |req| {
324+
with_coordinator(&factory.0, req, async |c, req| {
325+
c.macro_expansion(req).context(MacroExpansionSnafu).await
329326
})
330327
.await
331328
.map(Json)
@@ -433,10 +430,10 @@ impl Outcome {
433430
}
434431
}
435432

436-
async fn with_coordinator<WebReq, WebResp, Req, Resp, F>(
433+
async fn with_coordinator<WebReq, WebResp, Req, Resp>(
437434
factory: &CoordinatorFactory,
438435
req: WebReq,
439-
f: F,
436+
f: impl AsyncFnOnce(&coordinator::Coordinator<DockerBackend>, Req) -> Result<Resp>,
440437
) -> Result<WebResp>
441438
where
442439
WebReq: TryInto<Req>,
@@ -445,8 +442,6 @@ where
445442
Req: HasLabelsCore,
446443
Resp: Into<WebResp>,
447444
Resp: IsSuccess,
448-
for<'f> F:
449-
FnOnce(&'f coordinator::Coordinator<DockerBackend>, Req) -> BoxFuture<'f, Result<Resp>>,
450445
{
451446
let coordinator = factory.build();
452447

@@ -525,9 +520,8 @@ where
525520
.with_max_age(SANDBOX_CACHE_TIME_TO_LIVE)
526521
.with_public();
527522

528-
let use_fresh = if_none_match.map_or(true, |if_none_match| {
529-
if_none_match.0.precondition_passes(&etag)
530-
});
523+
let use_fresh =
524+
if_none_match.is_none_or(|if_none_match| if_none_match.0.precondition_passes(&etag));
531525

532526
let etag = TypedHeader(etag);
533527
let cache_control = TypedHeader(cache_control);
@@ -617,7 +611,7 @@ async fn nowebsocket(Json(req): Json<NoWebSocketRequest>) {
617611
}
618612

619613
static WS_ERRORS: LazyLock<std::sync::Mutex<std::collections::HashMap<String, usize>>> =
620-
LazyLock::new(|| Default::default());
614+
LazyLock::new(Default::default);
621615

622616
fn record_websocket_error(error: String) {
623617
*WS_ERRORS

0 commit comments

Comments
 (0)