Skip to content

Commit 2019676

Browse files
Merge pull request #5980 from ytmimi/subtree_push_2023_12_12
Subtree push 2023-12-12
2 parents 2174e60 + 03510f3 commit 2019676

29 files changed

+75
-61
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ diff = "0.1"
4343
dirs = "4.0"
4444
getopts = "0.2"
4545
ignore = "0.4"
46-
itertools = "0.10"
46+
itertools = "0.11"
4747
lazy_static = "1.4"
4848
regex = "1.7"
4949
serde = { version = "1.0.160", features = ["derive"] }

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-10-22"
2+
channel = "nightly-2023-12-12"
33
components = ["llvm-tools", "rustc-dev"]

src/closures.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure(
2929
binder: &ast::ClosureBinder,
3030
constness: ast::Const,
3131
capture: ast::CaptureBy,
32-
is_async: &ast::Async,
32+
coroutine_kind: &Option<ast::CoroutineKind>,
3333
movability: ast::Movability,
3434
fn_decl: &ast::FnDecl,
3535
body: &ast::Expr,
@@ -40,7 +40,16 @@ pub(crate) fn rewrite_closure(
4040
debug!("rewrite_closure {:?}", body);
4141

4242
let (prefix, extra_offset) = rewrite_closure_fn_decl(
43-
binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape,
43+
binder,
44+
constness,
45+
capture,
46+
coroutine_kind,
47+
movability,
48+
fn_decl,
49+
body,
50+
span,
51+
context,
52+
shape,
4453
)?;
4554
// 1 = space between `|...|` and body.
4655
let body_shape = shape.offset_left(extra_offset)?;
@@ -188,7 +197,7 @@ fn rewrite_closure_expr(
188197
fn allow_multi_line(expr: &ast::Expr) -> bool {
189198
match expr.kind {
190199
ast::ExprKind::Match(..)
191-
| ast::ExprKind::Async(..)
200+
| ast::ExprKind::Gen(..)
192201
| ast::ExprKind::Block(..)
193202
| ast::ExprKind::TryBlock(..)
194203
| ast::ExprKind::Loop(..)
@@ -233,7 +242,7 @@ fn rewrite_closure_fn_decl(
233242
binder: &ast::ClosureBinder,
234243
constness: ast::Const,
235244
capture: ast::CaptureBy,
236-
asyncness: &ast::Async,
245+
coroutine_kind: &Option<ast::CoroutineKind>,
237246
movability: ast::Movability,
238247
fn_decl: &ast::FnDecl,
239248
body: &ast::Expr,
@@ -263,16 +272,21 @@ fn rewrite_closure_fn_decl(
263272
} else {
264273
""
265274
};
266-
let is_async = if asyncness.is_async() { "async " } else { "" };
267-
let mover = if capture == ast::CaptureBy::Value {
275+
let coro = match coroutine_kind {
276+
Some(ast::CoroutineKind::Async { .. }) => "async ",
277+
Some(ast::CoroutineKind::Gen { .. }) => "gen ",
278+
Some(ast::CoroutineKind::AsyncGen { .. }) => "async gen ",
279+
None => "",
280+
};
281+
let mover = if matches!(capture, ast::CaptureBy::Value { .. }) {
268282
"move "
269283
} else {
270284
""
271285
};
272286
// 4 = "|| {".len(), which is overconservative when the closure consists of
273287
// a single expression.
274288
let nested_shape = shape
275-
.shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())?
289+
.shrink_left(binder.len() + const_.len() + immovable.len() + coro.len() + mover.len())?
276290
.sub_width(4)?;
277291

278292
// 1 = |
@@ -310,7 +324,7 @@ fn rewrite_closure_fn_decl(
310324
.tactic(tactic)
311325
.preserve_newline(true);
312326
let list_str = write_list(&item_vec, &fmt)?;
313-
let mut prefix = format!("{binder}{const_}{immovable}{is_async}{mover}|{list_str}|");
327+
let mut prefix = format!("{binder}{const_}{immovable}{coro}{mover}|{list_str}|");
314328

315329
if !ret_str.is_empty() {
316330
if prefix.contains('\n') {
@@ -339,7 +353,7 @@ pub(crate) fn rewrite_last_closure(
339353
ref binder,
340354
constness,
341355
capture_clause,
342-
ref asyncness,
356+
ref coroutine_kind,
343357
movability,
344358
ref fn_decl,
345359
ref body,
@@ -360,7 +374,7 @@ pub(crate) fn rewrite_last_closure(
360374
binder,
361375
constness,
362376
capture_clause,
363-
asyncness,
377+
coroutine_kind,
364378
movability,
365379
fn_decl,
366380
body,

src/comment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Formatting and tools for comments.
22

3-
use std::{self, borrow::Cow, iter};
3+
use std::{borrow::Cow, iter};
44

55
use itertools::{multipeek, MultiPeek};
66
use lazy_static::lazy_static;
@@ -1847,7 +1847,6 @@ fn remove_comment_header(comment: &str) -> &str {
18471847
#[cfg(test)]
18481848
mod test {
18491849
use super::*;
1850-
use crate::shape::{Indent, Shape};
18511850

18521851
#[test]
18531852
fn char_classes() {

src/config/file_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66
use std::{cmp, fmt, iter, str};
77

88
use rustc_data_structures::sync::Lrc;
9-
use rustc_span::{self, SourceFile};
9+
use rustc_span::SourceFile;
1010
use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
1111
use serde_json as json;
1212
use thiserror::Error;

src/config/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cell::Cell;
2-
use std::default::Default;
32
use std::fs::File;
43
use std::io::{Error, ErrorKind, Read};
54
use std::path::{Path, PathBuf};
@@ -1018,7 +1017,6 @@ make_backup = false
10181017
#[cfg(test)]
10191018
mod partially_unstable_option {
10201019
use super::mock::{Config, PartiallyUnstableOption};
1021-
use super::*;
10221020

10231021
/// From the command line, we can override with a stable variant.
10241022
#[test]

src/config/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_imports)]
2+
13
use std::collections::{hash_set, HashSet};
24
use std::fmt;
35
use std::path::{Path, PathBuf};

src/emitter/checkstyle.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use self::xml::XmlEscaped;
22
use super::*;
33
use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch};
4-
use std::io::{self, Write};
54

65
mod xml;
76

src/emitter/diff.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ impl Emitter for DiffEmitter {
5151
#[cfg(test)]
5252
mod tests {
5353
use super::*;
54-
use crate::config::Config;
55-
use crate::FileName;
5654
use std::path::PathBuf;
5755

5856
#[test]

0 commit comments

Comments
 (0)