Skip to content

Commit 5b3f8bb

Browse files
committed
hrtb_start safety
1 parent 0c39eeb commit 5b3f8bb

File tree

1 file changed

+9
-2
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+9
-2
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
876876
_ => None,
877877
});
878878
self.in_scope_lifetimes.extend(lt_def_names);
879+
879880
let hrtb_start = self.hrtb_start;
880-
if matches!(origin, LifetimeOrigin::Hrtb) && self.hrtb_start.is_none() {
881-
self.hrtb_start = Some(old_len);
881+
match (hrtb_start, origin) {
882+
(None, LifetimeOrigin::Hrtb) => self.hrtb_start = Some(old_len),
883+
(Some(idx), LifetimeOrigin::Hrtb) => debug_assert!(idx <= old_len),
884+
(None, LifetimeOrigin::Other) => (),
885+
(Some(idx), LifetimeOrigin::Other) => panic!(
886+
"unexpected lifetime origin inside of hrtb: {:?}, hrtb={:?}, new={:?}",
887+
self.in_scope_lifetimes, idx, old_len
888+
),
882889
}
883890

884891
let res = f(self);

0 commit comments

Comments
 (0)