about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-11-02 14:47:48 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-11-02 14:47:48 +0900
commitb96ad1c0960bd64fde273efe00df3fbc580a9c0a (patch)
tree68748b0ca3c7ff27702bfa7bb9689d24b4c8bc81
parent33b55ac39fa633d0983fad014469e1036669bf28 (diff)
downloadrust-b96ad1c0960bd64fde273efe00df3fbc580a9c0a.tar.gz
rust-b96ad1c0960bd64fde273efe00df3fbc580a9c0a.zip
return const_error when ty has errors
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/mod.rs3
-rw-r--r--src/test/ui/consts/issue-103790.rs10
-rw-r--r--src/test/ui/consts/issue-103790.stderr65
3 files changed, 78 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs
index 6baf9844977..21e6ab13a59 100644
--- a/compiler/rustc_hir_analysis/src/astconv/mod.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs
@@ -501,6 +501,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                     }
                     GenericParamDefKind::Const { has_default } => {
                         let ty = tcx.at(self.span).type_of(param.def_id);
+                        if ty.references_error() {
+                            return tcx.const_error(ty).into();
+                        }
                         if !infer_args && has_default {
                             tcx.bound_const_param_default(param.def_id)
                                 .subst(tcx, substs.unwrap())
diff --git a/src/test/ui/consts/issue-103790.rs b/src/test/ui/consts/issue-103790.rs
new file mode 100644
index 00000000000..ea3cac605b1
--- /dev/null
+++ b/src/test/ui/consts/issue-103790.rs
@@ -0,0 +1,10 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+struct S<const S: (), const S: S = { S }>;
+//~^ ERROR the name `S` is already used for a generic parameter in this item's generic parameters
+//~| ERROR missing generics for struct `S`
+//~| ERROR cycle detected when computing type of `S::S`
+//~| ERROR cycle detected when computing type of `S`
+
+fn main() {}
diff --git a/src/test/ui/consts/issue-103790.stderr b/src/test/ui/consts/issue-103790.stderr
new file mode 100644
index 00000000000..41b0816dc32
--- /dev/null
+++ b/src/test/ui/consts/issue-103790.stderr
@@ -0,0 +1,65 @@
+error[E0403]: the name `S` is already used for a generic parameter in this item's generic parameters
+  --> $DIR/issue-103790.rs:4:29
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   |                -            ^ already used
+   |                |
+   |                first use of `S`
+
+error[E0107]: missing generics for struct `S`
+  --> $DIR/issue-103790.rs:4:32
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   |                                ^ expected at least 1 generic argument
+   |
+note: struct defined here, with at least 1 generic parameter: `S`
+  --> $DIR/issue-103790.rs:4:8
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   |        ^ -----------
+help: add missing generic argument
+   |
+LL | struct S<const S: (), const S: S<S> = { S }>;
+   |                                ~~~~
+
+error[E0391]: cycle detected when computing type of `S::S`
+  --> $DIR/issue-103790.rs:4:32
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   |                                ^
+   |
+   = note: ...which immediately requires computing type of `S::S` again
+note: cycle used when computing type of `S`
+  --> $DIR/issue-103790.rs:4:1
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0391]: cycle detected when computing type of `S`
+  --> $DIR/issue-103790.rs:4:1
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: ...which requires computing type of `S::S`...
+  --> $DIR/issue-103790.rs:4:32
+   |
+LL | struct S<const S: (), const S: S = { S }>;
+   |                                ^
+   = note: ...which again requires computing type of `S`, completing the cycle
+note: cycle used when collecting item types in top-level module
+  --> $DIR/issue-103790.rs:1:1
+   |
+LL | / #![feature(generic_const_exprs)]
+LL | | #![allow(incomplete_features)]
+LL | |
+LL | | struct S<const S: (), const S: S = { S }>;
+...  |
+LL | |
+LL | | fn main() {}
+   | |____________^
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0107, E0391, E0403.
+For more information about an error, try `rustc --explain E0107`.