@@ -38,17 +38,6 @@ LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
3838 = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
3939 = note: the return type of a function must have a statically known size
4040
41- error[E0308]: mismatched types
42- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:21
43- |
44- LL | fn bap() -> Trait { Struct }
45- | ----- ^^^^^^ expected trait `Trait`, found struct `Struct`
46- | |
47- | expected `(dyn Trait + 'static)` because of return type
48- |
49- = note: expected trait object `(dyn Trait + 'static)`
50- found struct `Struct`
51-
5241error[E0746]: return type cannot have a bare trait because it must be `Sized`
5342 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
5443 |
@@ -61,19 +50,8 @@ help: you can use the `impl Trait` feature in the return type because all the re
6150LL | fn bap() -> impl Trait { Struct }
6251 | ^^^^^^^^^^
6352
64- error[E0308]: mismatched types
65- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:16:25
66- |
67- LL | fn ban() -> dyn Trait { Struct }
68- | --------- ^^^^^^ expected trait `Trait`, found struct `Struct`
69- | |
70- | expected `(dyn Trait + 'static)` because of return type
71- |
72- = note: expected trait object `(dyn Trait + 'static)`
73- found struct `Struct`
74-
7553error[E0746]: return type cannot have a bare trait because it must be `Sized`
76- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:16 :13
54+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15 :13
7755 |
7856LL | fn ban() -> dyn Trait { Struct }
7957 | ^^^^^^^^^ doesn't have a size known at compile-time
@@ -85,7 +63,7 @@ LL | fn ban() -> impl Trait { Struct }
8563 | ^^^^^^^^^^
8664
8765error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
88- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19 :13
66+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:17 :13
8967 |
9068LL | fn bak() -> dyn Trait { unimplemented!() }
9169 | ^^^^^^^^^ doesn't have a size known at compile-time
@@ -94,26 +72,14 @@ LL | fn bak() -> dyn Trait { unimplemented!() }
9472 = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
9573 = note: the return type of a function must have a statically known size
9674
97- error[E0308]: mismatched types
98- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:23:16
99- |
100- LL | fn bal() -> dyn Trait {
101- | --------- expected `(dyn Trait + 'static)` because of return type
102- LL | if true {
103- LL | return Struct;
104- | ^^^^^^ expected trait `Trait`, found struct `Struct`
105- |
106- = note: expected trait object `(dyn Trait + 'static)`
107- found struct `Struct`
108-
10975error[E0746]: return type cannot have a bare trait because it must be `Sized`
110- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:21 :13
76+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19 :13
11177 |
11278LL | fn bal() -> dyn Trait {
11379 | ^^^^^^^^^ doesn't have a size known at compile-time
11480 |
11581help: if all the returned values were of the same type you could use `impl Trait` as the return type
116- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:25 :5
82+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:23 :5
11783 |
11884LL | return Struct;
11985 | ^^^^^^
@@ -132,20 +98,8 @@ LL | }
13298LL | Box::new(42)
13399 |
134100
135- error[E0308]: mismatched types
136- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:5
137- |
138- LL | fn bal() -> dyn Trait {
139- | --------- expected `(dyn Trait + 'static)` because of return type
140- ...
141- LL | 42
142- | ^^ expected trait `Trait`, found integer
143- |
144- = note: expected trait object `(dyn Trait + 'static)`
145- found type `{integer}`
146-
147101error[E0746]: return type cannot have a bare trait because it must be `Sized`
148- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:29 :13
102+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:27 :13
149103 |
150104LL | fn bat() -> dyn Trait {
151105 | ^^^^^^^^^ doesn't have a size known at compile-time
@@ -156,31 +110,7 @@ help: you can use the `impl Trait` feature in the return type because all the re
156110LL | fn bat() -> impl Trait {
157111 | ^^^^^^^^^^
158112
159- error[E0308]: mismatched types
160- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:31:16
161- |
162- LL | fn bat() -> dyn Trait {
163- | --------- expected `(dyn Trait + 'static)` because of return type
164- LL | if true {
165- LL | return 0;
166- | ^ expected trait `Trait`, found integer
167- |
168- = note: expected trait object `(dyn Trait + 'static)`
169- found type `{integer}`
170-
171- error[E0308]: mismatched types
172- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:33:5
173- |
174- LL | fn bat() -> dyn Trait {
175- | --------- expected `(dyn Trait + 'static)` because of return type
176- ...
177- LL | 42
178- | ^^ expected trait `Trait`, found integer
179- |
180- = note: expected trait object `(dyn Trait + 'static)`
181- found type `{integer}`
182-
183- error: aborting due to 15 previous errors
113+ error: aborting due to 9 previous errors
184114
185115Some errors have detailed explanations: E0277, E0308.
186116For more information about an error, try `rustc --explain E0277`.
0 commit comments