Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d0db0a8

Browse files
authored
Rollup merge of rust-lang#71534 - cuviper:unused-option-map, r=Mark-Simulacrum
Avoid unused Option::map results These are changes that would be needed if we add `#[must_use]` to `Option::map`, per rust-lang#71484. r? @Mark-Simulacrum
2 parents 2ca6df7 + 2325c20 commit d0db0a8

File tree

21 files changed

+111
-64
lines changed

21 files changed

+111
-64
lines changed

src/librustc_attr/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
9898
}
9999
}
100100

101-
diagnostic.map(|d| {
101+
if let Some(d) = diagnostic {
102102
struct_span_err!(d, attr.span, E0633, "malformed `unwind` attribute input")
103103
.span_label(attr.span, "invalid argument")
104104
.span_suggestions(
@@ -110,7 +110,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
110110
Applicability::MachineApplicable,
111111
)
112112
.emit();
113-
});
113+
};
114114
}
115115
}
116116
}

src/librustc_expand/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,10 +1172,10 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
11721172
// ignore derives so they remain unused
11731173
let (attr, after_derive) = self.classify_nonitem(&mut expr);
11741174

1175-
if attr.is_some() {
1175+
if let Some(ref attr_value) = attr {
11761176
// Collect the invoc regardless of whether or not attributes are permitted here
11771177
// expansion will eat the attribute so it won't error later.
1178-
attr.as_ref().map(|a| self.cfg.maybe_emit_expr_attr_err(a));
1178+
self.cfg.maybe_emit_expr_attr_err(attr_value);
11791179

11801180
// AstFragmentKind::Expr requires the macro to emit an expression.
11811181
return self
@@ -1322,8 +1322,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13221322
// Ignore derives so they remain unused.
13231323
let (attr, after_derive) = self.classify_nonitem(&mut expr);
13241324

1325-
if attr.is_some() {
1326-
attr.as_ref().map(|a| self.cfg.maybe_emit_expr_attr_err(a));
1325+
if let Some(ref attr_value) = attr {
1326+
self.cfg.maybe_emit_expr_attr_err(attr_value);
13271327

13281328
return self
13291329
.collect_attr(

src/librustc_hir/definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl DefPath {
246246

247247
let mut opt_delimiter = None;
248248
for component in &self.data {
249-
opt_delimiter.map(|d| s.push(d));
249+
s.extend(opt_delimiter);
250250
opt_delimiter = Some('-');
251251
if component.disambiguator == 0 {
252252
write!(s, "{}", component.data.as_symbol()).unwrap();

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
755755
},
756756
ObligationCauseCode::IfExpression(box IfExpressionCause { then, outer, semicolon }) => {
757757
err.span_label(then, "expected because of this");
758-
outer.map(|sp| err.span_label(sp, "`if` and `else` have incompatible types"));
758+
if let Some(sp) = outer {
759+
err.span_label(sp, "`if` and `else` have incompatible types");
760+
}
759761
if let Some(sp) = semicolon {
760762
err.span_suggestion_short(
761763
sp,

src/librustc_metadata/creader.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ fn dump_crates(cstore: &CStore) {
101101
info!(" hash: {}", data.hash());
102102
info!(" reqd: {:?}", data.dep_kind());
103103
let CrateSource { dylib, rlib, rmeta } = data.source();
104-
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
105-
rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display()));
106-
rmeta.as_ref().map(|rl| info!(" rmeta: {}", rl.0.display()));
104+
if let Some(dylib) = dylib {
105+
info!(" dylib: {}", dylib.0.display());
106+
}
107+
if let Some(rlib) = rlib {
108+
info!(" rlib: {}", rlib.0.display());
109+
}
110+
if let Some(rmeta) = rmeta {
111+
info!(" rmeta: {}", rmeta.0.display());
112+
}
107113
});
108114
}
109115

src/librustc_mir_build/build/matches/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13881388
}
13891389

13901390
// Insert a Shallow borrow of any places that is switched on.
1391-
fake_borrows.as_mut().map(|fb| fb.insert(match_place));
1391+
if let Some(fb) = fake_borrows {
1392+
fb.insert(match_place);
1393+
}
13921394

13931395
// perform the test, branching to one of N blocks. For each of
13941396
// those N possible outcomes, create a (initially empty)

src/librustc_parse/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,8 @@ pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedBrace>, sess: &Pa
12061206
*sess.reached_eof.borrow_mut() |=
12071207
unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none());
12081208
for unmatched in unclosed_delims.drain(..) {
1209-
make_unclosed_delims_error(unmatched, sess).map(|mut e| {
1209+
if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) {
12101210
e.emit();
1211-
});
1211+
}
12121212
}
12131213
}

src/librustc_passes/loops.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
6868
self.with_context(LabeledBlock, |v| v.visit_block(&b));
6969
}
7070
hir::ExprKind::Break(label, ref opt_expr) => {
71-
opt_expr.as_ref().map(|e| self.visit_expr(e));
71+
if let Some(e) = opt_expr {
72+
self.visit_expr(e);
73+
}
7274

7375
if self.require_label_in_labeled_block(e.span, &label, "break") {
7476
// If we emitted an error about an unlabeled break in a labeled

src/librustc_query_system/query/job.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ impl<CTX: QueryContext> QueryJob<CTX> {
133133
/// as there are no concurrent jobs which could be waiting on us
134134
pub fn signal_complete(self) {
135135
#[cfg(parallel_compiler)]
136-
self.latch.map(|latch| latch.set());
136+
{
137+
if let Some(latch) = self.latch {
138+
latch.set();
139+
}
140+
}
137141
}
138142
}
139143

src/librustc_resolve/late.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19961996
this.visit_expr(cond);
19971997
this.visit_block(then);
19981998
});
1999-
opt_else.as_ref().map(|expr| self.visit_expr(expr));
1999+
if let Some(expr) = opt_else {
2000+
self.visit_expr(expr);
2001+
}
20002002
}
20012003

20022004
ExprKind::Loop(ref block, label) => self.resolve_labeled_block(label, expr.id, &block),

0 commit comments

Comments
 (0)