Merge pull request #5994 from ytmimi/subtree_sync_with_1.77.0_nightly_2023_12_28

Subtree push with 1.77.0 nightly 2023-12-28
This commit is contained in:
Caleb Cartwright 2023-12-28 21:18:48 -06:00 committed by GitHub
commit 85e21fabf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 68 additions and 63 deletions

View File

@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "nightly-2023-12-12" channel = "nightly-2023-12-28"
components = ["llvm-tools", "rustc-dev"] components = ["llvm-tools", "rustc-dev"]

View File

@ -448,7 +448,7 @@ fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bo
fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool { fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
match expr.kind { match expr.kind {
ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true, ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop { .. } => true,
ast::ExprKind::Loop(..) if version == Version::Two => true, ast::ExprKind::Loop(..) if version == Version::Two => true,
ast::ExprKind::AddrOf(_, _, ref expr) ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Try(ref expr) | ast::ExprKind::Try(ref expr)
@ -473,7 +473,7 @@ fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
| ast::ExprKind::Block(..) | ast::ExprKind::Block(..)
| ast::ExprKind::While(..) | ast::ExprKind::While(..)
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop { .. }
| ast::ExprKind::TryBlock(..) => false, | ast::ExprKind::TryBlock(..) => false,
_ => true, _ => true,
} }

View File

@ -3,7 +3,7 @@ use std::cmp::min;
use itertools::Itertools; use itertools::Itertools;
use rustc_ast::token::{Delimiter, Lit, LitKind}; use rustc_ast::token::{Delimiter, Lit, LitKind};
use rustc_ast::{ast, ptr, token}; use rustc_ast::{ast, ptr, token, ForLoopKind};
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use crate::chains::rewrite_chain; use crate::chains::rewrite_chain;
@ -134,7 +134,7 @@ pub(crate) fn format_expr(
} }
ast::ExprKind::Let(ref pat, ref expr, _span, _) => rewrite_let(context, shape, pat, expr), ast::ExprKind::Let(ref pat, ref expr, _span, _) => rewrite_let(context, shape, pat, expr),
ast::ExprKind::If(..) ast::ExprKind::If(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop { .. }
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::While(..) => to_control_flow(expr, expr_type) | ast::ExprKind::While(..) => to_control_flow(expr, expr_type)
.and_then(|control_flow| control_flow.rewrite(context, shape)), .and_then(|control_flow| control_flow.rewrite(context, shape)),
@ -682,9 +682,15 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<
expr.span, expr.span,
)) ))
} }
ast::ExprKind::ForLoop(ref pat, ref cond, ref block, label) => { ast::ExprKind::ForLoop {
Some(ControlFlow::new_for(pat, cond, block, label, expr.span)) ref pat,
} ref iter,
ref body,
label,
kind,
} => Some(ControlFlow::new_for(
pat, iter, body, label, expr.span, kind,
)),
ast::ExprKind::Loop(ref block, label, _) => { ast::ExprKind::Loop(ref block, label, _) => {
Some(ControlFlow::new_loop(block, label, expr.span)) Some(ControlFlow::new_loop(block, label, expr.span))
} }
@ -771,6 +777,7 @@ impl<'a> ControlFlow<'a> {
block: &'a ast::Block, block: &'a ast::Block,
label: Option<ast::Label>, label: Option<ast::Label>,
span: Span, span: Span,
kind: ForLoopKind,
) -> ControlFlow<'a> { ) -> ControlFlow<'a> {
ControlFlow { ControlFlow {
cond: Some(cond), cond: Some(cond),
@ -778,7 +785,10 @@ impl<'a> ControlFlow<'a> {
else_block: None, else_block: None,
label, label,
pat: Some(pat), pat: Some(pat),
keyword: "for", keyword: match kind {
ForLoopKind::For => "for",
ForLoopKind::ForAwait => "for await",
},
matcher: "", matcher: "",
connector: " in", connector: " in",
allow_single_line: false, allow_single_line: false,
@ -1364,7 +1374,7 @@ pub(crate) fn can_be_overflowed_expr(
|| context.config.overflow_delimited_expr() || context.config.overflow_delimited_expr()
} }
ast::ExprKind::If(..) ast::ExprKind::If(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop { .. }
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::While(..) => { | ast::ExprKind::While(..) => {
context.config.combine_control_expr() && context.use_block_indent() && args_len == 1 context.config.combine_control_expr() && context.use_block_indent() && args_len == 1

View File

@ -666,7 +666,7 @@ impl<'a> FmtVisitor<'a> {
let span = mk_sp(lo, field.span.lo()); let span = mk_sp(lo, field.span.lo());
let variant_body = match field.data { let variant_body = match field.data {
ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => format_struct( ast::VariantData::Tuple(..) | ast::VariantData::Struct { .. } => format_struct(
&context, &context,
&StructParts::from_variant(field, &context), &StructParts::from_variant(field, &context),
self.block_indent, self.block_indent,
@ -1094,7 +1094,7 @@ fn enum_variant_span(variant: &ast::Variant, context: &RewriteContext<'_>) -> Sp
if let Some(ref anon_const) = variant.disr_expr { if let Some(ref anon_const) = variant.disr_expr {
let span_before_consts = variant.span.until(anon_const.value.span); let span_before_consts = variant.span.until(anon_const.value.span);
let hi = match &variant.data { let hi = match &variant.data {
Struct(..) => context Struct { .. } => context
.snippet_provider .snippet_provider
.span_after_last(span_before_consts, "}"), .span_after_last(span_before_consts, "}"),
Tuple(..) => context Tuple(..) => context
@ -1114,12 +1114,12 @@ fn format_struct(
offset: Indent, offset: Indent,
one_line_width: Option<usize>, one_line_width: Option<usize>,
) -> Option<String> { ) -> Option<String> {
match *struct_parts.def { match struct_parts.def {
ast::VariantData::Unit(..) => format_unit_struct(context, struct_parts, offset), ast::VariantData::Unit(..) => format_unit_struct(context, struct_parts, offset),
ast::VariantData::Tuple(ref fields, _) => { ast::VariantData::Tuple(fields, _) => {
format_tuple_struct(context, struct_parts, fields, offset) format_tuple_struct(context, struct_parts, fields, offset)
} }
ast::VariantData::Struct(ref fields, _) => { ast::VariantData::Struct { fields, .. } => {
format_struct_struct(context, struct_parts, fields, offset, one_line_width) format_struct_struct(context, struct_parts, fields, offset, one_line_width)
} }
} }

View File

@ -591,7 +591,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
ast::ExprKind::If(..) => false, ast::ExprKind::If(..) => false,
// We do not allow collapsing a block around expression with condition // We do not allow collapsing a block around expression with condition
// to avoid it being cluttered with match arm. // to avoid it being cluttered with match arm.
ast::ExprKind::ForLoop(..) | ast::ExprKind::While(..) => false, ast::ExprKind::ForLoop { .. } | ast::ExprKind::While(..) => false,
ast::ExprKind::Loop(..) ast::ExprKind::Loop(..)
| ast::ExprKind::Match(..) | ast::ExprKind::Match(..)
| ast::ExprKind::Block(..) | ast::ExprKind::Block(..)

View File

@ -421,7 +421,7 @@ impl<'a> Context<'a> {
// When overflowing the expressions which consists of a control flow // When overflowing the expressions which consists of a control flow
// expression, avoid condition to use multi line. // expression, avoid condition to use multi line.
ast::ExprKind::If(..) ast::ExprKind::If(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop { .. }
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::While(..) | ast::ExprKind::While(..)
| ast::ExprKind::Match(..) => { | ast::ExprKind::Match(..) => {

View File

@ -67,7 +67,7 @@ fn parse_cfg_if_inner<'a>(
Ok(None) => continue, Ok(None) => continue,
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
parser.sess.span_diagnostic.reset_err_count(); parser.sess.dcx.reset_err_count();
return Err( return Err(
"Expected item inside cfg_if block, but failed to parse it as an item", "Expected item inside cfg_if block, but failed to parse it as an item",
); );

View File

@ -16,8 +16,8 @@ pub(crate) fn parse_lazy_static(
($method:ident $(,)* $($arg:expr),* $(,)*) => { ($method:ident $(,)* $($arg:expr),* $(,)*) => {
match parser.$method($($arg,)*) { match parser.$method($($arg,)*) {
Ok(val) => { Ok(val) => {
if parser.sess.span_diagnostic.has_errors().is_some() { if parser.sess.dcx.has_errors().is_some() {
parser.sess.span_diagnostic.reset_err_count(); parser.sess.dcx.reset_err_count();
return None; return None;
} else { } else {
val val
@ -25,7 +25,7 @@ pub(crate) fn parse_lazy_static(
} }
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
parser.sess.span_diagnostic.reset_err_count(); parser.sess.dcx.reset_err_count();
return None; return None;
} }
} }

View File

@ -28,8 +28,8 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
let mut cloned_parser = (*parser).clone(); let mut cloned_parser = (*parser).clone();
match $parser(&mut cloned_parser) { match $parser(&mut cloned_parser) {
Ok(x) => { Ok(x) => {
if parser.sess.span_diagnostic.has_errors().is_some() { if parser.sess.dcx.has_errors().is_some() {
parser.sess.span_diagnostic.reset_err_count(); parser.sess.dcx.reset_err_count();
} else { } else {
// Parsing succeeded. // Parsing succeeded.
*parser = cloned_parser; *parser = cloned_parser;
@ -38,7 +38,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
} }
Err(e) => { Err(e) => {
e.cancel(); e.cancel();
parser.sess.span_diagnostic.reset_err_count(); parser.sess.dcx.reset_err_count();
} }
} }
}; };

View File

@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_errors::emitter::{DynEmitter, Emitter, EmitterWriter}; use rustc_errors::emitter::{DynEmitter, Emitter, EmitterWriter};
use rustc_errors::translation::Translate; use rustc_errors::translation::Translate;
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel}; use rustc_errors::{ColorConfig, DiagCtxt, Diagnostic, Level as DiagnosticLevel};
use rustc_session::parse::ParseSess as RawParseSess; use rustc_session::parse::ParseSess as RawParseSess;
use rustc_span::{ use rustc_span::{
source_map::{FilePathMapping, SourceMap}, source_map::{FilePathMapping, SourceMap},
@ -118,13 +118,13 @@ impl From<Color> for ColorConfig {
} }
} }
fn default_handler( fn default_dcx(
source_map: Lrc<SourceMap>, source_map: Lrc<SourceMap>,
ignore_path_set: Lrc<IgnorePathSet>, ignore_path_set: Lrc<IgnorePathSet>,
can_reset: Lrc<AtomicBool>, can_reset: Lrc<AtomicBool>,
show_parse_errors: bool, show_parse_errors: bool,
color: Color, color: Color,
) -> Handler { ) -> DiagCtxt {
let supports_color = term::stderr().map_or(false, |term| term.supports_color()); let supports_color = term::stderr().map_or(false, |term| term.supports_color());
let emit_color = if supports_color { let emit_color = if supports_color {
ColorConfig::from(color) ColorConfig::from(color)
@ -141,7 +141,7 @@ fn default_handler(
); );
Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone()))) Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
}; };
Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter { DiagCtxt::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
has_non_ignorable_parser_errors: false, has_non_ignorable_parser_errors: false,
source_map, source_map,
emitter, emitter,
@ -159,14 +159,14 @@ impl ParseSess {
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let can_reset_errors = Lrc::new(AtomicBool::new(false)); let can_reset_errors = Lrc::new(AtomicBool::new(false));
let handler = default_handler( let dcx = default_dcx(
Lrc::clone(&source_map), Lrc::clone(&source_map),
Lrc::clone(&ignore_path_set), Lrc::clone(&ignore_path_set),
Lrc::clone(&can_reset_errors), Lrc::clone(&can_reset_errors),
config.show_parse_errors(), config.show_parse_errors(),
config.color(), config.color(),
); );
let parse_sess = RawParseSess::with_span_handler(handler, source_map); let parse_sess = RawParseSess::with_dcx(dcx, source_map);
Ok(ParseSess { Ok(ParseSess {
parse_sess, parse_sess,
@ -218,7 +218,7 @@ impl ParseSess {
} }
pub(crate) fn set_silent_emitter(&mut self) { pub(crate) fn set_silent_emitter(&mut self) {
self.parse_sess.span_diagnostic = Handler::with_emitter(silent_emitter()); self.parse_sess.dcx = DiagCtxt::with_emitter(silent_emitter());
} }
pub(crate) fn span_to_filename(&self, span: Span) -> FileName { pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
@ -284,10 +284,8 @@ impl ParseSess {
// Methods that should be restricted within the parse module. // Methods that should be restricted within the parse module.
impl ParseSess { impl ParseSess {
pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) { pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
for mut diagnostic in diagnostics { for diagnostic in diagnostics {
self.parse_sess self.parse_sess.dcx.emit_diagnostic(diagnostic);
.span_diagnostic
.emit_diagnostic(&mut diagnostic);
} }
} }
@ -296,11 +294,11 @@ impl ParseSess {
} }
pub(super) fn has_errors(&self) -> bool { pub(super) fn has_errors(&self) -> bool {
self.parse_sess.span_diagnostic.has_errors().is_some() self.parse_sess.dcx.has_errors().is_some()
} }
pub(super) fn reset_errors(&self) { pub(super) fn reset_errors(&self) {
self.parse_sess.span_diagnostic.reset_err_count(); self.parse_sess.dcx.reset_err_count();
} }
} }
@ -372,7 +370,7 @@ mod tests {
fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic { fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic {
let mut diag = Diagnostic::new(level, ""); let mut diag = Diagnostic::new(level, "");
diag.message.clear(); diag.messages.clear();
if let Some(span) = span { if let Some(span) = span {
diag.span = span; diag.span = span;
} }

View File

@ -259,9 +259,15 @@ impl Rewrite for Pat {
None, None,
None, None,
), ),
PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => { PatKind::Struct(ref qself, ref path, ref fields, rest) => rewrite_struct_pat(
rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape) qself,
} path,
fields,
rest == ast::PatFieldsRest::Rest,
self.span,
context,
shape,
),
PatKind::MacCall(ref mac) => { PatKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Pat) rewrite_macro(mac, None, context, shape, MacroPosition::Pat)
} }

View File

@ -537,28 +537,19 @@ impl Rewrite for ast::Lifetime {
impl Rewrite for ast::GenericBound { impl Rewrite for ast::GenericBound {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match *self { match *self {
ast::GenericBound::Trait(ref poly_trait_ref, trait_bound_modifier) => { ast::GenericBound::Trait(ref poly_trait_ref, modifiers) => {
let snippet = context.snippet(self.span()); let snippet = context.snippet(self.span());
let has_paren = snippet.starts_with('(') && snippet.ends_with(')'); let has_paren = snippet.starts_with('(') && snippet.ends_with(')');
let rewrite = match trait_bound_modifier { let mut constness = modifiers.constness.as_str().to_string();
ast::TraitBoundModifier::None => poly_trait_ref.rewrite(context, shape), if !constness.is_empty() {
ast::TraitBoundModifier::Maybe => poly_trait_ref constness.push(' ');
.rewrite(context, shape.offset_left(1)?) }
.map(|s| format!("?{}", s)), let polarity = modifiers.polarity.as_str();
ast::TraitBoundModifier::MaybeConst(_) => poly_trait_ref let shape = shape.offset_left(constness.len() + polarity.len())?;
.rewrite(context, shape.offset_left(7)?) poly_trait_ref
.map(|s| format!("~const {}", s)), .rewrite(context, shape)
ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref .map(|s| format!("{constness}{polarity}{s}"))
.rewrite(context, shape.offset_left(8)?) .map(|s| if has_paren { format!("({})", s) } else { s })
.map(|s| format!("~const ?{}", s)),
ast::TraitBoundModifier::Negative => poly_trait_ref
.rewrite(context, shape.offset_left(1)?)
.map(|s| format!("!{}", s)),
ast::TraitBoundModifier::MaybeConstNegative => poly_trait_ref
.rewrite(context, shape.offset_left(8)?)
.map(|s| format!("~const !{}", s)),
};
rewrite.map(|s| if has_paren { format!("({})", s) } else { s })
} }
ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape), ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape),
} }

View File

@ -295,7 +295,7 @@ pub(crate) fn semicolon_for_stmt(
) -> bool { ) -> bool {
match stmt.kind { match stmt.kind {
ast::StmtKind::Semi(ref expr) => match expr.kind { ast::StmtKind::Semi(ref expr) => match expr.kind {
ast::ExprKind::While(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop(..) => { ast::ExprKind::While(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop { .. } => {
false false
} }
ast::ExprKind::Break(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Ret(..) => { ast::ExprKind::Break(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Ret(..) => {
@ -476,7 +476,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::ConstBlock(..) | ast::ExprKind::ConstBlock(..)
| ast::ExprKind::Gen(..) | ast::ExprKind::Gen(..)
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop { .. }
| ast::ExprKind::TryBlock(..) | ast::ExprKind::TryBlock(..)
| ast::ExprKind::Match(..) => repr.contains('\n'), | ast::ExprKind::Match(..) => repr.contains('\n'),
ast::ExprKind::Paren(ref expr) ast::ExprKind::Paren(ref expr)