Skip to content

Commit ff82aa5

Browse files
committed
Add some regression tests for opaque types and const generics
1 parent f2798ae commit ff82aa5

File tree

6 files changed

+142
-2
lines changed

6 files changed

+142
-2
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
429429
// as the cause of an overflow.
430430
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
431431
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
432-
DefineOpaqueTypes::No,
432+
DefineOpaqueTypes::Yes,
433433
ct.ty(),
434434
ty,
435435
) {

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
998998
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
999999
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
10001000
match self.infcx.at(&obligation.cause, obligation.param_env).eq(
1001-
DefineOpaqueTypes::No,
1001+
DefineOpaqueTypes::Yes,
10021002
ct.ty(),
10031003
ty,
10041004
) {
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl Sized;
4+
//~^ ERROR: cycle
5+
6+
fn foo<const C: Foo>() {}
7+
//~^ ERROR: `Foo` is forbidden as the type of a const generic parameter
8+
9+
fn main() {
10+
foo::<42>();
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
error[E0391]: cycle detected when computing type of `Foo::{opaque#0}`
2+
--> $DIR/opaque_types.rs:3:12
3+
|
4+
LL | type Foo = impl Sized;
5+
| ^^^^^^^^^^
6+
|
7+
note: ...which requires computing type of opaque `Foo::{opaque#0}`...
8+
--> $DIR/opaque_types.rs:3:12
9+
|
10+
LL | type Foo = impl Sized;
11+
| ^^^^^^^^^^
12+
note: ...which requires type-checking `main`...
13+
--> $DIR/opaque_types.rs:9:1
14+
|
15+
LL | fn main() {
16+
| ^^^^^^^^^
17+
note: ...which requires evaluating type-level constant...
18+
--> $DIR/opaque_types.rs:10:11
19+
|
20+
LL | foo::<42>();
21+
| ^^
22+
note: ...which requires const-evaluating + checking `main::{constant#0}`...
23+
--> $DIR/opaque_types.rs:10:11
24+
|
25+
LL | foo::<42>();
26+
| ^^
27+
note: ...which requires caching mir of `main::{constant#0}` for CTFE...
28+
--> $DIR/opaque_types.rs:10:11
29+
|
30+
LL | foo::<42>();
31+
| ^^
32+
note: ...which requires elaborating drops for `main::{constant#0}`...
33+
--> $DIR/opaque_types.rs:10:11
34+
|
35+
LL | foo::<42>();
36+
| ^^
37+
= note: ...which requires normalizing `Foo`...
38+
= note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle
39+
note: cycle used when checking that `Foo::{opaque#0}` is well-formed
40+
--> $DIR/opaque_types.rs:3:12
41+
|
42+
LL | type Foo = impl Sized;
43+
| ^^^^^^^^^^
44+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
45+
46+
error: `Foo` is forbidden as the type of a const generic parameter
47+
--> $DIR/opaque_types.rs:6:17
48+
|
49+
LL | fn foo<const C: Foo>() {}
50+
| ^^^
51+
|
52+
= note: the only supported types are integers, `bool` and `char`
53+
54+
error: aborting due to 2 previous errors
55+
56+
For more information about this error, try `rustc --explain E0391`.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl Sized;
4+
//~^ ERROR: cycle
5+
6+
fn foo<const C: u32>() {}
7+
8+
const C: Foo = 42;
9+
10+
fn bar()
11+
where
12+
Foo:,
13+
{
14+
foo::<C>();
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
error[E0391]: cycle detected when computing type of `Foo::{opaque#0}`
2+
--> $DIR/opaque_types2.rs:3:12
3+
|
4+
LL | type Foo = impl Sized;
5+
| ^^^^^^^^^^
6+
|
7+
note: ...which requires computing type of opaque `Foo::{opaque#0}`...
8+
--> $DIR/opaque_types2.rs:3:12
9+
|
10+
LL | type Foo = impl Sized;
11+
| ^^^^^^^^^^
12+
note: ...which requires type-checking `bar`...
13+
--> $DIR/opaque_types2.rs:10:1
14+
|
15+
LL | / fn bar()
16+
LL | | where
17+
LL | | Foo:,
18+
| |_________^
19+
note: ...which requires evaluating type-level constant...
20+
--> $DIR/opaque_types2.rs:14:11
21+
|
22+
LL | foo::<C>();
23+
| ^
24+
note: ...which requires const-evaluating + checking `bar::{constant#0}`...
25+
--> $DIR/opaque_types2.rs:14:11
26+
|
27+
LL | foo::<C>();
28+
| ^
29+
note: ...which requires caching mir of `bar::{constant#0}` for CTFE...
30+
--> $DIR/opaque_types2.rs:14:11
31+
|
32+
LL | foo::<C>();
33+
| ^
34+
note: ...which requires elaborating drops for `bar::{constant#0}`...
35+
--> $DIR/opaque_types2.rs:14:11
36+
|
37+
LL | foo::<C>();
38+
| ^
39+
= note: ...which requires normalizing `Foo`...
40+
= note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle
41+
note: cycle used when checking that `Foo::{opaque#0}` is well-formed
42+
--> $DIR/opaque_types2.rs:3:12
43+
|
44+
LL | type Foo = impl Sized;
45+
| ^^^^^^^^^^
46+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
47+
48+
note: erroneous constant encountered
49+
--> $DIR/opaque_types2.rs:14:11
50+
|
51+
LL | foo::<C>();
52+
| ^
53+
54+
error: aborting due to 1 previous error
55+
56+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)