about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-05-30 10:53:07 +0200
committerGitHub <noreply@github.com>2019-05-30 10:53:07 +0200
commit528972a28aa9e7e303e2283a31469c12c3d87e23 (patch)
treec960557e317e8e2d73db61fd13894d62884b2a66
parent6282fae46f34cdf1700a218120655ce1582c4e07 (diff)
parent998ef688a39a1b842b5d0a71ea92a8f825650975 (diff)
Rollup merge of #61333 - varkor:apit-const-param-ice, r=estebank
Fix ICE with APIT in a function with a const parameter

Fixes https://github.com/rust-lang/rust/issues/60953.
-rw-r--r--src/librustc/hir/lowering.rs12
-rw-r--r--src/test/ui/const-generics/apit-with-const-param.rs10
-rw-r--r--src/test/ui/const-generics/apit-with-const-param.stderr6
3 files changed, 28 insertions, 0 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index c5bcddcb266..08fbd0d20d7 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -1083,6 +1083,18 @@ impl<'a> LoweringContext<'a> {
             .chain(in_band_defs)
             .collect();
 
+        // FIXME(const_generics): the compiler doesn't always cope with
+        // unsorted generic parameters at the moment, so we make sure
+        // that they're ordered correctly here for now. (When we chain
+        // the `in_band_defs`, we might make the order unsorted.)
+        lowered_generics.params.sort_by_key(|param| {
+            match param.kind {
+                hir::GenericParamKind::Lifetime { .. } => ParamKindOrd::Lifetime,
+                hir::GenericParamKind::Type { .. } => ParamKindOrd::Type,
+                hir::GenericParamKind::Const { .. } => ParamKindOrd::Const,
+            }
+        });
+
         (lowered_generics, res)
     }
 
diff --git a/src/test/ui/const-generics/apit-with-const-param.rs b/src/test/ui/const-generics/apit-with-const-param.rs
new file mode 100644
index 00000000000..70e718d8890
--- /dev/null
+++ b/src/test/ui/const-generics/apit-with-const-param.rs
@@ -0,0 +1,10 @@
+// run-pass
+
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+trait Trait {}
+
+fn f<const N: usize>(_: impl Trait) {}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/apit-with-const-param.stderr b/src/test/ui/const-generics/apit-with-const-param.stderr
new file mode 100644
index 00000000000..b3038ee6488
--- /dev/null
+++ b/src/test/ui/const-generics/apit-with-const-param.stderr
@@ -0,0 +1,6 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/apit-with-const-param.rs:3:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+