Skip to content

box syntax does not allow an expression? #16777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FranklinChen opened this issue Aug 27, 2014 · 5 comments
Closed

box syntax does not allow an expression? #16777

FranklinChen opened this issue Aug 27, 2014 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@FranklinChen
Copy link
Contributor

    let foo = box (1i+2);
<anon>:3:25: 3:26 error: unexpected token: `;`
<anon>:3     let foo = box (1i+2);
@tomjakubowski
Copy link
Contributor

I expect it's trying to parse (1i+2) as an identifier since the box operator can take an optional "argument" in parentheses defaulting to std::owned::HEAP. This should compile:

fn main() {
    use std::owned::HEAP;
    let foo = box(HEAP) (1i + 2);
}

@FranklinChen
Copy link
Contributor Author

Ah, yes, that makes sense now. But I suggest something be done about the syntax because people will get quite confused when just using the default.

@huonw
Copy link
Member

huonw commented Aug 27, 2014

identifier

Actually an arbitrary 'allocator' expression. Currently we only support two builtin ones, but we will likely have some form of generalisation in the future. In any case, you can choose the default via box() (...) too (i.e. omitting the expression is the same as the explicit HEAP).

I do think we can improve the error messages here.

@ftxqxd
Copy link
Contributor

ftxqxd commented Aug 29, 2014

Is this a dupe of #15386?

I do agree that the syntax is awful and probably should be changed, but that’s probably for another issue.

@alexcrichton
Copy link
Member

Yes, I believe this is a dupe of #15386, which also has to do with diagnostics. Thanks @P1start!

matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
fix: Don't invalid body query results when generating desugared names

The hack remains until we get hygiene, but with this the generated names are stable across bodies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

5 participants