mirror of
https://github.com/rust-lang/rust
synced 2024-09-06 01:11:17 +00:00
Add some tests
This commit is contained in:
parent
f75361fec7
commit
4e0769956b
13
tests/ui/impl-trait/rpit/early_bound.rs
Normal file
13
tests/ui/impl-trait/rpit/early_bound.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use std::convert::identity;
|
||||
|
||||
fn test<'a: 'a>(n: bool) -> impl Sized + 'a {
|
||||
//~^ ERROR concrete type differs from previous defining opaque type use
|
||||
let true = n else { loop {} };
|
||||
let _ = || {
|
||||
let _ = identity::<&'a ()>(test(false));
|
||||
//~^ ERROR hidden type for `impl Sized + 'a` captures lifetime that does not appear in bounds
|
||||
};
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() {}
|
26
tests/ui/impl-trait/rpit/early_bound.stderr
Normal file
26
tests/ui/impl-trait/rpit/early_bound.stderr
Normal file
|
@ -0,0 +1,26 @@
|
|||
error[E0700]: hidden type for `impl Sized + 'a` captures lifetime that does not appear in bounds
|
||||
--> $DIR/early_bound.rs:7:17
|
||||
|
|
||||
LL | fn test<'a: 'a>(n: bool) -> impl Sized + 'a {
|
||||
| -- --------------- opaque type defined here
|
||||
| |
|
||||
| hidden type `&'a ()` captures the lifetime `'a` as defined here
|
||||
...
|
||||
LL | let _ = identity::<&'a ()>(test(false));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: concrete type differs from previous defining opaque type use
|
||||
--> $DIR/early_bound.rs:3:29
|
||||
|
|
||||
LL | fn test<'a: 'a>(n: bool) -> impl Sized + 'a {
|
||||
| ^^^^^^^^^^^^^^^ expected `&()`, got `()`
|
||||
|
|
||||
note: previous use here
|
||||
--> $DIR/early_bound.rs:7:36
|
||||
|
|
||||
LL | let _ = identity::<&'a ()>(test(false));
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0700`.
|
|
@ -0,0 +1,38 @@
|
|||
//! Check that we cannot instantiate a hidden type in the body
|
||||
//! of an assoc fn or const unless mentioned in the signature.
|
||||
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
trait Trait: Sized {
|
||||
type Assoc;
|
||||
fn foo();
|
||||
fn bar() -> Self::Assoc;
|
||||
}
|
||||
|
||||
impl Trait for () {
|
||||
type Assoc = impl std::fmt::Debug;
|
||||
fn foo() {
|
||||
let x: Self::Assoc = 42; //~ ERROR: mismatched types
|
||||
}
|
||||
fn bar() -> Self::Assoc {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
trait Trait2: Sized {
|
||||
type Assoc;
|
||||
const FOO: ();
|
||||
fn bar() -> Self::Assoc;
|
||||
}
|
||||
|
||||
impl Trait2 for () {
|
||||
type Assoc = impl std::fmt::Debug;
|
||||
const FOO: () = {
|
||||
let x: Self::Assoc = 42; //~ ERROR: mismatched types
|
||||
};
|
||||
fn bar() -> Self::Assoc {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,41 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/impl_trait_in_trait_defined_outside_trait.rs:15:30
|
||||
|
|
||||
LL | type Assoc = impl std::fmt::Debug;
|
||||
| -------------------- the expected opaque type
|
||||
LL | fn foo() {
|
||||
LL | let x: Self::Assoc = 42;
|
||||
| ----------- ^^ expected opaque type, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected opaque type `<() as Trait>::Assoc`
|
||||
found type `{integer}`
|
||||
note: this item must have the opaque type in its signature in order to be able to register hidden types
|
||||
--> $DIR/impl_trait_in_trait_defined_outside_trait.rs:14:8
|
||||
|
|
||||
LL | fn foo() {
|
||||
| ^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/impl_trait_in_trait_defined_outside_trait.rs:31:30
|
||||
|
|
||||
LL | type Assoc = impl std::fmt::Debug;
|
||||
| -------------------- the expected opaque type
|
||||
LL | const FOO: () = {
|
||||
LL | let x: Self::Assoc = 42;
|
||||
| ----------- ^^ expected opaque type, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected opaque type `<() as Trait2>::Assoc`
|
||||
found type `{integer}`
|
||||
note: this item must have the opaque type in its signature in order to be able to register hidden types
|
||||
--> $DIR/impl_trait_in_trait_defined_outside_trait.rs:30:11
|
||||
|
|
||||
LL | const FOO: () = {
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
|
@ -0,0 +1,22 @@
|
|||
//! Check that we cannot instantiate a hidden type from another assoc type.
|
||||
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
trait Trait: Sized {
|
||||
type Assoc;
|
||||
type Foo;
|
||||
fn foo() -> Self::Assoc;
|
||||
}
|
||||
|
||||
impl Trait for () {
|
||||
type Assoc = impl std::fmt::Debug;
|
||||
type Foo = [(); {
|
||||
let x: Self::Assoc = 42; //~ ERROR: mismatched types
|
||||
3
|
||||
}];
|
||||
fn foo() -> Self::Assoc {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,17 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/impl_trait_in_trait_defined_outside_trait2.rs:14:30
|
||||
|
|
||||
LL | type Assoc = impl std::fmt::Debug;
|
||||
| -------------------- the expected opaque type
|
||||
LL | type Foo = [(); {
|
||||
LL | let x: Self::Assoc = 42;
|
||||
| ----------- ^^ expected opaque type, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected opaque type `<() as Trait>::Assoc`
|
||||
found type `{integer}`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
|
@ -0,0 +1,38 @@
|
|||
//! Check that non-defining assoc items can use the opaque type
|
||||
//! opaquely.
|
||||
|
||||
// check-pass
|
||||
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
trait Trait: Sized {
|
||||
type Assoc;
|
||||
fn foo();
|
||||
fn bar() -> Self::Assoc;
|
||||
}
|
||||
|
||||
impl Trait for () {
|
||||
type Assoc = impl std::fmt::Debug;
|
||||
fn foo() {
|
||||
let x: Self::Assoc = Self::bar();
|
||||
}
|
||||
fn bar() -> Self::Assoc {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
trait Trait2: Sized {
|
||||
type Assoc;
|
||||
const FOO: ();
|
||||
const BAR: Self::Assoc;
|
||||
}
|
||||
|
||||
impl Trait2 for () {
|
||||
type Assoc = impl Copy;
|
||||
const FOO: () = {
|
||||
let x: Self::Assoc = Self::BAR;
|
||||
};
|
||||
const BAR: Self::Assoc = "";
|
||||
}
|
||||
|
||||
fn main() {}
|
17
tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs
Normal file
17
tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
trait Foo {
|
||||
type Assoc<'a, 'b>;
|
||||
fn bar<'a: 'a, 'b: 'b>(_: &'a ()) -> Self::Assoc<'a, 'b>;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Assoc<'a, 'b> = impl Sized;
|
||||
fn bar<'a: 'a, 'b: 'b>(x: &'a ()) -> Self::Assoc<'a, 'b> {
|
||||
let closure = |x: &'a ()| -> Self::Assoc<'b, 'a> { x };
|
||||
//~^ ERROR `<() as Foo>::Assoc<'b, 'a>` captures lifetime that does not appear in bounds
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,13 @@
|
|||
error[E0700]: hidden type for `<() as Foo>::Assoc<'b, 'a>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/in-assoc-ty-early-bound.rs:11:60
|
||||
|
|
||||
LL | type Assoc<'a, 'b> = impl Sized;
|
||||
| ---------- opaque type defined here
|
||||
LL | fn bar<'a: 'a, 'b: 'b>(x: &'a ()) -> Self::Assoc<'a, 'b> {
|
||||
| -- hidden type `&'a ()` captures the lifetime `'a` as defined here
|
||||
LL | let closure = |x: &'a ()| -> Self::Assoc<'b, 'a> { x };
|
||||
| ^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0700`.
|
21
tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs
Normal file
21
tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
trait Foo {
|
||||
type Assoc<'a>;
|
||||
fn bar<'a: 'a>();
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Assoc<'a> = impl Sized; //~ ERROR unconstrained opaque type
|
||||
fn bar<'a: 'a>()
|
||||
where
|
||||
Self::Assoc<'a>:,
|
||||
{
|
||||
let _ = |x: &'a ()| {
|
||||
let _: Self::Assoc<'a> = x;
|
||||
//~^ ERROR `<() as Foo>::Assoc<'a>` captures lifetime that does not appear in bound
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,22 @@
|
|||
error[E0700]: hidden type for `<() as Foo>::Assoc<'a>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/in-assoc-ty-early-bound2.rs:15:20
|
||||
|
|
||||
LL | type Assoc<'a> = impl Sized;
|
||||
| ---------- opaque type defined here
|
||||
LL | fn bar<'a: 'a>()
|
||||
| -- hidden type `&'a ()` captures the lifetime `'a` as defined here
|
||||
...
|
||||
LL | let _: Self::Assoc<'a> = x;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: unconstrained opaque type
|
||||
--> $DIR/in-assoc-ty-early-bound2.rs:9:22
|
||||
|
|
||||
LL | type Assoc<'a> = impl Sized;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `Assoc` must be used in combination with a concrete type within the same impl
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0700`.
|
Loading…
Reference in a new issue