diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-10-14 13:48:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-14 13:48:19 +0200 |
| commit | 30b2cc0cc38b168b8e271d490ce2ef4d869c9d6b (patch) | |
| tree | b4c055da67b2b842121552fdca8fa2cb8ec1a15e | |
| parent | f29dbe8885c551aa244a9ea6fc4788877451d3e8 (diff) | |
| parent | feedd68f80e15616511493feda4c9c60d5571e73 (diff) | |
| download | rust-30b2cc0cc38b168b8e271d490ce2ef4d869c9d6b.tar.gz rust-30b2cc0cc38b168b8e271d490ce2ef4d869c9d6b.zip | |
Rollup merge of #116679 - estebank:rewrap-unwrap, r=oli-obk
Remove some unnecessary `unwrap`s
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/suggest.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 2 |
3 files changed, 16 insertions, 9 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 9999fa2e59c..45153699794 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -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) { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index a4bbb16026a..bda1df4b753 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -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()]); @@ -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), diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index d5beff4f101..1e7a839e931 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -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 { |
