Closed
Description
This code
trait Trait {}
fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) {
ptr as _
}
produces the following error
error: incorrect braces around trait bounds
--> src/lib.rs:3:49
|
3 | fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) {
| ^ ^
|
help: remove the parentheses
|
3 - fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) {
3 + fn assert_send(ptr: *mut dyn Trait) -> *mut dyn Trait + Send {
|
error: could not compile `playground` (lib) due to previous error
First of all, "braces" is the wrong word here I think, AFAIK "braces" means {...}
, but here we have parentheses.
More importantly though, if I apply the suggestion, the code still does not build! Instead it now shows a different error:
error: ambiguous `+` in a type
--> src/lib.rs:3:45
|
3 | fn assert_send(ptr: *mut dyn Trait) -> *mut dyn Trait + Send {
| ^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(dyn Trait + Send)`
The correct syntax is to write *mut (dyn Trait + Send)
.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.