forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#62423 - Aaron1011:fix/existential-cycle, r=…
…oli-obk Fix cycle error with existential types Fixes rust-lang#61863 We now allow uses of `existential type`'s that aren't defining uses - that is, uses which don't constrain the underlying concrete type. To make this work correctly, we also modify `eq_opaque_type_and_type` to not try to apply additional constraints to an opaque type. If we have code like this: ```rust existential type Foo; fn foo1() -> Foo { ... } fn foo2() -> Foo { foo1() } ``` then `foo2` doesn't end up constraining `Foo`, which means that `foo2` will end up using the type `Foo` internally - that is, an actual `TyKind::Opaque`. We don't want to equate this to the underlying concrete type - we just need to enforce the basic equality constraint between the two types (here, the return type of `foo1` and the return type of `foo2`)
- Loading branch information
Showing
12 changed files
with
158 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/ui/existential_types/existential-types-with-cycle-error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 1 addition & 23 deletions
24
src/test/ui/existential_types/existential-types-with-cycle-error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,8 @@ | ||
error[E0391]: cycle detected when processing `Foo` | ||
error: could not find defining uses | ||
--> $DIR/existential-types-with-cycle-error.rs:3:1 | ||
| | ||
LL | existential type Foo: Fn() -> Foo; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: ...which requires processing `crash`... | ||
--> $DIR/existential-types-with-cycle-error.rs:6:25 | ||
| | ||
LL | fn crash(x: Foo) -> Foo { | ||
| _________________________^ | ||
LL | | x | ||
LL | | } | ||
| |_^ | ||
= note: ...which again requires processing `Foo`, completing the cycle | ||
note: cycle used when collecting item types in top-level module | ||
--> $DIR/existential-types-with-cycle-error.rs:1:1 | ||
| | ||
LL | / #![feature(existential_type)] | ||
LL | | | ||
LL | | existential type Foo: Fn() -> Foo; | ||
LL | | | ||
... | | ||
LL | | | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 1 addition & 23 deletions
24
src/test/ui/existential_types/existential-types-with-cycle-error2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,8 @@ | ||
error[E0391]: cycle detected when processing `Foo` | ||
error: could not find defining uses | ||
--> $DIR/existential-types-with-cycle-error2.rs:7:1 | ||
| | ||
LL | existential type Foo: Bar<Foo, Item = Foo>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: ...which requires processing `crash`... | ||
--> $DIR/existential-types-with-cycle-error2.rs:10:25 | ||
| | ||
LL | fn crash(x: Foo) -> Foo { | ||
| _________________________^ | ||
LL | | x | ||
LL | | } | ||
| |_^ | ||
= note: ...which again requires processing `Foo`, completing the cycle | ||
note: cycle used when collecting item types in top-level module | ||
--> $DIR/existential-types-with-cycle-error2.rs:1:1 | ||
| | ||
LL | / #![feature(existential_type)] | ||
LL | | | ||
LL | | pub trait Bar<T> { | ||
LL | | type Item; | ||
... | | ||
LL | | | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// check-pass | ||
|
||
#![feature(existential_type)] | ||
// Currently, the `existential_type` feature implicitly | ||
// depends on `impl_trait_in_bindings` in order to work properly. | ||
// Specifically, this line requires `impl_trait_in_bindings` to be enabled: | ||
// https://github.com/rust-lang/rust/blob/481068a707679257e2a738b40987246e0420e787/src/librustc_typeck/check/mod.rs#L856 | ||
#![feature(impl_trait_in_bindings)] | ||
//~^ WARN the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash | ||
|
||
// Ensures that `const` items can constrain an `existential type`. | ||
|
||
use std::fmt::Debug; | ||
|
||
pub existential type Foo: Debug; | ||
|
||
const _FOO: Foo = 5; | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash | ||
--> $DIR/existential_type_const.rs:8:12 | ||
| | ||
LL | #![feature(impl_trait_in_bindings)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// check-pass | ||
|
||
#![feature(existential_type)] | ||
|
||
// Regression test for issue #61863 | ||
|
||
pub trait MyTrait {} | ||
|
||
#[derive(Debug)] | ||
pub struct MyStruct { | ||
v: u64 | ||
} | ||
|
||
impl MyTrait for MyStruct {} | ||
|
||
pub fn bla() -> TE { | ||
return MyStruct {v:1} | ||
} | ||
|
||
pub fn bla2() -> TE { | ||
bla() | ||
} | ||
|
||
|
||
existential type TE: MyTrait; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// check-pass | ||
|
||
#![feature(existential_type)] | ||
#![allow(dead_code)] | ||
|
||
pub trait MyTrait {} | ||
|
||
impl MyTrait for bool {} | ||
|
||
struct Blah { | ||
my_foo: Foo, | ||
my_u8: u8 | ||
} | ||
|
||
impl Blah { | ||
fn new() -> Blah { | ||
Blah { | ||
my_foo: make_foo(), | ||
my_u8: 12 | ||
} | ||
} | ||
fn into_inner(self) -> (Foo, u8) { | ||
(self.my_foo, self.my_u8) | ||
} | ||
} | ||
|
||
fn make_foo() -> Foo { | ||
true | ||
} | ||
|
||
existential type Foo: MyTrait; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 1 addition & 20 deletions
21
src/test/ui/existential_types/no_inferrable_concrete_type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,8 @@ | ||
error[E0391]: cycle detected when processing `Foo` | ||
error: could not find defining uses | ||
--> $DIR/no_inferrable_concrete_type.rs:6:1 | ||
| | ||
LL | existential type Foo: Copy; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: ...which requires processing `bar`... | ||
--> $DIR/no_inferrable_concrete_type.rs:9:23 | ||
| | ||
LL | fn bar(x: Foo) -> Foo { x } | ||
| ^^^^^ | ||
= note: ...which again requires processing `Foo`, completing the cycle | ||
note: cycle used when collecting item types in top-level module | ||
--> $DIR/no_inferrable_concrete_type.rs:4:1 | ||
| | ||
LL | / #![feature(existential_type)] | ||
LL | | | ||
LL | | existential type Foo: Copy; | ||
LL | | | ||
... | | ||
LL | | let _: Foo = std::mem::transmute(0u8); | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |