diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-06-08 07:37:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-08 07:37:29 +0200 |
| commit | 148a44a001ccffbcf0baca5ec0a4b160f41ef99d (patch) | |
| tree | 333b0d6ac191ccfdb98567613b7139db920a5e77 /compiler/rustc_trait_selection/src | |
| parent | 47aee31b2a89cb7de97d779869a30b046632b6af (diff) | |
| parent | 8f1fff04a72f65bc991b0c76b7b7300384b0d33d (diff) | |
| download | rust-148a44a001ccffbcf0baca5ec0a4b160f41ef99d.tar.gz rust-148a44a001ccffbcf0baca5ec0a4b160f41ef99d.zip | |
Rollup merge of #97595 - ouz-a:issue-97381, r=compiler-errors
Remove unwrap from get_vtable This avoids ICE on issue #97381 I think the bug is a bit deeper though, it compiles fine when `v` is `&v` which makes me think `Deref` is causing some issue with borrowck but it's fine I guess since this thing crashes since `nightly-2020-09-17` 😅
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/util.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index f2e31c068a0..3a00c41d90a 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -304,22 +304,24 @@ pub fn get_vtable_index_of_object_method<'tcx, N>( tcx: TyCtxt<'tcx>, object: &super::ImplSourceObjectData<'tcx, N>, method_def_id: DefId, -) -> usize { +) -> Option<usize> { let existential_trait_ref = object .upcast_trait_ref .map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)); let existential_trait_ref = tcx.erase_regions(existential_trait_ref); + // Count number of methods preceding the one we are selecting and // add them to the total offset. - let index = tcx + if let Some(index) = tcx .own_existential_vtable_entries(existential_trait_ref) .iter() .copied() .position(|def_id| def_id == method_def_id) - .unwrap_or_else(|| { - bug!("get_vtable_index_of_object_method: {:?} was not found", method_def_id); - }); - object.vtable_base + index + { + Some(object.vtable_base + index) + } else { + None + } } pub fn closure_trait_ref_and_return_type<'tcx>( |
