2020-01-13 15:13:12 -06:00
|
|
|
#![allow(bare_trait_objects)]
|
|
|
|
struct Struct;
|
|
|
|
trait Trait {}
|
|
|
|
impl Trait for Struct {}
|
|
|
|
impl Trait for u32 {}
|
|
|
|
|
|
|
|
fn fuz() -> (usize, Trait) { (42, Struct) }
|
|
|
|
//~^ ERROR E0277
|
|
|
|
//~| ERROR E0308
|
|
|
|
fn bar() -> (usize, dyn Trait) { (42, Struct) }
|
|
|
|
//~^ ERROR E0277
|
|
|
|
//~| ERROR E0308
|
|
|
|
fn bap() -> Trait { Struct }
|
|
|
|
//~^ ERROR E0746
|
|
|
|
fn ban() -> dyn Trait { Struct }
|
|
|
|
//~^ ERROR E0746
|
2020-04-10 12:19:47 -05:00
|
|
|
fn bak() -> dyn Trait { unimplemented!() } //~ ERROR E0746
|
2020-01-13 15:13:12 -06:00
|
|
|
// Suggest using `Box<dyn Trait>`
|
|
|
|
fn bal() -> dyn Trait { //~ ERROR E0746
|
|
|
|
if true {
|
2020-01-13 18:12:44 -06:00
|
|
|
return Struct;
|
2020-01-13 15:13:12 -06:00
|
|
|
}
|
2020-01-13 18:12:44 -06:00
|
|
|
42
|
2020-01-13 15:13:12 -06:00
|
|
|
}
|
2020-01-24 12:35:13 -06:00
|
|
|
fn bax() -> dyn Trait { //~ ERROR E0746
|
|
|
|
if true {
|
|
|
|
Struct
|
|
|
|
} else {
|
2020-04-11 13:31:54 -05:00
|
|
|
42 //~ ERROR `if` and `else` have incompatible types
|
2020-01-24 12:35:13 -06:00
|
|
|
}
|
|
|
|
}
|
2020-01-23 17:21:15 -06:00
|
|
|
fn bam() -> Box<dyn Trait> {
|
|
|
|
if true {
|
|
|
|
return Struct; //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
42 //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
fn baq() -> Box<dyn Trait> {
|
|
|
|
if true {
|
|
|
|
return 0; //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
42 //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
fn baz() -> Box<dyn Trait> {
|
|
|
|
if true {
|
|
|
|
Struct //~ ERROR mismatched types
|
|
|
|
} else {
|
|
|
|
42 //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn baw() -> Box<dyn Trait> {
|
|
|
|
if true {
|
|
|
|
0 //~ ERROR mismatched types
|
|
|
|
} else {
|
|
|
|
42 //~ ERROR mismatched types
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 15:13:12 -06:00
|
|
|
|
|
|
|
// Suggest using `impl Trait`
|
|
|
|
fn bat() -> dyn Trait { //~ ERROR E0746
|
|
|
|
if true {
|
2020-01-24 13:47:54 -06:00
|
|
|
return 0;
|
2020-01-13 15:13:12 -06:00
|
|
|
}
|
2020-01-24 13:47:54 -06:00
|
|
|
42
|
2020-01-13 15:13:12 -06:00
|
|
|
}
|
2020-01-23 17:21:15 -06:00
|
|
|
fn bay() -> dyn Trait { //~ ERROR E0746
|
|
|
|
if true {
|
2020-01-24 13:47:54 -06:00
|
|
|
0
|
2020-01-23 17:21:15 -06:00
|
|
|
} else {
|
2020-01-24 13:47:54 -06:00
|
|
|
42
|
2020-01-23 17:21:15 -06:00
|
|
|
}
|
|
|
|
}
|
2020-01-13 15:13:12 -06:00
|
|
|
|
|
|
|
fn main() {}
|