Skip to content

Commit 2b0c8ff

Browse files
Various pattern cleanups
1 parent fde1b76 commit 2b0c8ff

File tree

9 files changed

+47
-68
lines changed

9 files changed

+47
-68
lines changed

compiler/rustc_ast/src/mut_visit.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1179,13 +1179,10 @@ fn noop_visit_inline_asm<T: MutVisitor>(asm: &mut InlineAsm, vis: &mut T) {
11791179
for (op, _) in &mut asm.operands {
11801180
match op {
11811181
InlineAsmOperand::In { expr, .. }
1182+
| InlineAsmOperand::Out { expr: Some(expr), .. }
11821183
| InlineAsmOperand::InOut { expr, .. }
11831184
| InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr),
1184-
InlineAsmOperand::Out { expr, .. } => {
1185-
if let Some(expr) = expr {
1186-
vis.visit_expr(expr);
1187-
}
1188-
}
1185+
InlineAsmOperand::Out { expr: None, .. } => {}
11891186
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
11901187
vis.visit_expr(in_expr);
11911188
if let Some(out_expr) = out_expr {

compiler/rustc_ast/src/visit.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,10 @@ fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) {
714714
for (op, _) in &asm.operands {
715715
match op {
716716
InlineAsmOperand::In { expr, .. }
717+
| InlineAsmOperand::Out { expr: Some(expr), .. }
717718
| InlineAsmOperand::InOut { expr, .. }
718719
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
719-
InlineAsmOperand::Out { expr, .. } => {
720-
if let Some(expr) = expr {
721-
visitor.visit_expr(expr);
722-
}
723-
}
720+
InlineAsmOperand::Out { expr: None, .. } => {}
724721
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
725722
visitor.visit_expr(in_expr);
726723
if let Some(out_expr) = out_expr {

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(bootstrap, feature(bindings_after_at))]
12
#![feature(crate_visibility_modifier)]
23
#![feature(decl_macro)]
34
#![feature(destructuring_assignment)]

compiler/rustc_middle/src/mir/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1664,13 +1664,10 @@ impl Debug for Statement<'_> {
16641664
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
16651665
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
16661666
}
1667-
Coverage(box ref coverage) => {
1668-
if let Some(rgn) = &coverage.code_region {
1669-
write!(fmt, "Coverage::{:?} for {:?}", coverage.kind, rgn)
1670-
} else {
1671-
write!(fmt, "Coverage::{:?}", coverage.kind)
1672-
}
1667+
Coverage(box self::Coverage { ref kind, code_region: Some(ref rgn) }) => {
1668+
write!(fmt, "Coverage::{:?} for {:?}", kind, rgn)
16731669
}
1670+
Coverage(box ref coverage) => write!(fmt, "Coverage::{:?}", coverage.kind),
16741671
CopyNonOverlapping(box crate::mir::CopyNonOverlapping {
16751672
ref src,
16761673
ref dst,

compiler/rustc_middle/src/mir/visit.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,12 @@ macro_rules! make_mir_visitor {
587587
InlineAsmOperand::In { value, .. } => {
588588
self.visit_operand(value, location);
589589
}
590-
InlineAsmOperand::Out { place, .. } => {
591-
if let Some(place) = place {
592-
self.visit_place(
593-
place,
594-
PlaceContext::MutatingUse(MutatingUseContext::Store),
595-
location,
596-
);
597-
}
590+
InlineAsmOperand::Out { place: Some(place), .. } => {
591+
self.visit_place(
592+
place,
593+
PlaceContext::MutatingUse(MutatingUseContext::Store),
594+
location,
595+
);
598596
}
599597
InlineAsmOperand::InOut { in_value, out_place, .. } => {
600598
self.visit_operand(in_value, location);
@@ -610,7 +608,8 @@ macro_rules! make_mir_visitor {
610608
| InlineAsmOperand::SymFn { value } => {
611609
self.visit_constant(value, location);
612610
}
613-
InlineAsmOperand::SymStatic { def_id: _ } => {}
611+
InlineAsmOperand::Out { place: None, .. }
612+
| InlineAsmOperand::SymStatic { def_id: _ } => {}
614613
}
615614
}
616615
}

compiler/rustc_middle/src/thir.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::def::CtorKind;
1414
use rustc_hir::def_id::DefId;
1515
use rustc_hir::RangeEnd;
1616
use rustc_index::newtype_index;
17-
use rustc_index::vec::{Idx, IndexVec};
17+
use rustc_index::vec::IndexVec;
1818
use rustc_middle::infer::canonical::Canonical;
1919
use rustc_middle::middle::region;
2020
use rustc_middle::mir::{
@@ -716,17 +716,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
716716
PatKind::Variant { adt_def, variant_index, .. } => {
717717
Some(&adt_def.variants[variant_index])
718718
}
719-
_ => {
720-
if let ty::Adt(adt, _) = self.ty.kind() {
721-
if !adt.is_enum() {
722-
Some(&adt.variants[VariantIdx::new(0)])
723-
} else {
724-
None
725-
}
726-
} else {
727-
None
728-
}
729-
}
719+
_ => self.ty.ty_adt_def().and_then(|adt| {
720+
if !adt.is_enum() { Some(adt.non_enum_variant()) } else { None }
721+
}),
730722
};
731723

732724
if let Some(variant) = variant {

compiler/rustc_middle/src/ty/print/pretty.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -927,27 +927,29 @@ pub trait PrettyPrinter<'tcx>:
927927
}
928928

929929
match ct.val {
930-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => {
931-
if let Some(promoted) = promoted {
932-
p!(print_value_path(def.did, substs));
933-
p!(write("::{:?}", promoted));
934-
} else {
935-
match self.tcx().def_kind(def.did) {
936-
DefKind::Static | DefKind::Const | DefKind::AssocConst => {
937-
p!(print_value_path(def.did, substs))
938-
}
939-
_ => {
940-
if def.is_local() {
941-
let span = self.tcx().def_span(def.did);
942-
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span)
943-
{
944-
p!(write("{}", snip))
945-
} else {
946-
print_underscore!()
947-
}
930+
ty::ConstKind::Unevaluated(ty::Unevaluated {
931+
def,
932+
substs,
933+
promoted: Some(promoted),
934+
}) => {
935+
p!(print_value_path(def.did, substs));
936+
p!(write("::{:?}", promoted));
937+
}
938+
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted: None }) => {
939+
match self.tcx().def_kind(def.did) {
940+
DefKind::Static | DefKind::Const | DefKind::AssocConst => {
941+
p!(print_value_path(def.did, substs))
942+
}
943+
_ => {
944+
if def.is_local() {
945+
let span = self.tcx().def_span(def.did);
946+
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
947+
p!(write("{}", snip))
948948
} else {
949949
print_underscore!()
950950
}
951+
} else {
952+
print_underscore!()
951953
}
952954
}
953955
}

compiler/rustc_typeck/src/check/expr.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -2164,14 +2164,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21642164
hir::InlineAsmOperand::In { expr, .. } => {
21652165
self.check_expr_asm_operand(expr, true);
21662166
}
2167-
hir::InlineAsmOperand::Out { expr, .. } => {
2168-
if let Some(expr) = expr {
2169-
self.check_expr_asm_operand(expr, false);
2170-
}
2171-
}
2172-
hir::InlineAsmOperand::InOut { expr, .. } => {
2167+
hir::InlineAsmOperand::Out { expr: Some(expr), .. }
2168+
| hir::InlineAsmOperand::InOut { expr, .. } => {
21732169
self.check_expr_asm_operand(expr, false);
21742170
}
2171+
hir::InlineAsmOperand::Out { expr: None, .. } => {}
21752172
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
21762173
self.check_expr_asm_operand(in_expr, true);
21772174
if let Some(out_expr) = out_expr {

compiler/rustc_typeck/src/expr_use_visitor.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
334334
match op {
335335
hir::InlineAsmOperand::In { expr, .. }
336336
| hir::InlineAsmOperand::Sym { expr, .. } => self.consume_expr(expr),
337-
hir::InlineAsmOperand::Out { expr, .. } => {
338-
if let Some(expr) = expr {
339-
self.mutate_expr(expr);
340-
}
341-
}
342-
hir::InlineAsmOperand::InOut { expr, .. } => {
337+
hir::InlineAsmOperand::Out { expr: Some(expr), .. }
338+
| hir::InlineAsmOperand::InOut { expr, .. } => {
343339
self.mutate_expr(expr);
344340
}
345341
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
@@ -348,7 +344,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
348344
self.mutate_expr(out_expr);
349345
}
350346
}
351-
hir::InlineAsmOperand::Const { .. } => {}
347+
hir::InlineAsmOperand::Out { expr: None, .. }
348+
| hir::InlineAsmOperand::Const { .. } => {}
352349
}
353350
}
354351
}

0 commit comments

Comments
 (0)