]> git.proxmox.com Git - rustc.git/blame - src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / test / ui / impl-trait / dyn-trait-return-should-be-impl-trait.stderr
CommitLineData
dfeec247
XL
1error[E0308]: mismatched types
2 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:35
3 |
4LL | fn fuz() -> (usize, Trait) { (42, Struct) }
5 | ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
6 |
7 = note: expected trait object `(dyn Trait + 'static)`
8 found struct `Struct`
9
10error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
11 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:13
12 |
13LL | fn fuz() -> (usize, Trait) { (42, Struct) }
14 | ^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
15 | |
16 | doesn't have a size known at compile-time
17 |
1b1a35ee 18 = help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
dfeec247
XL
19 = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
20 = note: the return type of a function must have a statically known size
21
22error[E0308]: mismatched types
23 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:39
24 |
25LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
26 | ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
27 |
28 = note: expected trait object `(dyn Trait + 'static)`
29 found struct `Struct`
30
31error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
32 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:13
33 |
34LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
35 | ^^^^^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
36 | |
37 | doesn't have a size known at compile-time
38 |
1b1a35ee 39 = help: within `(usize, (dyn Trait + 'static))`, the trait `Sized` is not implemented for `(dyn Trait + 'static)`
dfeec247
XL
40 = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
41 = note: the return type of a function must have a statically known size
42
43error[E0746]: return type cannot have an unboxed trait object
44 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
45 |
46LL | fn bap() -> Trait { Struct }
47 | ^^^^^ doesn't have a size known at compile-time
48 |
49 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
f9f354fc 50help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
dfeec247
XL
51 |
52LL | fn bap() -> impl Trait { Struct }
53 | ^^^^^^^^^^
54
55error[E0746]: return type cannot have an unboxed trait object
56 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
57 |
58LL | fn ban() -> dyn Trait { Struct }
59 | ^^^^^^^^^ doesn't have a size known at compile-time
60 |
61 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
f9f354fc 62help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
dfeec247
XL
63 |
64LL | fn ban() -> impl Trait { Struct }
65 | ^^^^^^^^^^
66
f9f354fc 67error[E0746]: return type cannot have an unboxed trait object
dfeec247
XL
68 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
69 |
70LL | fn bak() -> dyn Trait { unimplemented!() }
71 | ^^^^^^^^^ doesn't have a size known at compile-time
72 |
f9f354fc
XL
73help: use some type `T` that is `T: Sized` as the return type if all return paths have the same type
74 |
75LL | fn bak() -> T { unimplemented!() }
76 | ^
77help: use `impl Trait` as the return type if all return paths have the same type but you want to expose only the trait in the signature
78 |
79LL | fn bak() -> impl Trait { unimplemented!() }
80 | ^^^^^^^^^^
81help: use a boxed trait object if all return paths implement trait `Trait`
82 |
83LL | fn bak() -> Box<dyn Trait> { unimplemented!() }
84 | ^^^^^^^^^^^^^^
dfeec247
XL
85
86error[E0746]: return type cannot have an unboxed trait object
87 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
88 |
89LL | fn bal() -> dyn Trait {
90 | ^^^^^^^^^ doesn't have a size known at compile-time
91 |
92 = 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>
93 = note: if all the returned values were of the same type you could use `impl Trait` as the return type
94 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
95 = note: you can create a new `enum` with a variant for each returned type
96help: return a boxed trait object instead
97 |
98LL | fn bal() -> Box<dyn Trait> {
99LL | if true {
100LL | return Box::new(Struct);
101LL | }
102LL | Box::new(42)
103 |
104
f9f354fc
XL
105error[E0308]: `if` and `else` have incompatible types
106 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
107 |
108LL | / if true {
109LL | | Struct
110 | | ------ expected because of this
111LL | | } else {
112LL | | 42
113 | | ^^ expected struct `Struct`, found integer
114LL | | }
115 | |_____- `if` and `else` have incompatible types
116
dfeec247
XL
117error[E0746]: return type cannot have an unboxed trait object
118 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:13
119 |
120LL | fn bax() -> dyn Trait {
121 | ^^^^^^^^^ doesn't have a size known at compile-time
122 |
123 = 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>
124 = note: if all the returned values were of the same type you could use `impl Trait` as the return type
125 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
126 = note: you can create a new `enum` with a variant for each returned type
127help: return a boxed trait object instead
128 |
129LL | fn bax() -> Box<dyn Trait> {
130LL | if true {
131LL | Box::new(Struct)
132LL | } else {
133LL | Box::new(42)
134 |
135
136error[E0308]: mismatched types
137 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16
138 |
139LL | fn bam() -> Box<dyn Trait> {
1b1a35ee 140 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
141LL | if true {
142LL | return Struct;
143 | ^^^^^^
144 | |
1b1a35ee 145 | expected struct `Box`, found struct `Struct`
dfeec247
XL
146 | help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
147 |
1b1a35ee 148 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
149 found struct `Struct`
150 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
151
152error[E0308]: mismatched types
153 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
154 |
155LL | fn bam() -> Box<dyn Trait> {
1b1a35ee 156 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
157...
158LL | 42
159 | ^^
160 | |
1b1a35ee 161 | expected struct `Box`, found integer
dfeec247
XL
162 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
163 |
1b1a35ee 164 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
165 found type `{integer}`
166 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
167
168error[E0308]: mismatched types
169 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
170 |
171LL | fn baq() -> Box<dyn Trait> {
1b1a35ee 172 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
173LL | if true {
174LL | return 0;
175 | ^
176 | |
1b1a35ee 177 | expected struct `Box`, found integer
dfeec247
XL
178 | help: store this in the heap by calling `Box::new`: `Box::new(0)`
179 |
1b1a35ee 180 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
181 found type `{integer}`
182 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
183
184error[E0308]: mismatched types
185 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
186 |
187LL | fn baq() -> Box<dyn Trait> {
1b1a35ee 188 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
189...
190LL | 42
191 | ^^
192 | |
1b1a35ee 193 | expected struct `Box`, found integer
dfeec247
XL
194 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
195 |
1b1a35ee 196 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
197 found type `{integer}`
198 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
199
200error[E0308]: mismatched types
201 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
202 |
203LL | fn baz() -> Box<dyn Trait> {
1b1a35ee 204 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
205LL | if true {
206LL | Struct
207 | ^^^^^^
208 | |
1b1a35ee 209 | expected struct `Box`, found struct `Struct`
dfeec247
XL
210 | help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
211 |
1b1a35ee 212 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
213 found struct `Struct`
214 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
215
216error[E0308]: mismatched types
217 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
218 |
219LL | fn baz() -> Box<dyn Trait> {
1b1a35ee 220 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
221...
222LL | 42
223 | ^^
224 | |
1b1a35ee 225 | expected struct `Box`, found integer
dfeec247
XL
226 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
227 |
1b1a35ee 228 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
229 found type `{integer}`
230 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
231
232error[E0308]: mismatched types
233 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
234 |
235LL | fn baw() -> Box<dyn Trait> {
1b1a35ee 236 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
237LL | if true {
238LL | 0
239 | ^
240 | |
1b1a35ee 241 | expected struct `Box`, found integer
dfeec247
XL
242 | help: store this in the heap by calling `Box::new`: `Box::new(0)`
243 |
1b1a35ee 244 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
245 found type `{integer}`
246 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
247
248error[E0308]: mismatched types
249 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
250 |
251LL | fn baw() -> Box<dyn Trait> {
1b1a35ee 252 | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
dfeec247
XL
253...
254LL | 42
255 | ^^
256 | |
1b1a35ee 257 | expected struct `Box`, found integer
dfeec247
XL
258 | help: store this in the heap by calling `Box::new`: `Box::new(42)`
259 |
1b1a35ee 260 = note: expected struct `Box<(dyn Trait + 'static)>`
dfeec247
XL
261 found type `{integer}`
262 = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
263
264error[E0746]: return type cannot have an unboxed trait object
265 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13
266 |
267LL | fn bat() -> dyn Trait {
268 | ^^^^^^^^^ doesn't have a size known at compile-time
269 |
270 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
f9f354fc 271help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
dfeec247
XL
272 |
273LL | fn bat() -> impl Trait {
274 | ^^^^^^^^^^
275
276error[E0746]: return type cannot have an unboxed trait object
277 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
278 |
279LL | fn bay() -> dyn Trait {
280 | ^^^^^^^^^ doesn't have a size known at compile-time
281 |
282 = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
f9f354fc 283help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
dfeec247
XL
284 |
285LL | fn bay() -> impl Trait {
286 | ^^^^^^^^^^
287
f9f354fc 288error: aborting due to 20 previous errors
dfeec247
XL
289
290Some errors have detailed explanations: E0277, E0308, E0746.
291For more information about an error, try `rustc --explain E0277`.