Skip to content

Commit 5d10a69

Browse files
committed
Remove some unnecessary unwraps
1 parent df4379b commit 5d10a69

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
604604
return false;
605605
}
606606
let box_found = Ty::new_box(self.tcx, found);
607-
let pin_box_found = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin).unwrap();
608-
let pin_found = Ty::new_lang_item(self.tcx, found, LangItem::Pin).unwrap();
607+
let Some(pin_box_found) = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin) else {
608+
return false;
609+
};
610+
let Some(pin_found) = Ty::new_lang_item(self.tcx, found, LangItem::Pin) else {
611+
return false;
612+
};
609613
match expected.kind() {
610614
ty::Adt(def, _) if Some(def.did()) == pin_did => {
611615
if self.can_coerce(pin_box_found, expected) {

compiler/rustc_hir_typeck/src/method/suggest.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16161616
continue;
16171617
}
16181618

1619-
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None);
1619+
let Some(range_def_id) =
1620+
lang_item.and_then(|lang_item| self.tcx.lang_items().get(lang_item))
1621+
else {
1622+
continue;
1623+
};
16201624
let range_ty =
16211625
self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]);
16221626

@@ -2539,11 +2543,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25392543
Err(_) => (),
25402544
}
25412545

2542-
let pred = ty::TraitRef::new(
2543-
self.tcx,
2544-
self.tcx.lang_items().unpin_trait().unwrap(),
2545-
[*rcvr_ty],
2546-
);
2546+
let Some(unpin_trait) = self.tcx.lang_items().unpin_trait() else {
2547+
return;
2548+
};
2549+
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
25472550
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
25482551
self.tcx,
25492552
ObligationCause::misc(rcvr.span, self.body_id),

compiler/rustc_lint/src/unused.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
353353
ty::Generator(def_id, ..) => {
354354
// async fn should be treated as "implementor of `Future`"
355355
let must_use = if cx.tcx.generator_is_async(def_id) {
356-
let def_id = cx.tcx.lang_items().future_trait().unwrap();
356+
let Some(def_id) = cx.tcx.lang_items().future_trait() else {
357+
return None;
358+
};
357359
is_def_must_use(cx, def_id, span)
358360
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
359361
} else {

0 commit comments

Comments
 (0)