Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unnecessary unwraps #116679

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false;
}
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 pin_found = Ty::new_lang_item(self.tcx, found, LangItem::Pin).unwrap();
let Some(pin_box_found) = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin) else {
return false;
};
let Some(pin_found) = Ty::new_lang_item(self.tcx, found, LangItem::Pin) else {
return false;
};
match expected.kind() {
ty::Adt(def, _) if Some(def.did()) == pin_did => {
if self.can_coerce(pin_box_found, expected) {
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 =
self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]);

Expand Down Expand Up @@ -2539,11 +2543,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(_) => (),
}

let pred = ty::TraitRef::new(
self.tcx,
self.tcx.lang_items().unpin_trait().unwrap(),
[*rcvr_ty],
);
let Some(unpin_trait) = self.tcx.lang_items().unpin_trait() else {
return;
};
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
self.tcx,
ObligationCause::misc(rcvr.span, self.body_id),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
ty::Generator(def_id, ..) => {
// async fn should be treated as "implementor of `Future`"
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)
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
} else {
Expand Down
Loading