diff options
| author | varkor <github@varkor.com> | 2018-07-02 18:09:15 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-08-19 20:02:32 +0100 |
| commit | d5e24dc121da70027c8320ab03a7ca886d16ca0e (patch) | |
| tree | c306e7157c74a6e3549dcd3ce71472bb8c3211dd | |
| parent | 734ce4ae1a87d83687d6a138f3ac78aa4bf97a8c (diff) | |
Fix integer overflow
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 779cb6f32cd..916261eba22 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4997,18 +4997,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else { 0 }; - let param_idx = param.index as usize - has_self as usize - lifetime_offset; + let param_idx = (param.index as usize - has_self as usize) + .saturating_sub(lifetime_offset); if let Some(arg) = data.args.get(param_idx) { - return match param.kind { + match param.kind { GenericParamDefKind::Lifetime => match arg { GenericArg::Lifetime(lt) => { - AstConv::ast_region_to_region(self, lt, Some(param)).into() + return AstConv::ast_region_to_region(self, + lt, Some(param)).into(); } - _ => bug!("expected a lifetime arg"), + _ => {} } GenericParamDefKind::Type { .. } => match arg { - GenericArg::Type(ty) => self.to_ty(ty).into(), - _ => bug!("expected a type arg"), + GenericArg::Type(ty) => return self.to_ty(ty).into(), + _ => {} } } } |
