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

Fix parsing for casting an empty return expression #39303

Closed
wants to merge 1 commit into from

Conversation

cramertj
Copy link
Member

Partial fix for #28784.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@petrochenkov
Copy link
Contributor

petrochenkov commented Jan 25, 2017

Hm, I think you need to

  • add the same condition to NtIdent below
  • actually list all possible ident that can start an expression.

The list should look like this if I'm not missing anything:

  • all !is_any_keyword idents
  • is_path_segment_keyword idents
  • box, break, continue, false, for, if, loop, match, move, return, true, unsafe, while

@cramertj
Copy link
Member Author

cramertj commented Jan 25, 2017 via email

@petrochenkov
Copy link
Contributor

petrochenkov commented Jan 25, 2017

@cramertj
Making can_begin_expr precise is the general solution for the return sub-problem of #28784 (it affects couple of other places as well), so it's wanted.

@cramertj
Copy link
Member Author

@petrochenkov Great! I'll make that change then.

@cramertj cramertj closed this Jan 26, 2017
@cramertj cramertj deleted the cramertj/parse_return_as branch January 26, 2017 00:25
@cramertj
Copy link
Member Author

@petrochenkov Just started working on this, and I wanted to clarify the desired behavior for the NtIdent case. Currently, is_keyword, is_any_keyword, is_strict_keyword, etc. return false for Interpolated(NtIdent(..)) (or rather, they return false for all non-Idents). Should that be changed, too?

@petrochenkov
Copy link
Contributor

petrochenkov commented Jan 26, 2017

@cramertj
Actually, disregard my comment about NtIdent, it looks like macro machinery always unwraps it into Ident immediately, so it can never be encountered during parsing.

@cramertj
Copy link
Member Author

@petrochenkov
Does this look right to you?

fn ident_can_begin_expr(ident: ast::Ident) -> bool {
    let ident_token: Token = Ident(ident);

    !ident_token.is_any_keyword() ||
    ident_token.is_path_segment_keyword() ||
    [
        keywords::Box.name(),
        keywords::Break.name(),
        keywords::Continue.name(),
        keywords::False.name(),
        keywords::For.name(),
        keywords::If.name(),
        keywords::Loop.name(),
        keywords::Match.name(),
        keywords::Move.name(),
        keywords::Return.name(),
        keywords::True.name(),
        keywords::Unsafe.name(),
        keywords::While.name(),
    ].contains(&ident.name)
}

@cramertj
Copy link
Member Author

I don't think while and for can be expressions, can they? I'm guessing you added those because of the discussions around breaking with a value.

@petrochenkov
Copy link
Contributor

@cramertj

let a: () = while true { break };

They are expressions, they are just always result in () at the moment.

@cramertj
Copy link
Member Author

Huh. TIL.

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

Successfully merging this pull request may close these issues.

4 participants