You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #111056 - JohnBobbo96:fix_box_suggestions, r=compiler-errors
Fix some suggestions where a `Box<T>` is expected.
This fixes#111011, and also adds a suggestion for boxing a unit type when a `Box<T>` was expected and an empty block was found.
Copy file name to clipboardExpand all lines: compiler/rustc_hir_typeck/messages.ftl
+4
Original file line number
Diff line number
Diff line change
@@ -75,3 +75,7 @@ hir_typeck_union_pat_dotdot = `..` cannot be used in union patterns
75
75
76
76
hir_typeck_arg_mismatch_indeterminate = argument type mismatch was detected, but rustc had trouble determining where
77
77
.note = we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new
78
+
79
+
hir_typeck_suggest_boxing_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
80
+
81
+
hir_typeck_suggest_boxing_when_appropriate = store this in the heap by calling `Box::new`
| ^^ expected `Box<_>`, found `async` closure body
6
+
|
7
+
= note: expected struct `Box<_>`
8
+
found `async` closure body `[async closure body@$DIR/issue-111011.rs:10:23: 10:25]`
9
+
= 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
10
+
11
+
error[E0308]: mismatched types
12
+
--> $DIR/issue-111011.rs:11:9
13
+
|
14
+
LL | bar(async move || {});
15
+
| --- ^^^^^^^^^^^^^^^^ expected `Box<dyn FnOnce() -> _>`, found closure
found closure `[closure@$DIR/issue-111011.rs:11:9: 11:22]`
21
+
= 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
22
+
note: function defined here
23
+
--> $DIR/issue-111011.rs:7:4
24
+
|
25
+
LL | fn bar<X>(x: Box<dyn FnOnce() -> X>) {}
26
+
| ^^^ -------------------------
27
+
help: store this in the heap by calling `Box::new`
28
+
|
29
+
LL | bar(Box::new(async move || {}));
30
+
| +++++++++ +
31
+
32
+
error: aborting due to 2 previous errors
33
+
34
+
For more information about this error, try `rustc --explain E0308`.
= 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
10
+
help: store this in the heap by calling `Box::new`
11
+
|
12
+
LL - foo({});
13
+
LL + foo(Box::new(()));
14
+
|
15
+
16
+
error[E0308]: mismatched types
17
+
--> $DIR/suggest-boxed-empty-block.rs:11:12
18
+
|
19
+
LL | bar(|| {});
20
+
| ^^ expected `Box<_>`, found `()`
21
+
|
22
+
= note: expected struct `Box<_>`
23
+
found unit type `()`
24
+
= 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
25
+
help: store this in the heap by calling `Box::new`
26
+
|
27
+
LL - bar(|| {});
28
+
LL + bar(|| Box::new(()));
29
+
|
30
+
31
+
error: aborting due to 2 previous errors
32
+
33
+
For more information about this error, try `rustc --explain E0308`.
0 commit comments