Skip to content
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

Subtree push 2023-12-12 #5980

Merged
merged 39 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aac383e
Use builder pattern instead of lots of arguments for `EmitterWriter::…
oli-obk Jul 25, 2023
35d875a
Fix rustfmt dep
mu001999 Aug 2, 2023
14101ed
Remove `MacDelimiter`.
nnethercote Aug 1, 2023
4cc22af
Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
matthiaskrgr Aug 3, 2023
aca22c7
Improve spans for indexing expressions
Noratrieb Aug 3, 2023
e3d6bf8
Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
bors Aug 4, 2023
6e87f86
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
matthiaskrgr Aug 4, 2023
327903e
Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
bors Aug 4, 2023
af6a6a3
Parse unnamed fields and anonymous structs or unions
frank-king Aug 23, 2023
eb349e3
Use conditional synchronization for Lock
Zoxc Oct 31, 2020
45e19aa
Use relative positions inside a SourceFile.
cjgillot Sep 3, 2023
e0d90cc
Update tools and fulldeps tests
matthewjasper Sep 8, 2023
f867858
Fix spans for comments in rustfmt
compiler-errors Oct 4, 2023
1b9dd4b
s/generator/coroutine/
oli-obk Oct 19, 2023
7a20da3
Rename lots of files that had `generator` in their name
oli-obk Oct 20, 2023
4335c28
use visibility to check unused imports and delete some stmts
bvanjoi Oct 15, 2023
04bd720
Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-…
calebcartwright Oct 23, 2023
d5bf53b
Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
bors Oct 23, 2023
a3be235
Add gen blocks to ast and do some broken ast lowering
oli-obk Oct 20, 2023
494560c
fixes for rustfmt + ast visitor
dnbln Nov 4, 2023
c043d01
Update itertools to 0.11.
nnethercote Nov 13, 2023
24ce52a
Add `Span` to `TraitBoundModifier`
fee1-dead Nov 24, 2023
d84d8d2
Rework `ast::BinOpKind::to_string` and `ast::UnOp::to_string`.
nnethercote Nov 27, 2023
f2f2431
Add `never_patterns` feature gate
Nadrieril Nov 22, 2023
1ab7fc9
Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compile…
matthiaskrgr Nov 29, 2023
a445ba8
Parse a pattern with no arm
Nadrieril Nov 27, 2023
97fdae1
Merge Async and Gen into CoroutineKind
eholk Nov 30, 2023
13d284d
Option<CoroutineKind>
eholk Dec 1, 2023
f114bb4
Address code review feedback
eholk Dec 4, 2023
77bb46d
Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-er…
bors Dec 8, 2023
6ebb66c
coro_kind -> coroutine_kind
compiler-errors Dec 5, 2023
3ffacf7
Make some matches exhaustive to avoid bugs, fix tools
compiler-errors Dec 5, 2023
9c809ce
Auto merge of #118420 - compiler-errors:async-gen, r=eholk
bors Dec 8, 2023
1b9bf8a
remove redundant imports
surechen Nov 10, 2023
b9ad024
Remove edition umbrella features.
ehuss Dec 10, 2023
1cb804b
Add spacing information to delimiters.
nnethercote Oct 12, 2023
948c904
Rollup merge of #118802 - ehuss:remove-edition-preview, r=TaKO8Ki
GuillaumeGomez Dec 11, 2023
227e361
Merge remote-tracking branch 'upstream/master' into subtree_push_2023…
ytmimi Dec 12, 2023
03510f3
chore: bump to the nightly 2023-12-12 toolchain
ytmimi Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ diff = "0.1"
dirs = "4.0"
getopts = "0.2"
ignore = "0.4"
itertools = "0.10"
itertools = "0.11"
lazy_static = "1.4"
regex = "1.7"
serde = { version = "1.0.160", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-10-22"
channel = "nightly-2023-12-12"
components = ["llvm-tools", "rustc-dev"]
34 changes: 24 additions & 10 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure(
binder: &ast::ClosureBinder,
constness: ast::Const,
capture: ast::CaptureBy,
is_async: &ast::Async,
coroutine_kind: &Option<ast::CoroutineKind>,
movability: ast::Movability,
fn_decl: &ast::FnDecl,
body: &ast::Expr,
Expand All @@ -40,7 +40,16 @@ pub(crate) fn rewrite_closure(
debug!("rewrite_closure {:?}", body);

let (prefix, extra_offset) = rewrite_closure_fn_decl(
binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape,
binder,
constness,
capture,
coroutine_kind,
movability,
fn_decl,
body,
span,
context,
shape,
)?;
// 1 = space between `|...|` and body.
let body_shape = shape.offset_left(extra_offset)?;
Expand Down Expand Up @@ -188,7 +197,7 @@ fn rewrite_closure_expr(
fn allow_multi_line(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::Match(..)
| ast::ExprKind::Async(..)
| ast::ExprKind::Gen(..)
| ast::ExprKind::Block(..)
| ast::ExprKind::TryBlock(..)
| ast::ExprKind::Loop(..)
Expand Down Expand Up @@ -233,7 +242,7 @@ fn rewrite_closure_fn_decl(
binder: &ast::ClosureBinder,
constness: ast::Const,
capture: ast::CaptureBy,
asyncness: &ast::Async,
coroutine_kind: &Option<ast::CoroutineKind>,
movability: ast::Movability,
fn_decl: &ast::FnDecl,
body: &ast::Expr,
Expand Down Expand Up @@ -263,16 +272,21 @@ fn rewrite_closure_fn_decl(
} else {
""
};
let is_async = if asyncness.is_async() { "async " } else { "" };
let mover = if capture == ast::CaptureBy::Value {
let coro = match coroutine_kind {
Some(ast::CoroutineKind::Async { .. }) => "async ",
Some(ast::CoroutineKind::Gen { .. }) => "gen ",
Some(ast::CoroutineKind::AsyncGen { .. }) => "async gen ",
None => "",
};
let mover = if matches!(capture, ast::CaptureBy::Value { .. }) {
"move "
} else {
""
};
// 4 = "|| {".len(), which is overconservative when the closure consists of
// a single expression.
let nested_shape = shape
.shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())?
.shrink_left(binder.len() + const_.len() + immovable.len() + coro.len() + mover.len())?
.sub_width(4)?;

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

if !ret_str.is_empty() {
if prefix.contains('\n') {
Expand Down Expand Up @@ -339,7 +353,7 @@ pub(crate) fn rewrite_last_closure(
ref binder,
constness,
capture_clause,
ref asyncness,
ref coroutine_kind,
movability,
ref fn_decl,
ref body,
Expand All @@ -360,7 +374,7 @@ pub(crate) fn rewrite_last_closure(
binder,
constness,
capture_clause,
asyncness,
coroutine_kind,
movability,
fn_decl,
body,
Expand Down
3 changes: 1 addition & 2 deletions src/comment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Formatting and tools for comments.

use std::{self, borrow::Cow, iter};
use std::{borrow::Cow, iter};

use itertools::{multipeek, MultiPeek};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -1847,7 +1847,6 @@ fn remove_comment_header(comment: &str) -> &str {
#[cfg(test)]
mod test {
use super::*;
use crate::shape::{Indent, Shape};

#[test]
fn char_classes() {
Expand Down
2 changes: 1 addition & 1 deletion src/config/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;
use std::{cmp, fmt, iter, str};

use rustc_data_structures::sync::Lrc;
use rustc_span::{self, SourceFile};
use rustc_span::SourceFile;
use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
use serde_json as json;
use thiserror::Error;
Expand Down
2 changes: 0 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cell::Cell;
use std::default::Default;
use std::fs::File;
use std::io::{Error, ErrorKind, Read};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1018,7 +1017,6 @@ make_backup = false
#[cfg(test)]
mod partially_unstable_option {
use super::mock::{Config, PartiallyUnstableOption};
use super::*;

/// From the command line, we can override with a stable variant.
#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/config/options.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_imports)]

use std::collections::{hash_set, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
Expand Down
1 change: 0 additions & 1 deletion src/emitter/checkstyle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use self::xml::XmlEscaped;
use super::*;
use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch};
use std::io::{self, Write};

mod xml;

Expand Down
2 changes: 0 additions & 2 deletions src/emitter/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ impl Emitter for DiffEmitter {
#[cfg(test)]
mod tests {
use super::*;
use crate::config::Config;
use crate::FileName;
use std::path::PathBuf;

#[test]
Expand Down
2 changes: 0 additions & 2 deletions src/emitter/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::*;
use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch};
use serde::Serialize;
use serde_json::to_string as to_json_string;
use std::io::{self, Write};

#[derive(Debug, Default)]
pub(crate) struct JsonEmitter {
Expand Down Expand Up @@ -106,7 +105,6 @@ impl JsonEmitter {
#[cfg(test)]
mod tests {
use super::*;
use crate::FileName;
use std::path::PathBuf;

#[test]
Expand Down
1 change: 0 additions & 1 deletion src/emitter/modified_lines.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::rustfmt_diff::{make_diff, ModifiedLines};
use std::io::Write;

#[derive(Debug, Default)]
pub(crate) struct ModifiedLinesEmitter;
Expand Down
1 change: 0 additions & 1 deletion src/emitter/stdout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::config::Verbosity;
use std::io::Write;

#[derive(Debug)]
pub(crate) struct StdoutEmitter {
Expand Down
14 changes: 7 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub(crate) fn format_expr(
&cl.binder,
cl.constness,
cl.capture_clause,
&cl.asyncness,
&cl.coroutine_kind,
cl.movability,
&cl.fn_decl,
&cl.body,
Expand Down Expand Up @@ -367,15 +367,15 @@ pub(crate) fn format_expr(
))
}
}
ast::ExprKind::Async(capture_by, ref block) => {
let mover = if capture_by == ast::CaptureBy::Value {
ast::ExprKind::Gen(capture_by, ref block, ref kind) => {
let mover = if matches!(capture_by, ast::CaptureBy::Value { .. }) {
"move "
} else {
""
};
if let rw @ Some(_) = rewrite_single_line_block(
context,
format!("async {mover}").as_str(),
format!("{kind} {mover}").as_str(),
block,
Some(&expr.attrs),
None,
Expand All @@ -386,7 +386,7 @@ pub(crate) fn format_expr(
// 6 = `async `
let budget = shape.width.saturating_sub(6);
Some(format!(
"async {mover}{}",
"{kind} {mover}{}",
rewrite_block(
block,
Some(&expr.attrs),
Expand Down Expand Up @@ -1371,7 +1371,7 @@ pub(crate) fn can_be_overflowed_expr(
}

// Handle always block-like expressions
ast::ExprKind::Async(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true,
ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true,

// Handle `[]` and `{}`-like expressions
ast::ExprKind::Array(..) | ast::ExprKind::Struct(..) => {
Expand Down Expand Up @@ -1933,7 +1933,7 @@ fn rewrite_unary_op(
shape: Shape,
) -> Option<String> {
// For some reason, an UnOp is not spanned like BinOp!
rewrite_unary_prefix(context, ast::UnOp::to_string(op), expr, shape)
rewrite_unary_prefix(context, op.as_str(), expr, shape)
}

pub(crate) enum RhsAssignKind<'ast> {
Expand Down
2 changes: 1 addition & 1 deletion src/ignore_path.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ignore::{self, gitignore};
use ignore::gitignore;

use crate::config::{FileName, IgnoreList};

Expand Down
1 change: 0 additions & 1 deletion src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,6 @@ enum SharedPrefix {
#[cfg(test)]
mod test {
use super::*;
use rustc_span::DUMMY_SP;

// Parse the path part of an import. This parser is not robust and is only
// suitable for use in a test harness.
Expand Down
9 changes: 5 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub(crate) struct FnSig<'a> {
decl: &'a ast::FnDecl,
generics: &'a ast::Generics,
ext: ast::Extern,
is_async: Cow<'a, ast::Async>,
coroutine_kind: Cow<'a, Option<ast::CoroutineKind>>,
constness: ast::Const,
defaultness: ast::Defaultness,
unsafety: ast::Unsafe,
Expand All @@ -302,7 +302,7 @@ impl<'a> FnSig<'a> {
) -> FnSig<'a> {
FnSig {
unsafety: method_sig.header.unsafety,
is_async: Cow::Borrowed(&method_sig.header.asyncness),
coroutine_kind: Cow::Borrowed(&method_sig.header.coroutine_kind),
constness: method_sig.header.constness,
defaultness: ast::Defaultness::Final,
ext: method_sig.header.ext,
Expand All @@ -328,7 +328,7 @@ impl<'a> FnSig<'a> {
generics,
ext: fn_sig.header.ext,
constness: fn_sig.header.constness,
is_async: Cow::Borrowed(&fn_sig.header.asyncness),
coroutine_kind: Cow::Borrowed(&fn_sig.header.coroutine_kind),
defaultness,
unsafety: fn_sig.header.unsafety,
visibility: vis,
Expand All @@ -343,7 +343,8 @@ impl<'a> FnSig<'a> {
result.push_str(&*format_visibility(context, self.visibility));
result.push_str(format_defaultness(self.defaultness));
result.push_str(format_constness(self.constness));
result.push_str(format_async(&self.is_async));
self.coroutine_kind
.map(|coroutine_kind| result.push_str(format_coro(&coroutine_kind)));
result.push_str(format_unsafety(self.unsafety));
result.push_str(&format_extern(
self.ext,
Expand Down
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ struct MacroArgParser {
fn last_tok(tt: &TokenTree) -> Token {
match *tt {
TokenTree::Token(ref t, _) => t.clone(),
TokenTree::Delimited(delim_span, delim, _) => Token {
TokenTree::Delimited(delim_span, _, delim, _) => Token {
kind: TokenKind::CloseDelim(delim),
span: delim_span.close,
},
Expand Down Expand Up @@ -925,7 +925,7 @@ impl MacroArgParser {
self.add_meta_variable(&mut iter)?;
}
TokenTree::Token(ref t, _) => self.update_buffer(t),
&TokenTree::Delimited(_delimited_span, delimited, ref tts) => {
&TokenTree::Delimited(_dspan, _spacing, delimited, ref tts) => {
if !self.buf.is_empty() {
if next_space(&self.last_tok.kind) == SpaceState::Always {
self.add_separator();
Expand Down Expand Up @@ -1167,7 +1167,7 @@ impl<'a> MacroParser<'a> {
let tok = self.toks.next()?;
let (lo, args_paren_kind) = match tok {
TokenTree::Token(..) => return None,
&TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d),
&TokenTree::Delimited(delimited_span, _, d, _) => (delimited_span.open.lo(), d),
};
let args = TokenStream::new(vec![tok.clone()]);
match self.toks.next()? {
Expand Down
8 changes: 4 additions & 4 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn rewrite_match_arm(
) -> Option<String> {
let (missing_span, attrs_str) = if !arm.attrs.is_empty() {
if contains_skip(&arm.attrs) {
let (_, body) = flatten_arm_body(context, &arm.body, None);
let (_, body) = flatten_arm_body(context, arm.body.as_deref()?, None);
// `arm.span()` does not include trailing comma, add it manually.
return Some(format!(
"{}{}",
Expand All @@ -246,7 +246,7 @@ fn rewrite_match_arm(
};

// Patterns
let pat_shape = match &arm.body.kind {
let pat_shape = match &arm.body.as_ref()?.kind {
ast::ExprKind::Block(_, Some(label)) => {
// Some block with a label ` => 'label: {`
// 7 = ` => : {`
Expand Down Expand Up @@ -280,10 +280,10 @@ fn rewrite_match_arm(
false,
)?;

let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.span().lo());
let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.as_ref()?.span().lo());
rewrite_match_body(
context,
&arm.body,
arm.body.as_ref()?,
&lhs_str,
shape,
guard_str.contains('\n'),
Expand Down
2 changes: 1 addition & 1 deletion src/pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl FlattenPair for ast::Expr {
if let Some(pop) = stack.pop() {
match pop.kind {
ast::ExprKind::Binary(op, _, ref rhs) => {
separators.push(op.node.to_string());
separators.push(op.node.as_str());
node = rhs;
}
_ => unreachable!(),
Expand Down
Loading
Loading