Skip to content

Commit b96ad1c

Browse files
committed
return const_error when ty has errors
1 parent 33b55ac commit b96ad1c

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
501501
}
502502
GenericParamDefKind::Const { has_default } => {
503503
let ty = tcx.at(self.span).type_of(param.def_id);
504+
if ty.references_error() {
505+
return tcx.const_error(ty).into();
506+
}
504507
if !infer_args && has_default {
505508
tcx.bound_const_param_default(param.def_id)
506509
.subst(tcx, substs.unwrap())

src/test/ui/consts/issue-103790.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
struct S<const S: (), const S: S = { S }>;
5+
//~^ ERROR the name `S` is already used for a generic parameter in this item's generic parameters
6+
//~| ERROR missing generics for struct `S`
7+
//~| ERROR cycle detected when computing type of `S::S`
8+
//~| ERROR cycle detected when computing type of `S`
9+
10+
fn main() {}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
error[E0403]: the name `S` is already used for a generic parameter in this item's generic parameters
2+
--> $DIR/issue-103790.rs:4:29
3+
|
4+
LL | struct S<const S: (), const S: S = { S }>;
5+
| - ^ already used
6+
| |
7+
| first use of `S`
8+
9+
error[E0107]: missing generics for struct `S`
10+
--> $DIR/issue-103790.rs:4:32
11+
|
12+
LL | struct S<const S: (), const S: S = { S }>;
13+
| ^ expected at least 1 generic argument
14+
|
15+
note: struct defined here, with at least 1 generic parameter: `S`
16+
--> $DIR/issue-103790.rs:4:8
17+
|
18+
LL | struct S<const S: (), const S: S = { S }>;
19+
| ^ -----------
20+
help: add missing generic argument
21+
|
22+
LL | struct S<const S: (), const S: S<S> = { S }>;
23+
| ~~~~
24+
25+
error[E0391]: cycle detected when computing type of `S::S`
26+
--> $DIR/issue-103790.rs:4:32
27+
|
28+
LL | struct S<const S: (), const S: S = { S }>;
29+
| ^
30+
|
31+
= note: ...which immediately requires computing type of `S::S` again
32+
note: cycle used when computing type of `S`
33+
--> $DIR/issue-103790.rs:4:1
34+
|
35+
LL | struct S<const S: (), const S: S = { S }>;
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
38+
error[E0391]: cycle detected when computing type of `S`
39+
--> $DIR/issue-103790.rs:4:1
40+
|
41+
LL | struct S<const S: (), const S: S = { S }>;
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43+
|
44+
note: ...which requires computing type of `S::S`...
45+
--> $DIR/issue-103790.rs:4:32
46+
|
47+
LL | struct S<const S: (), const S: S = { S }>;
48+
| ^
49+
= note: ...which again requires computing type of `S`, completing the cycle
50+
note: cycle used when collecting item types in top-level module
51+
--> $DIR/issue-103790.rs:1:1
52+
|
53+
LL | / #![feature(generic_const_exprs)]
54+
LL | | #![allow(incomplete_features)]
55+
LL | |
56+
LL | | struct S<const S: (), const S: S = { S }>;
57+
... |
58+
LL | |
59+
LL | | fn main() {}
60+
| |____________^
61+
62+
error: aborting due to 4 previous errors
63+
64+
Some errors have detailed explanations: E0107, E0391, E0403.
65+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)