Skip to content
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

'as', '<' and '*' can cause a parsing error #32852

Closed
keeperofdakeys opened this issue Apr 9, 2016 · 4 comments
Closed

'as', '<' and '*' can cause a parsing error #32852

keeperofdakeys opened this issue Apr 9, 2016 · 4 comments

Comments

@keeperofdakeys
Copy link
Contributor

The following code snippet is causing an error that might be avoidable (I suspect a parsing error, but I don't know how the grammar is actually defined, so this is just a guess). The error is "bare raw pointers are no longer allowed".

fn main() { let a = &4u64; println!("{}", 43 as u64 < *a);

I suspect that the *a is being interpreted as the start of a type generic, when it's actually dereferencing a value. Adding brances '( ... )' fixes the issue, as well as reordering the statement into a '>'. The problem occurs on both stable and nightly.

@keeperofdakeys
Copy link
Contributor Author

Thinking about this a bit further, the 'bare raw pointers' error must be occurring very early in the parsing (lexer?) in order to trigger that early. The less-than doesn't even have a matching angle-bracket.

@petrochenkov
Copy link
Contributor

The parser expects a type after as, so it starts parsing u64 < *a as a type.
If we rename the identifiers and remove whitespaces things become more evident - we have Type<*T and < is interpreted as a start of type parameters and * is interpreted as a start of a pointer type which should be followed by const or mut, but is followed by T, therefore the error.

The specialized error message about bare raw pointers should probably be removed - it's a pre-1.0 feature and only gray-bearded elders remember about them.

@birkenfeld
Copy link
Contributor

birkenfeld commented May 9, 2016

Compiler now says

x.rs:1:55: 1:56 error: expected mut or const in raw pointer type (use`_mut T`or`_const T` as appropriate)
x.rs:1 fn main() { let a = &4u64; println!("{}", 43 as u64 < *a);

Otherwise, this is a duplicate of #22644 and #11962.

@Mark-Simulacrum
Copy link
Member

Closing in favor of #22644.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants