Auto merge of #122869 - matthiaskrgr:rollup-0navj4l, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #121619 (Experimental feature postfix match) - #122370 (Gracefully handle `AnonConst` in `diagnostic_hir_wf_check()`) - #122537 (interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit) - #122542 (coverage: Clean up marker statements that aren't needed later) - #122800 (Add `NonNull::<[T]>::is_empty`.) - #122820 (Stop using `<DefId as Ord>` in various diagnostic situations) - #122847 (Suggest `RUST_MIN_STACK` workaround on overflow) - #122855 (Fix Itanium mangling usizes) - #122863 (add more ice tests ) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
1447f9d38c
73 changed files with 1199 additions and 247 deletions
|
|
@ -105,7 +105,7 @@ impl<'ast> Visitor<'ast> for BreakVisitor {
|
|||
fn visit_expr(&mut self, expr: &'ast Expr) {
|
||||
self.is_break = match expr.kind {
|
||||
ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true,
|
||||
ExprKind::Match(_, ref arms) => arms.iter().all(|arm|
|
||||
ExprKind::Match(_, ref arms, _) => arms.iter().all(|arm|
|
||||
arm.body.is_none() || arm.body.as_deref().is_some_and(|body| self.check_expr(body))
|
||||
),
|
||||
ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els),
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ fn ident_difference_expr_with_base_location(
|
|||
| (Gen(_, _, _), Gen(_, _, _))
|
||||
| (Block(_, _), Block(_, _))
|
||||
| (Closure(_), Closure(_))
|
||||
| (Match(_, _), Match(_, _))
|
||||
| (Match(_, _, _), Match(_, _, _))
|
||||
| (Loop(_, _, _), Loop(_, _, _))
|
||||
| (ForLoop { .. }, ForLoop { .. })
|
||||
| (While(_, _, _), While(_, _, _))
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
|||
},
|
||||
(AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv),
|
||||
(Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp),
|
||||
(Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm),
|
||||
(Match(ls, la, lkind), Match(rs, ra, rkind)) => (lkind == rkind) && eq_expr(ls, rs) && over(la, ra, eq_arm),
|
||||
(
|
||||
Closure(box ast::Closure {
|
||||
binder: lb,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::cmp::min;
|
|||
|
||||
use itertools::Itertools;
|
||||
use rustc_ast::token::{Delimiter, Lit, LitKind};
|
||||
use rustc_ast::{ast, ptr, token, ForLoopKind};
|
||||
use rustc_ast::{ast, ptr, token, ForLoopKind, MatchKind};
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
use crate::chains::rewrite_chain;
|
||||
|
|
@ -170,8 +170,8 @@ pub(crate) fn format_expr(
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Match(ref cond, ref arms) => {
|
||||
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs)
|
||||
ast::ExprKind::Match(ref cond, ref arms, kind) => {
|
||||
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs, kind)
|
||||
}
|
||||
ast::ExprKind::Path(ref qself, ref path) => {
|
||||
rewrite_path(context, PathContext::Expr, qself, path, shape)
|
||||
|
|
@ -625,7 +625,7 @@ pub(crate) fn rewrite_cond(
|
|||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
match expr.kind {
|
||||
ast::ExprKind::Match(ref cond, _) => {
|
||||
ast::ExprKind::Match(ref cond, _, MatchKind::Prefix) => {
|
||||
// `match `cond` {`
|
||||
let cond_shape = match context.config.indent_style() {
|
||||
IndentStyle::Visual => shape.shrink_left(6).and_then(|s| s.sub_width(2))?,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::iter::repeat;
|
||||
|
||||
use rustc_ast::{ast, ptr};
|
||||
use rustc_ast::{ast, ptr, MatchKind};
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};
|
||||
|
|
@ -72,6 +72,7 @@ pub(crate) fn rewrite_match(
|
|||
shape: Shape,
|
||||
span: Span,
|
||||
attrs: &[ast::Attribute],
|
||||
match_kind: MatchKind,
|
||||
) -> Option<String> {
|
||||
// Do not take the rhs overhead from the upper expressions into account
|
||||
// when rewriting match condition.
|
||||
|
|
@ -131,15 +132,27 @@ pub(crate) fn rewrite_match(
|
|||
}
|
||||
} else {
|
||||
let span_after_cond = mk_sp(cond.span.hi(), span.hi());
|
||||
Some(format!(
|
||||
"match {}{}{{\n{}{}{}\n{}}}",
|
||||
cond_str,
|
||||
block_sep,
|
||||
inner_attrs_str,
|
||||
nested_indent_str,
|
||||
rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?,
|
||||
shape.indent.to_string(context.config),
|
||||
))
|
||||
|
||||
match match_kind {
|
||||
MatchKind::Prefix => Some(format!(
|
||||
"match {}{}{{\n{}{}{}\n{}}}",
|
||||
cond_str,
|
||||
block_sep,
|
||||
inner_attrs_str,
|
||||
nested_indent_str,
|
||||
rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?,
|
||||
shape.indent.to_string(context.config),
|
||||
)),
|
||||
MatchKind::Postfix => Some(format!(
|
||||
"{}.match{}{{\n{}{}{}\n{}}}",
|
||||
cond_str,
|
||||
block_sep,
|
||||
inner_attrs_str,
|
||||
nested_indent_str,
|
||||
rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?,
|
||||
shape.indent.to_string(context.config),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
20
src/tools/rustfmt/tests/source/postfix-match/pf-match.rs
Normal file
20
src/tools/rustfmt/tests/source/postfix-match/pf-match.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#![feature(postfix_match)]
|
||||
|
||||
fn main() {
|
||||
let val = Some(42);
|
||||
|
||||
val.match {
|
||||
Some(_) => 2,
|
||||
_ => 1
|
||||
};
|
||||
|
||||
Some(2).match {
|
||||
Some(_) => true,
|
||||
None => false
|
||||
}.match {
|
||||
false => "ferris is cute",
|
||||
true => "I turn cats in to petted cats",
|
||||
}.match {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
20
src/tools/rustfmt/tests/target/postfix-match/pf-match.rs
Normal file
20
src/tools/rustfmt/tests/target/postfix-match/pf-match.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#![feature(postfix_match)]
|
||||
|
||||
fn main() {
|
||||
let val = Some(42);
|
||||
|
||||
val.match {
|
||||
Some(_) => 2,
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
Some(2).match {
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
}.match {
|
||||
false => "ferris is cute",
|
||||
true => "I turn cats in to petted cats",
|
||||
}.match {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue