Add tests
This commit is contained in:
parent
e8fa74ae45
commit
81badff860
@ -0,0 +1,5 @@
|
|||||||
|
trait Foo {
|
||||||
|
fn bar() -> impl Sized; //~ ERROR `impl Trait` only allowed in function and inherent method return types, not in trait method return
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,9 @@
|
|||||||
|
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait method return
|
||||||
|
--> $DIR/feature-gate-return_position_impl_trait_in_trait.rs:2:17
|
||||||
|
|
|
||||||
|
LL | fn bar() -> impl Sized;
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0562`.
|
13
src/test/ui/impl-trait/in-trait/doesnt-satisfy.rs
Normal file
13
src/test/ui/impl-trait/in-trait/doesnt-satisfy.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#![feature(return_position_impl_trait_in_trait)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn bar() -> impl std::fmt::Display;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for () {
|
||||||
|
fn bar() -> () {}
|
||||||
|
//~^ ERROR `()` doesn't implement `std::fmt::Display`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
17
src/test/ui/impl-trait/in-trait/doesnt-satisfy.stderr
Normal file
17
src/test/ui/impl-trait/in-trait/doesnt-satisfy.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
error[E0277]: `()` doesn't implement `std::fmt::Display`
|
||||||
|
--> $DIR/doesnt-satisfy.rs:9:17
|
||||||
|
|
|
||||||
|
LL | fn bar() -> () {}
|
||||||
|
| ^^ `()` cannot be formatted with the default formatter
|
||||||
|
|
|
||||||
|
= help: the trait `std::fmt::Display` is not implemented for `()`
|
||||||
|
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
|
||||||
|
note: required by a bound in `Foo::bar::{opaque#0}`
|
||||||
|
--> $DIR/doesnt-satisfy.rs:5:22
|
||||||
|
|
|
||||||
|
LL | fn bar() -> impl std::fmt::Display;
|
||||||
|
| ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::bar::{opaque#0}`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
19
src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs
Normal file
19
src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#![feature(return_position_impl_trait_in_trait)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn bar(&self) -> impl Display;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for () {
|
||||||
|
fn bar(&self) -> impl Display {
|
||||||
|
"Hello, world"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: &str = ().bar();
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/opaque-in-impl-is-opaque.rs:17:19
|
||||||
|
|
|
||||||
|
LL | fn bar(&self) -> impl Display {
|
||||||
|
| ------------ the found opaque type
|
||||||
|
...
|
||||||
|
LL | let x: &str = ().bar();
|
||||||
|
| ---- ^^^^^^^^ expected `&str`, found opaque type
|
||||||
|
| |
|
||||||
|
| expected due to this
|
||||||
|
|
|
||||||
|
= note: expected reference `&str`
|
||||||
|
found opaque type `impl std::fmt::Display`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
20
src/test/ui/impl-trait/in-trait/opaque-in-impl.rs
Normal file
20
src/test/ui/impl-trait/in-trait/opaque-in-impl.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(return_position_impl_trait_in_trait)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn bar(&self) -> impl Display;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for () {
|
||||||
|
fn bar(&self) -> impl Display {
|
||||||
|
"Hello, world"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", ().bar());
|
||||||
|
}
|
40
src/test/ui/impl-trait/in-trait/success.rs
Normal file
40
src/test/ui/impl-trait/in-trait/success.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(return_position_impl_trait_in_trait)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn bar(&self) -> impl Display;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for i32 {
|
||||||
|
fn bar(&self) -> i32 {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for &'static str {
|
||||||
|
fn bar(&self) -> &'static str {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Yay;
|
||||||
|
|
||||||
|
impl Foo for Yay {
|
||||||
|
fn bar(&self) -> String {
|
||||||
|
String::from(":^)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo_generically<T: Foo>(t: T) {
|
||||||
|
println!("{}", t.bar());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", "Hello, world.".bar());
|
||||||
|
println!("The answer is {}!", 42.bar());
|
||||||
|
foo_generically(Yay);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user