]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/mod.rs
Fix integer overflow
[rust.git] / src / librustc_typeck / check / mod.rs
index 779cb6f32cd0df9a8e2bf613ac84d53854dd948f..916261eba226a071f5be675677fcf31cc17d18a2 100644 (file)
@@ -4997,18 +4997,20 @@ pub fn instantiate_value_path(&self,
                         } 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(),
+                                    _ => {}
                                 }
                             }
                         }