about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-07-27 22:22:39 +0200
committerCamille GILLOT <gillot.camille@gmail.com>2022-08-03 18:44:19 +0200
commitc95ff1d52bd3d8abec2e39b5b76426e22cc6d582 (patch)
tree9670d42268e8141be7bd9be17058d1190b0b33b5
parenta4240902529b75ed39995f506331eb532a6a0c51 (diff)
downloadrust-c95ff1d52bd3d8abec2e39b5b76426e22cc6d582.tar.gz
rust-c95ff1d52bd3d8abec2e39b5b76426e22cc6d582.zip
Assert index sanity.
-rw-r--r--compiler/rustc_resolve/src/late/lifetimes.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs
index 4c894ccd53d..6ea976a5900 100644
--- a/compiler/rustc_resolve/src/late/lifetimes.rs
+++ b/compiler/rustc_resolve/src/late/lifetimes.rs
@@ -1486,6 +1486,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
 
             let map = &self.map;
             let generics = self.tcx.generics_of(def_id);
+
+            // `type_def_id` points to an item, so there is nothing to inherit generics from.
+            debug_assert_eq!(generics.parent_count, 0);
+
             let set_to_region = |set: ObjectLifetimeDefault| match set {
                 ObjectLifetimeDefault::Empty => {
                     if in_body {
@@ -1496,8 +1500,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
                 }
                 ObjectLifetimeDefault::Static => Some(Region::Static),
                 ObjectLifetimeDefault::Param(param_def_id) => {
-                    let index = generics.param_def_id_to_index[&param_def_id];
-                    generic_args.args.get(index as usize).and_then(|arg| match arg {
+                    // This index can be used with `generic_args` since `parent_count == 0`.
+                    let index = generics.param_def_id_to_index[&param_def_id] as usize;
+                    generic_args.args.get(index).and_then(|arg| match arg {
                         GenericArg::Lifetime(lt) => map.defs.get(&lt.hir_id).copied(),
                         _ => None,
                     })