about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-03-22 15:48:34 +0100
committerGitHub <noreply@github.com>2020-03-22 15:48:34 +0100
commit3c8f8b6304e6d8ec735f32a8286a1461f36feeb0 (patch)
treea1044147d280ab775c291d0ce0b34ea9ab8605b6
parentea44d71f9bc76d2136e20553259d43f55f282db1 (diff)
parenta9c2378b7dc365189178130d3d3b701aec3809aa (diff)
downloadrust-3c8f8b6304e6d8ec735f32a8286a1461f36feeb0.tar.gz
rust-3c8f8b6304e6d8ec735f32a8286a1461f36feeb0.zip
Rollup merge of #70223 - lcnr:issue70167, r=eddyb
fix type of const params in associated types.

fixes #66906
fixes #70167

r? @eddyb
-rw-r--r--src/librustc_typeck/collect/type_of.rs20
-rw-r--r--src/test/ui/const-generics/issues/issue-66906.rs12
-rw-r--r--src/test/ui/const-generics/issues/issue-66906.stderr8
-rw-r--r--src/test/ui/const-generics/issues/issue-70167.rs10
-rw-r--r--src/test/ui/const-generics/issues/issue-70167.stderr8
5 files changed, 54 insertions, 4 deletions
diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs
index 44ef4ebd463..55642dfb455 100644
--- a/src/librustc_typeck/collect/type_of.rs
+++ b/src/librustc_typeck/collect/type_of.rs
@@ -256,15 +256,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
                         // figure out which generic parameter it corresponds to and return
                         // the relevant type.
                         let generics = match path.res {
-                            Res::Def(DefKind::Ctor(..), def_id) => {
+                            Res::Def(DefKind::Ctor(..), def_id)
+                            | Res::Def(DefKind::AssocTy, def_id) => {
                                 tcx.generics_of(tcx.parent(def_id).unwrap())
                             }
                             Res::Def(_, def_id) => tcx.generics_of(def_id),
-                            Res::Err => return tcx.types.err,
                             res => {
                                 tcx.sess.delay_span_bug(
                                     DUMMY_SP,
-                                    &format!("unexpected const parent path def {:?}", res,),
+                                    &format!(
+                                        "unexpected const parent path def, parent: {:?}, def: {:?}",
+                                        parent_node, res
+                                    ),
                                 );
                                 return tcx.types.err;
                             }
@@ -284,7 +287,16 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
                             .map(|param| tcx.type_of(param.def_id))
                             // This is no generic parameter associated with the arg. This is
                             // probably from an extra arg where one is not needed.
-                            .unwrap_or(tcx.types.err)
+                            .unwrap_or_else(|| {
+                                tcx.sess.delay_span_bug(
+                                    DUMMY_SP,
+                                    &format!(
+                                        "missing generic parameter for `AnonConst`, parent {:?}",
+                                        parent_node
+                                    ),
+                                );
+                                tcx.types.err
+                            })
                     } else {
                         tcx.sess.delay_span_bug(
                             DUMMY_SP,
diff --git a/src/test/ui/const-generics/issues/issue-66906.rs b/src/test/ui/const-generics/issues/issue-66906.rs
new file mode 100644
index 00000000000..461fe837dac
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-66906.rs
@@ -0,0 +1,12 @@
+// check-pass
+
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+pub struct Tuple;
+
+pub trait Trait<const I: usize> {
+    type Input: From<<Self as Trait<I>>::Input>;
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-66906.stderr b/src/test/ui/const-generics/issues/issue-66906.stderr
new file mode 100644
index 00000000000..f8710b67b68
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-66906.stderr
@@ -0,0 +1,8 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/issue-66906.rs:3:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
diff --git a/src/test/ui/const-generics/issues/issue-70167.rs b/src/test/ui/const-generics/issues/issue-70167.rs
new file mode 100644
index 00000000000..58fac8e0511
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-70167.rs
@@ -0,0 +1,10 @@
+// check-pass
+
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+pub trait Trait<const N: usize>: From<<Self as Trait<N>>::Item> {
+  type Item;
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-70167.stderr b/src/test/ui/const-generics/issues/issue-70167.stderr
new file mode 100644
index 00000000000..4ba3c204097
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-70167.stderr
@@ -0,0 +1,8 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/issue-70167.rs:3:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+