add regression tests for opaque types in impl headers
This commit is contained in:
parent
7d5bbf55f2
commit
d652cd4959
4 changed files with 92 additions and 0 deletions
|
@ -0,0 +1,23 @@
|
||||||
|
// Regression test for issues #84660 and #86411: both are variations on #76202.
|
||||||
|
// Tests that we don't ICE when we have an opaque type appearing anywhere in an impl header.
|
||||||
|
|
||||||
|
#![feature(min_type_alias_impl_trait)]
|
||||||
|
|
||||||
|
trait Foo {}
|
||||||
|
impl Foo for () {}
|
||||||
|
type Bar = impl Foo;
|
||||||
|
fn _defining_use() -> Bar {}
|
||||||
|
|
||||||
|
trait TraitArg<T> {
|
||||||
|
fn f();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TraitArg<Bar> for () { //~ ERROR cannot implement trait
|
||||||
|
fn f() {
|
||||||
|
println!("ho");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
<() as TraitArg<Bar>>::f();
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
error: cannot implement trait on type alias impl trait
|
||||||
|
--> $DIR/issue-84660-trait-impl-for-tait.rs:15:1
|
||||||
|
|
|
||||||
|
LL | impl TraitArg<Bar> for () {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: type alias impl trait defined here
|
||||||
|
--> $DIR/issue-84660-trait-impl-for-tait.rs:8:12
|
||||||
|
|
|
||||||
|
LL | type Bar = impl Foo;
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
41
src/test/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
Normal file
41
src/test/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Another example from issue #84660, this time weaponized as a safe transmut: an opaque type in an
|
||||||
|
// impl header being accepted was used to create unsoundness.
|
||||||
|
|
||||||
|
#![feature(min_type_alias_impl_trait)]
|
||||||
|
|
||||||
|
trait Foo {}
|
||||||
|
impl Foo for () {}
|
||||||
|
type Bar = impl Foo;
|
||||||
|
fn _defining_use() -> Bar {}
|
||||||
|
|
||||||
|
trait Trait<T, In> {
|
||||||
|
type Out;
|
||||||
|
fn convert(i: In) -> Self::Out;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<In, Out> Trait<Bar, In> for Out { //~ ERROR cannot implement trait
|
||||||
|
type Out = Out;
|
||||||
|
fn convert(_i: In) -> Self::Out {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<In, Out> Trait<(), In> for Out {
|
||||||
|
type Out = In;
|
||||||
|
fn convert(i: In) -> Self::Out {
|
||||||
|
i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn transmute<In, Out>(i: In) -> Out {
|
||||||
|
<Out as Trait<Bar, In>>::convert(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let d;
|
||||||
|
{
|
||||||
|
let x = "Hello World".to_string();
|
||||||
|
d = transmute::<&String, &String>(&x);
|
||||||
|
}
|
||||||
|
println!("{}", d);
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
error: cannot implement trait on type alias impl trait
|
||||||
|
--> $DIR/issue-84660-unsoundness.rs:16:1
|
||||||
|
|
|
||||||
|
LL | impl<In, Out> Trait<Bar, In> for Out {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: type alias impl trait defined here
|
||||||
|
--> $DIR/issue-84660-unsoundness.rs:8:12
|
||||||
|
|
|
||||||
|
LL | type Bar = impl Foo;
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue