@@ -38,17 +38,6 @@ LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
38
38
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
39
39
= note: the return type of a function must have a statically known size
40
40
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
-
52
41
error[E0746]: return type cannot have a bare trait because it must be `Sized`
53
42
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
54
43
|
@@ -61,19 +50,8 @@ help: you can use the `impl Trait` feature in the return type because all the re
61
50
LL | fn bap() -> impl Trait { Struct }
62
51
| ^^^^^^^^^^
63
52
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
-
75
53
error[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
77
55
|
78
56
LL | fn ban() -> dyn Trait { Struct }
79
57
| ^^^^^^^^^ doesn't have a size known at compile-time
@@ -85,7 +63,7 @@ LL | fn ban() -> impl Trait { Struct }
85
63
| ^^^^^^^^^^
86
64
87
65
error[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
89
67
|
90
68
LL | fn bak() -> dyn Trait { unimplemented!() }
91
69
| ^^^^^^^^^ doesn't have a size known at compile-time
@@ -94,26 +72,14 @@ LL | fn bak() -> dyn Trait { unimplemented!() }
94
72
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
95
73
= note: the return type of a function must have a statically known size
96
74
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
-
109
75
error[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
111
77
|
112
78
LL | fn bal() -> dyn Trait {
113
79
| ^^^^^^^^^ doesn't have a size known at compile-time
114
80
|
115
81
help: 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
117
83
|
118
84
LL | return Struct;
119
85
| ^^^^^^
@@ -132,20 +98,8 @@ LL | }
132
98
LL | Box::new(42)
133
99
|
134
100
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
-
147
101
error[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
149
103
|
150
104
LL | fn bat() -> dyn Trait {
151
105
| ^^^^^^^^^ 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
156
110
LL | fn bat() -> impl Trait {
157
111
| ^^^^^^^^^^
158
112
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
184
114
185
115
Some errors have detailed explanations: E0277, E0308.
186
116
For more information about an error, try `rustc --explain E0277`.
0 commit comments