Skip to content

Commit 1d436cf

Browse files
authored
Rollup merge of rust-lang#52773 - ljedrz:unncecessary_patterns, r=nikomatsakis
Avoid unnecessary pattern matching against Option and Result
2 parents ebe8df4 + 44d32d4 commit 1d436cf

File tree

16 files changed

+21
-23
lines changed

16 files changed

+21
-23
lines changed

src/librustc/traits/auto_trait.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
681681
}
682682
}
683683
&ty::Predicate::RegionOutlives(ref binder) => {
684-
if let Err(_) = select
685-
.infcx()
686-
.region_outlives_predicate(&dummy_cause, binder)
687-
{
684+
if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
688685
return false;
689686
}
690687
}

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
143143
// Eventually I'll need to implement param-env-aware
144144
// `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic.
145145
let param_env = ty::ParamEnv::empty();
146-
if let Ok(_) = self.can_sub(param_env, error, implication) {
146+
if self.can_sub(param_env, error, implication).is_ok() {
147147
debug!("error_implies: {:?} -> {:?} -> {:?}", cond, error, implication);
148148
return true
149149
}

src/librustc/traits/query/outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
137137
// variables. Process these constraints.
138138
let mut fulfill_cx = FulfillmentContext::new();
139139
fulfill_cx.register_predicate_obligations(self, result.obligations);
140-
if let Err(_) = fulfill_cx.select_all_or_error(self) {
140+
if fulfill_cx.select_all_or_error(self).is_err() {
141141
self.tcx.sess.delay_span_bug(
142142
span,
143143
"implied_outlives_bounds failed to solve obligations from instantiation"

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
15871587
-> bool
15881588
{
15891589
assert!(!skol_trait_ref.has_escaping_regions());
1590-
if let Err(_) = self.infcx.at(&obligation.cause, obligation.param_env)
1591-
.sup(ty::Binder::dummy(skol_trait_ref), trait_bound) {
1590+
if self.infcx.at(&obligation.cause, obligation.param_env)
1591+
.sup(ty::Binder::dummy(skol_trait_ref), trait_bound).is_err() {
15921592
return false;
15931593
}
15941594

src/librustc/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ fn resolve_associated_item<'a, 'tcx>(
294294
})
295295
}
296296
traits::VtableBuiltin(..) => {
297-
if let Some(_) = tcx.lang_items().clone_trait() {
297+
if tcx.lang_items().clone_trait().is_some() {
298298
Some(Instance {
299299
def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()),
300300
substs: rcvr_substs

src/librustc_errors/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ impl EmitterWriter {
12951295
}
12961296

12971297
// if we elided some lines, add an ellipsis
1298-
if let Some(_) = lines.next() {
1298+
if lines.next().is_some() {
12991299
buffer.puts(row_num, max_line_num_len - 1, "...", Style::LineNumber);
13001300
} else if !show_underline {
13011301
draw_col_separator_no_space(&mut buffer, row_num, max_line_num_len + 1);

src/librustc_mir/borrow_check/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
138138
let tables = self.tcx.typeck_tables_of(id);
139139
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
140140
let hir_id = self.tcx.hir.node_to_hir_id(node_id);
141-
if let Some(_) = tables.closure_kind_origins().get(hir_id) {
141+
if tables.closure_kind_origins().get(hir_id).is_some() {
142142
false
143143
} else {
144144
true
@@ -735,7 +735,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
735735
&including_downcast,
736736
)?;
737737
buf.push_str("[");
738-
if let Err(_) = self.append_local_to_string(index, buf) {
738+
if self.append_local_to_string(index, buf).is_err() {
739739
buf.push_str("..");
740740
}
741741
buf.push_str("]");

src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
26982698
self.label_ribs.pop();
26992699
}
27002700
self.ribs[ValueNS].pop();
2701-
if let Some(_) = anonymous_module {
2701+
if anonymous_module.is_some() {
27022702
self.ribs[TypeNS].pop();
27032703
}
27042704
debug!("(resolving block) leaving block");
@@ -4256,7 +4256,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
42564256

42574257
while let Some((in_module, path_segments)) = worklist.pop() {
42584258
// abort if the module is already found
4259-
if let Some(_) = result { break; }
4259+
if result.is_some() { break; }
42604260

42614261
self.populate_module_if_necessary(in_module);
42624262

src/librustc_save_analysis/json_dumper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct WriteOutput<'b, W: Write + 'b> {
3939

4040
impl<'b, W: Write> DumpOutput for WriteOutput<'b, W> {
4141
fn dump(&mut self, result: &Analysis) {
42-
if let Err(_) = write!(self.output, "{}", as_json(&result)) {
42+
if write!(self.output, "{}", as_json(&result)).is_err() {
4343
error!("Error writing output");
4444
}
4545
}

src/librustc_typeck/check/method/probe.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
758758
self.span, infer::FnCall, &fty);
759759

760760
if let Some(self_ty) = self_ty {
761-
if let Err(_) = self.at(&ObligationCause::dummy(), self.param_env)
762-
.sup(fty.inputs()[0], self_ty)
761+
if self.at(&ObligationCause::dummy(), self.param_env)
762+
.sup(fty.inputs()[0], self_ty)
763+
.is_err()
763764
{
764765
return false
765766
}

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39153915

39163916
}
39173917
hir::ExprKind::Continue(destination) => {
3918-
if let Ok(_) = destination.target_id {
3918+
if destination.target_id.is_ok() {
39193919
tcx.types.never
39203920
} else {
39213921
// There was an error, make typecheck fail

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub fn run_core(search_paths: SearchPaths,
486486
&name,
487487
&output_filenames,
488488
|tcx, analysis, _, result| {
489-
if let Err(_) = result {
489+
if result.is_err() {
490490
sess.fatal("Compilation failed, aborting rustdoc");
491491
}
492492

src/librustdoc/html/highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn render_with_highlighting(src: &str, class: Option<&str>,
4444
write_header(class, &mut out).unwrap();
4545

4646
let mut classifier = Classifier::new(lexer::StringReader::new(&sess, fm, None), sess.codemap());
47-
if let Err(_) = classifier.write_source(&mut out) {
47+
if classifier.write_source(&mut out).is_err() {
4848
return format!("<pre>{}</pre>", src);
4949
}
5050

src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ impl LangString {
625625
data.no_run = true;
626626
}
627627
x if allow_error_code_check && x.starts_with("E") && x.len() == 5 => {
628-
if let Ok(_) = x[1..].parse::<u32>() {
628+
if x[1..].parse::<u32>().is_ok() {
629629
data.error_codes.push(x.to_owned());
630630
seen_rust_tags = !seen_other_tags || seen_rust_tags;
631631
} else {

src/libsyntax/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn path_name_i(idents: &[Ident]) -> String {
631631
let mut idents_iter = idents.iter().peekable();
632632
while let Some(ident) = idents_iter.next() {
633633
path_name.push_str(&ident.as_str());
634-
if let Some(_) = idents_iter.peek() {
634+
if idents_iter.peek().is_some() {
635635
path_name.push_str("::")
636636
}
637637
}

src/libsyntax_ext/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt,
8181
}
8282
};
8383

84-
if let Some(_) = exprs.next() {
84+
if exprs.next().is_some() {
8585
cx.span_err(sp, "env! takes 1 or 2 arguments");
8686
return DummyResult::expr(sp);
8787
}

0 commit comments

Comments
 (0)