about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-05-03 14:41:47 +0100
committervarkor <github@varkor.com>2019-05-04 14:39:43 +0100
commit0439efbbee8eae0fff98640697adb00d0b0b9357 (patch)
treebe82a5b90ecdf87e0b4896de7c8f22a8416cf8e4 /src
parentd0a6ddfe10a1b0002e76c82696c8a093d87dc155 (diff)
Improve subst error when parameter kinds mismatch
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/subst.rs53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs
index ed3da31fb89..8d51fbc174a 100644
--- a/src/librustc/ty/subst.rs
+++ b/src/librustc/ty/subst.rs
@@ -550,17 +550,32 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
         let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
         let ty = match opt_ty {
             Some(UnpackedKind::Type(ty)) => ty,
-            _ => {
+            Some(kind) => {
                 let span = self.span.unwrap_or(DUMMY_SP);
                 span_bug!(
                     span,
-                    "Type parameter `{:?}` ({:?}/{}) out of range \
+                    "expected type for `{:?}` ({:?}/{}) but found {:?} \
                      when substituting (root type={:?}) substs={:?}",
                     p,
                     source_ty,
                     p.idx,
+                    kind,
                     self.root_ty,
-                    self.substs);
+                    self.substs,
+                );
+            }
+            None => {
+                let span = self.span.unwrap_or(DUMMY_SP);
+                span_bug!(
+                    span,
+                    "type parameter `{:?}` ({:?}/{}) out of range \
+                     when substituting (root type={:?}) substs={:?}",
+                    p,
+                    source_ty,
+                    p.idx,
+                    self.root_ty,
+                    self.substs,
+                );
             }
         };
 
@@ -570,29 +585,41 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
     fn const_for_param(
         &self,
         p: ParamConst,
-        source_cn: &'tcx ty::Const<'tcx>
+        source_ct: &'tcx ty::Const<'tcx>
     ) -> &'tcx ty::Const<'tcx> {
         // Look up the const in the substitutions. It really should be in there.
-        let opt_cn = self.substs.get(p.index as usize).map(|k| k.unpack());
-        let cn = match opt_cn {
-            Some(UnpackedKind::Const(cn)) => cn,
-            _ => {
+        let opt_ct = self.substs.get(p.index as usize).map(|k| k.unpack());
+        let ct = match opt_ct {
+            Some(UnpackedKind::Const(ct)) => ct,
+            Some(kind) => {
                 let span = self.span.unwrap_or(DUMMY_SP);
                 span_bug!(
                     span,
-                    "Const parameter `{:?}` ({:?}/{}) out of range \
-                     when substituting (root type={:?}) substs={:?}",
+                    "expected const for `{:?}` ({:?}/{}) but found {:?} \
+                     when substituting substs={:?}",
                     p,
-                    source_cn,
+                    source_ct,
+                    p.index,
+                    kind,
+                    self.substs,
+                );
+            }
+            None => {
+                let span = self.span.unwrap_or(DUMMY_SP);
+                span_bug!(
+                    span,
+                    "const parameter `{:?}` ({:?}/{}) out of range \
+                     when substituting substs={:?}",
+                    p,
+                    source_ct,
                     p.index,
-                    self.root_ty,
                     self.substs,
                 );
             }
         };
 
         // FIXME(const_generics): shift const through binders
-        cn
+        ct
     }
 
     /// It is sometimes necessary to adjust the De Bruijn indices during substitution. This occurs