Skip to content

Unhelpful errors for unintended use of box (...) ... syntax #14085

Closed
@huonw

Description

@huonw
fn main() {
    box (1 + 2) * 3;

    // box (1.0 + 2.0).sqrt()
}

with just the first:

boxerror.rs:2:17: 2:20 error: type `<generic integer #2>` cannot be dereferenced
boxerror.rs:2     box (1 + 2) * 3;
                              ^~~
boxerror.rs:2:5: 2:20 error: only the managed heap and exchange heap are currently supported
boxerror.rs:2     box (1 + 2) * 3;
                  ^~~~~~~~~~~~~~~

with the second uncommented it's a parse error:

boxerror.rs:4:20: 4:21 error: unexpected token: `.`
boxerror.rs:4     box (1.0 + 2.0).sqrt()
                                 ^

The (...) is interpreted as the allocator/placement part of the box expression, rather than just part of the value to be boxed. It would be nice to suggest something like "if you wish to use the default box write box () ...;".

(Also, "amusingly", the code as written above hits #14084)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions