Account for diverging types in return impl Trait
This commit is contained in:
parent
6fd564112f
commit
75eabb17ae
3 changed files with 63 additions and 0 deletions
|
|
@ -9,6 +9,11 @@ LL | return 1_i32;
|
|||
LL | }
|
||||
LL | 0_u32
|
||||
| ^^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn Foo>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error[E0277]: cannot add `impl Foo` to `u32`
|
||||
--> $DIR/equality.rs:24:11
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ LL | return 0i32;
|
|||
LL | }
|
||||
LL | 1u32
|
||||
| ^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:13:16
|
||||
|
|
@ -21,6 +26,11 @@ LL | return 0i32;
|
|||
LL | } else {
|
||||
LL | return 1u32;
|
||||
| ^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:22:9
|
||||
|
|
@ -33,6 +43,11 @@ LL | return 0i32;
|
|||
LL | } else {
|
||||
LL | 1u32
|
||||
| ^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error[E0308]: `if` and `else` have incompatible types
|
||||
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:31:9
|
||||
|
|
@ -57,6 +72,11 @@ LL | 0 => return 0i32,
|
|||
| ---- ...is found to be `i32` here
|
||||
LL | _ => 1u32,
|
||||
| ^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:45:5
|
||||
|
|
@ -71,6 +91,11 @@ LL | | 1 => 1u32,
|
|||
LL | | _ => 2u32,
|
||||
LL | | }
|
||||
| |_____^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:59:13
|
||||
|
|
@ -83,6 +108,11 @@ LL | return 0i32;
|
|||
...
|
||||
LL | 1u32
|
||||
| ^^^^ expected `i32`, found `u32`
|
||||
|
|
||||
= note: `impl Trait` as a return type requires that all the returned values must have the same type
|
||||
= help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
|
||||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
|
||||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue