Skip to content

Commit

Permalink
Merge pull request rust-lang#5994 from ytmimi/subtree_sync_with_1.77.…
Browse files Browse the repository at this point in the history
…0_nightly_2023_12_28

Subtree push with 1.77.0 nightly 2023-12-28
  • Loading branch information
calebcartwright authored Dec 29, 2023
2 parents d86fc1b + 621904f commit 85e21fa
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 63 deletions.
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-12-12"
channel = "nightly-2023-12-28"
components = ["llvm-tools", "rustc-dev"]
4 changes: 2 additions & 2 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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::AddrOf(_, _, ref expr)
| ast::ExprKind::Try(ref expr)
Expand All @@ -473,7 +473,7 @@ fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
| ast::ExprKind::Block(..)
| ast::ExprKind::While(..)
| ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::ForLoop { .. }
| ast::ExprKind::TryBlock(..) => false,
_ => true,
}
Expand Down
24 changes: 17 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::min;

use itertools::Itertools;
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 crate::chains::rewrite_chain;
Expand Down Expand Up @@ -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::If(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::ForLoop { .. }
| ast::ExprKind::Loop(..)
| ast::ExprKind::While(..) => to_control_flow(expr, expr_type)
.and_then(|control_flow| control_flow.rewrite(context, shape)),
Expand Down Expand Up @@ -682,9 +682,15 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<
expr.span,
))
}
ast::ExprKind::ForLoop(ref pat, ref cond, ref block, label) => {
Some(ControlFlow::new_for(pat, cond, block, label, expr.span))
}
ast::ExprKind::ForLoop {
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, _) => {
Some(ControlFlow::new_loop(block, label, expr.span))
}
Expand Down Expand Up @@ -771,14 +777,18 @@ impl<'a> ControlFlow<'a> {
block: &'a ast::Block,
label: Option<ast::Label>,
span: Span,
kind: ForLoopKind,
) -> ControlFlow<'a> {
ControlFlow {
cond: Some(cond),
block,
else_block: None,
label,
pat: Some(pat),
keyword: "for",
keyword: match kind {
ForLoopKind::For => "for",
ForLoopKind::ForAwait => "for await",
},
matcher: "",
connector: " in",
allow_single_line: false,
Expand Down Expand Up @@ -1364,7 +1374,7 @@ pub(crate) fn can_be_overflowed_expr(
|| context.config.overflow_delimited_expr()
}
ast::ExprKind::If(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::ForLoop { .. }
| ast::ExprKind::Loop(..)
| ast::ExprKind::While(..) => {
context.config.combine_control_expr() && context.use_block_indent() && args_len == 1
Expand Down
10 changes: 5 additions & 5 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl<'a> FmtVisitor<'a> {
let span = mk_sp(lo, field.span.lo());

let variant_body = match field.data {
ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => format_struct(
ast::VariantData::Tuple(..) | ast::VariantData::Struct { .. } => format_struct(
&context,
&StructParts::from_variant(field, &context),
self.block_indent,
Expand Down Expand Up @@ -1094,7 +1094,7 @@ fn enum_variant_span(variant: &ast::Variant, context: &RewriteContext<'_>) -> Sp
if let Some(ref anon_const) = variant.disr_expr {
let span_before_consts = variant.span.until(anon_const.value.span);
let hi = match &variant.data {
Struct(..) => context
Struct { .. } => context
.snippet_provider
.span_after_last(span_before_consts, "}"),
Tuple(..) => context
Expand All @@ -1114,12 +1114,12 @@ fn format_struct(
offset: Indent,
one_line_width: Option<usize>,
) -> Option<String> {
match *struct_parts.def {
match struct_parts.def {
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)
}
ast::VariantData::Struct(ref fields, _) => {
ast::VariantData::Struct { fields, .. } => {
format_struct_struct(context, struct_parts, fields, offset, one_line_width)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
ast::ExprKind::If(..) => false,
// We do not allow collapsing a block around expression with condition
// 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::Match(..)
| ast::ExprKind::Block(..)
Expand Down
2 changes: 1 addition & 1 deletion src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl<'a> Context<'a> {
// When overflowing the expressions which consists of a control flow
// expression, avoid condition to use multi line.
ast::ExprKind::If(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::ForLoop { .. }
| ast::ExprKind::Loop(..)
| ast::ExprKind::While(..)
| ast::ExprKind::Match(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/parse/macros/cfg_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn parse_cfg_if_inner<'a>(
Ok(None) => continue,
Err(err) => {
err.cancel();
parser.sess.span_diagnostic.reset_err_count();
parser.sess.dcx.reset_err_count();
return Err(
"Expected item inside cfg_if block, but failed to parse it as an item",
);
Expand Down
6 changes: 3 additions & 3 deletions src/parse/macros/lazy_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ pub(crate) fn parse_lazy_static(
($method:ident $(,)* $($arg:expr),* $(,)*) => {
match parser.$method($($arg,)*) {
Ok(val) => {
if parser.sess.span_diagnostic.has_errors().is_some() {
parser.sess.span_diagnostic.reset_err_count();
if parser.sess.dcx.has_errors().is_some() {
parser.sess.dcx.reset_err_count();
return None;
} else {
val
}
}
Err(err) => {
err.cancel();
parser.sess.span_diagnostic.reset_err_count();
parser.sess.dcx.reset_err_count();
return None;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/parse/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
let mut cloned_parser = (*parser).clone();
match $parser(&mut cloned_parser) {
Ok(x) => {
if parser.sess.span_diagnostic.has_errors().is_some() {
parser.sess.span_diagnostic.reset_err_count();
if parser.sess.dcx.has_errors().is_some() {
parser.sess.dcx.reset_err_count();
} else {
// Parsing succeeded.
*parser = cloned_parser;
Expand All @@ -38,7 +38,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
}
Err(e) => {
e.cancel();
parser.sess.span_diagnostic.reset_err_count();
parser.sess.dcx.reset_err_count();
}
}
};
Expand Down
26 changes: 12 additions & 14 deletions src/parse/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_errors::emitter::{DynEmitter, Emitter, EmitterWriter};
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_span::{
source_map::{FilePathMapping, SourceMap},
Expand Down Expand Up @@ -118,13 +118,13 @@ impl From<Color> for ColorConfig {
}
}

fn default_handler(
fn default_dcx(
source_map: Lrc<SourceMap>,
ignore_path_set: Lrc<IgnorePathSet>,
can_reset: Lrc<AtomicBool>,
show_parse_errors: bool,
color: Color,
) -> Handler {
) -> DiagCtxt {
let supports_color = term::stderr().map_or(false, |term| term.supports_color());
let emit_color = if supports_color {
ColorConfig::from(color)
Expand All @@ -141,7 +141,7 @@ fn default_handler(
);
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,
source_map,
emitter,
Expand All @@ -159,14 +159,14 @@ impl ParseSess {
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let can_reset_errors = Lrc::new(AtomicBool::new(false));

let handler = default_handler(
let dcx = default_dcx(
Lrc::clone(&source_map),
Lrc::clone(&ignore_path_set),
Lrc::clone(&can_reset_errors),
config.show_parse_errors(),
config.color(),
);
let parse_sess = RawParseSess::with_span_handler(handler, source_map);
let parse_sess = RawParseSess::with_dcx(dcx, source_map);

Ok(ParseSess {
parse_sess,
Expand Down Expand Up @@ -218,7 +218,7 @@ impl ParseSess {
}

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 {
Expand Down Expand Up @@ -284,10 +284,8 @@ impl ParseSess {
// Methods that should be restricted within the parse module.
impl ParseSess {
pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
for mut diagnostic in diagnostics {
self.parse_sess
.span_diagnostic
.emit_diagnostic(&mut diagnostic);
for diagnostic in diagnostics {
self.parse_sess.dcx.emit_diagnostic(diagnostic);
}
}

Expand All @@ -296,11 +294,11 @@ impl ParseSess {
}

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) {
self.parse_sess.span_diagnostic.reset_err_count();
self.parse_sess.dcx.reset_err_count();
}
}

Expand Down Expand Up @@ -372,7 +370,7 @@ mod tests {

fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic {
let mut diag = Diagnostic::new(level, "");
diag.message.clear();
diag.messages.clear();
if let Some(span) = span {
diag.span = span;
}
Expand Down
12 changes: 9 additions & 3 deletions src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,15 @@ impl Rewrite for Pat {
None,
None,
),
PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => {
rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape)
}
PatKind::Struct(ref qself, ref path, ref fields, rest) => rewrite_struct_pat(
qself,
path,
fields,
rest == ast::PatFieldsRest::Rest,
self.span,
context,
shape,
),
PatKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Pat)
}
Expand Down
31 changes: 11 additions & 20 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,28 +537,19 @@ impl Rewrite for ast::Lifetime {
impl Rewrite for ast::GenericBound {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 has_paren = snippet.starts_with('(') && snippet.ends_with(')');
let rewrite = match trait_bound_modifier {
ast::TraitBoundModifier::None => poly_trait_ref.rewrite(context, shape),
ast::TraitBoundModifier::Maybe => poly_trait_ref
.rewrite(context, shape.offset_left(1)?)
.map(|s| format!("?{}", s)),
ast::TraitBoundModifier::MaybeConst(_) => poly_trait_ref
.rewrite(context, shape.offset_left(7)?)
.map(|s| format!("~const {}", s)),
ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref
.rewrite(context, shape.offset_left(8)?)
.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 })
let mut constness = modifiers.constness.as_str().to_string();
if !constness.is_empty() {
constness.push(' ');
}
let polarity = modifiers.polarity.as_str();
let shape = shape.offset_left(constness.len() + polarity.len())?;
poly_trait_ref
.rewrite(context, shape)
.map(|s| format!("{constness}{polarity}{s}"))
.map(|s| if has_paren { format!("({})", s) } else { s })
}
ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape),
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub(crate) fn semicolon_for_stmt(
) -> bool {
match stmt.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
}
ast::ExprKind::Break(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Ret(..) => {
Expand Down Expand Up @@ -476,7 +476,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::ConstBlock(..)
| ast::ExprKind::Gen(..)
| ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::ForLoop { .. }
| ast::ExprKind::TryBlock(..)
| ast::ExprKind::Match(..) => repr.contains('\n'),
ast::ExprKind::Paren(ref expr)
Expand Down

0 comments on commit 85e21fa

Please sign in to comment.