Skip to content

Parser confuses double-borrowed &&type/&&expr with ANDAND token. #7837

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
bblum opened this issue Jul 16, 2013 · 8 comments
Closed

Parser confuses double-borrowed &&type/&&expr with ANDAND token. #7837

bblum opened this issue Jul 16, 2013 · 8 comments
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST

Comments

@bblum
Copy link
Contributor

bblum commented Jul 16, 2013

These two programs compile only if you put a space between the two ampersands:

fn main() {
    let _x: &&() = fail!();
}
fn main() {
    let _x = &&();
}
@bblum
Copy link
Contributor Author

bblum commented Jul 16, 2013

here's another good one. this parses:

fn main() {
    let _ = true &&& () as *() as bool;
}

this doesn't:

fn main() {
    let _ = true &&&& () as *&() as bool;
}

@nikomatsakis
Copy link
Contributor

It should be straightforward enough to treat && in the type grammar or in unary operator position as two ampersands, though the use in a unary operator seems more theoretical than actual.

@sfackler
Copy link
Member

I've had it come up in a practical context trying to cast a string literal to a trait object:

trait Foo {}

impl<'self> Foo for &'self str {}

...
let _ = & &"foo" as &Foo;

@huonw
Copy link
Member

huonw commented Aug 18, 2013

I've also had it come up with hash maps and strings: .find_equiv(& &"foo")

@emberian
Copy link
Member

emberian commented Apr 7, 2014

This is really annoying.

@thestinger
Copy link
Contributor

The only mentioned use case is for string literals, and #10105 would get rid of that problem.

@nikomatsakis
Copy link
Contributor

On Mon, Apr 07, 2014 at 11:07:23AM -0700, Corey Richardson wrote:

This is really annoying.

Yes, it is.

@gereeter
Copy link
Contributor

I believe this is fixed by #13576 and should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

7 participants