From fd649a3cc5e9f17c8aee070227e8c71f094560b7 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 30 Jan 2023 11:03:32 +0000 Subject: Replace enum `==`s with `match`es where it makes sense --- compiler/rustc_errors/src/emitter.rs | 54 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 628e1999921..faeaa548619 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2113,30 +2113,38 @@ impl EmitterWriter { } } for sugg in suggestions { - if sugg.style == SuggestionStyle::CompletelyHidden { - // do not display this suggestion, it is meant only for tools - } else if sugg.style == SuggestionStyle::HideCodeAlways { - if let Err(e) = self.emit_message_default( - &MultiSpan::new(), - &[(sugg.msg.to_owned(), Style::HeaderMsg)], - args, - &None, - &Level::Help, - max_line_num_len, - true, - None, - ) { - panic!("failed to emit error: {}", e); + match sugg.style { + SuggestionStyle::CompletelyHidden => { + // do not display this suggestion, it is meant only for tools } - } else if let Err(e) = self.emit_suggestion_default( - span, - sugg, - args, - &Level::Help, - max_line_num_len, - ) { - panic!("failed to emit error: {}", e); - }; + SuggestionStyle::HideCodeAlways => { + if let Err(e) = self.emit_message_default( + &MultiSpan::new(), + &[(sugg.msg.to_owned(), Style::HeaderMsg)], + args, + &None, + &Level::Help, + max_line_num_len, + true, + None, + ) { + panic!("failed to emit error: {}", e); + } + } + SuggestionStyle::HideCodeInline + | SuggestionStyle::ShowCode + | SuggestionStyle::ShowAlways => { + if let Err(e) = self.emit_suggestion_default( + span, + sugg, + args, + &Level::Help, + max_line_num_len, + ) { + panic!("failed to emit error: {}", e); + } + } + } } } } -- cgit 1.4.1-3-g733a5 From f1d273cbfbebe108306455b7b34bbc625a24fa7a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 30 Jan 2023 12:01:09 +0000 Subject: Replace some `_ == _ || _ == _`s with `matches!(_, _ | _)`s --- compiler/rustc_const_eval/src/transform/validate.rs | 2 +- compiler/rustc_errors/src/styled_buffer.rs | 2 +- compiler/rustc_expand/src/mbe/macro_parser.rs | 2 +- compiler/rustc_metadata/src/native_libs.rs | 2 +- compiler/rustc_mir_transform/src/const_prop.rs | 2 +- compiler/rustc_mir_transform/src/const_prop_lint.rs | 2 +- compiler/rustc_passes/src/stability.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index a2f2457487a..72f456138ef 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -754,7 +754,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { // FIXME(JakobDegen) The validator should check that `self.mir_phase < // DropsLowered`. However, this causes ICEs with generation of drop shims, which // seem to fail to set their `MirPhase` correctly. - if *kind == RetagKind::Raw || *kind == RetagKind::TwoPhase { + if matches!(kind, RetagKind::Raw | RetagKind::TwoPhase) { self.fail(location, format!("explicit `{:?}` is forbidden", kind)); } } diff --git a/compiler/rustc_errors/src/styled_buffer.rs b/compiler/rustc_errors/src/styled_buffer.rs index 9abdb5fc97c..9aa14e1f214 100644 --- a/compiler/rustc_errors/src/styled_buffer.rs +++ b/compiler/rustc_errors/src/styled_buffer.rs @@ -142,7 +142,7 @@ impl StyledBuffer { pub fn set_style(&mut self, line: usize, col: usize, style: Style, overwrite: bool) { if let Some(ref mut line) = self.lines.get_mut(line) { if let Some(StyledChar { style: s, .. }) = line.get_mut(col) { - if overwrite || *s == Style::NoStyle || *s == Style::Quotation { + if overwrite || matches!(s, Style::NoStyle | Style::Quotation) { *s = style; } } diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 2e199541b92..283e68a68b5 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -503,7 +503,7 @@ impl TtParser { mp.push_match(metavar_idx, seq_depth, MatchedSeq(vec![])); } - if op == KleeneOp::ZeroOrMore || op == KleeneOp::ZeroOrOne { + if matches!(op, KleeneOp::ZeroOrMore | KleeneOp::ZeroOrOne) { // Try zero matches of this sequence, by skipping over it. self.cur_mps.push(MatcherPos { idx: idx_first_after, diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 6f05c76e89d..a5910100786 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -107,7 +107,7 @@ impl<'tcx> Collector<'tcx> { return; }; - if abi == Abi::Rust || abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic { + if matches!(abi, Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic) { return; } diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 9699611e9b0..feb054392bc 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -527,7 +527,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let r = self.use_ecx(|this| this.ecx.read_immediate(&this.ecx.eval_operand(right, None)?)); let l = self.use_ecx(|this| this.ecx.read_immediate(&this.ecx.eval_operand(left, None)?)); // Check for exceeding shifts *even if* we cannot evaluate the LHS. - if op == BinOp::Shr || op == BinOp::Shl { + if matches!(op, BinOp::Shr | BinOp::Shl) { let r = r.clone()?; // We need the type of the LHS. We cannot use `place_layout` as that is the type // of the result, which for checked binops is not the same! diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 0ab67228f3f..c4b10218c23 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -368,7 +368,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { this.ecx.read_immediate(&this.ecx.eval_operand(left, None)?) }); // Check for exceeding shifts *even if* we cannot evaluate the LHS. - if op == BinOp::Shr || op == BinOp::Shl { + if matches!(op, BinOp::Shr | BinOp::Shl) { let r = r.clone()?; // We need the type of the LHS. We cannot use `place_layout` as that is the type // of the result, which for checked binops is not the same! diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 0bde7502e39..47911aef25d 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -125,7 +125,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if let Some((depr, span)) = &depr { is_deprecated = true; - if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited { + if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) { let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); self.tcx.emit_spanned_lint( USELESS_DEPRECATED, -- cgit 1.4.1-3-g733a5