Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Const-Generic Cycle ICE #74199 #74991

Merged
merged 2 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/librustc_typeck/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_sig(current_item, tcx.fn_sig(def_id), self.covariant);
}

_ => {
span_bug!(
tcx.def_span(def_id),
"`build_constraints_for_item` unsupported for this item"
);
}
_ => {}
lcnr marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/const-generics/nested-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(const_generics)]
#![allow(incomplete_features)]

struct Foo<const N: [u8; {
//~^ ERROR cycle detected
//~| ERROR cycle detected
struct Foo<const N: usize>;

impl<const N: usize> Foo<N> {
fn value() -> usize {
N
}
}

Foo::<17>::value()
}]>;

fn main() {}
159 changes: 159 additions & 0 deletions src/test/ui/const-generics/nested-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
error[E0391]: cycle detected when computing type of `Foo`
--> $DIR/nested-type.rs:4:1
|
LL | struct Foo<const N: [u8; {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing type of `Foo::N`...
--> $DIR/nested-type.rs:4:18
|
LL | struct Foo<const N: [u8; {
| ^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires type-checking `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`...
--> $DIR/nested-type.rs:7:5
|
LL | struct Foo<const N: usize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires computing type of `Foo`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/nested-type.rs:1:1
|
LL | / #![feature(const_generics)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | struct Foo<const N: [u8; {
... |
LL | |
LL | | fn main() {}
| |____________^

error[E0391]: cycle detected when computing type of `Foo`
--> $DIR/nested-type.rs:4:1
|
LL | struct Foo<const N: [u8; {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing type of `Foo::N`...
--> $DIR/nested-type.rs:4:18
|
LL | struct Foo<const N: [u8; {
| ^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires type-checking `Foo::{{constant}}#0`...
--> $DIR/nested-type.rs:4:26
|
LL | struct Foo<const N: [u8; {
| __________________________^
LL | |
LL | |
LL | | struct Foo<const N: usize>;
... |
LL | | Foo::<17>::value()
LL | | }]>;
| |_^
note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`...
--> $DIR/nested-type.rs:7:5
|
LL | struct Foo<const N: usize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires computing type of `Foo`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/nested-type.rs:1:1
|
LL | / #![feature(const_generics)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | struct Foo<const N: [u8; {
... |
LL | |
LL | | fn main() {}
| |____________^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.