Remove some unnecessary unwraps

This commit is contained in:
Esteban Küber 2023-10-13 00:28:49 +00:00
parent df4379b4eb
commit feedd68f80
3 changed files with 16 additions and 9 deletions

View File

@ -604,8 +604,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
} }
let box_found = Ty::new_box(self.tcx, found); let box_found = Ty::new_box(self.tcx, found);
let pin_box_found = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin).unwrap(); let Some(pin_box_found) = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin) else {
let pin_found = Ty::new_lang_item(self.tcx, found, LangItem::Pin).unwrap(); return false;
};
let Some(pin_found) = Ty::new_lang_item(self.tcx, found, LangItem::Pin) else {
return false;
};
match expected.kind() { match expected.kind() {
ty::Adt(def, _) if Some(def.did()) == pin_did => { ty::Adt(def, _) if Some(def.did()) == pin_did => {
if self.can_coerce(pin_box_found, expected) { if self.can_coerce(pin_box_found, expected) {

View File

@ -1616,7 +1616,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
continue; continue;
} }
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None); let Some(range_def_id) =
lang_item.and_then(|lang_item| self.tcx.lang_items().get(lang_item))
else {
continue;
};
let range_ty = let range_ty =
self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]); self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]);
@ -2539,11 +2543,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(_) => (), Err(_) => (),
} }
let pred = ty::TraitRef::new( let Some(unpin_trait) = self.tcx.lang_items().unpin_trait() else {
self.tcx, return;
self.tcx.lang_items().unpin_trait().unwrap(), };
[*rcvr_ty], let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
);
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new( let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
self.tcx, self.tcx,
ObligationCause::misc(rcvr.span, self.body_id), ObligationCause::misc(rcvr.span, self.body_id),

View File

@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
ty::Generator(def_id, ..) => { ty::Generator(def_id, ..) => {
// async fn should be treated as "implementor of `Future`" // async fn should be treated as "implementor of `Future`"
let must_use = if cx.tcx.generator_is_async(def_id) { let must_use = if cx.tcx.generator_is_async(def_id) {
let def_id = cx.tcx.lang_items().future_trait().unwrap(); let def_id = cx.tcx.lang_items().future_trait()?;
is_def_must_use(cx, def_id, span) is_def_must_use(cx, def_id, span)
.map(|inner| MustUsePath::Opaque(Box::new(inner))) .map(|inner| MustUsePath::Opaque(Box::new(inner)))
} else { } else {