Skip to content

Commit d5e24dc

Browse files
committed
Fix integer overflow
1 parent 734ce4a commit d5e24dc

File tree

1 file changed

+8
-6
lines changed
  • src/librustc_typeck/check

1 file changed

+8
-6
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4997,18 +4997,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49974997
} else {
49984998
0
49994999
};
5000-
let param_idx = param.index as usize - has_self as usize - lifetime_offset;
5000+
let param_idx = (param.index as usize - has_self as usize)
5001+
.saturating_sub(lifetime_offset);
50015002
if let Some(arg) = data.args.get(param_idx) {
5002-
return match param.kind {
5003+
match param.kind {
50035004
GenericParamDefKind::Lifetime => match arg {
50045005
GenericArg::Lifetime(lt) => {
5005-
AstConv::ast_region_to_region(self, lt, Some(param)).into()
5006+
return AstConv::ast_region_to_region(self,
5007+
lt, Some(param)).into();
50065008
}
5007-
_ => bug!("expected a lifetime arg"),
5009+
_ => {}
50085010
}
50095011
GenericParamDefKind::Type { .. } => match arg {
5010-
GenericArg::Type(ty) => self.to_ty(ty).into(),
5011-
_ => bug!("expected a type arg"),
5012+
GenericArg::Type(ty) => return self.to_ty(ty).into(),
5013+
_ => {}
50125014
}
50135015
}
50145016
}

0 commit comments

Comments
 (0)