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

1.35 -> 1.36 regression: && incorrectly considered to be unable to start expressions. #74233

Closed
eddyb opened this issue Jul 11, 2020 · 2 comments · Fixed by #74650
Closed

1.35 -> 1.36 regression: && incorrectly considered to be unable to start expressions. #74233

eddyb opened this issue Jul 11, 2020 · 2 comments · Fixed by #74650
Assignees
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. relnotes Marks issues that should be documented in the release notes of the next release. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eddyb
Copy link
Member

eddyb commented Jul 11, 2020

This example compiles on 1.35 but not 1.36 or later:

pub fn foo() -> &'static &'static bool {
    {} // equivalent to {}; or ();
    &&false
}

(The example above was reduced from one involving match ... {...} && false, found by @digama0)

This regression was likely introduced by #60188, due to the definition of can_continue_expr_unambiguously:

/// This operator could be used to follow a block unambiguously.
///
/// This is used for error recovery at the moment, providing a suggestion to wrap blocks with
/// parentheses while having a high degree of confidence on the correctness of the suggestion.
pub fn can_continue_expr_unambiguously(&self) -> bool {
use AssocOp::*;
match self {
BitXor | // `{ 42 } ^ 3`
Assign | // `{ 42 } = { 42 }`
Divide | // `{ 42 } / 42`
Modulus | // `{ 42 } % 2`
ShiftRight | // `{ 42 } >> 2`
LessEqual | // `{ 42 } <= 3`
Greater | // `{ 42 } > 3`
GreaterEqual | // `{ 42 } >= 3`
AssignOp(_) | // `{ 42 } +=`
LAnd | // `{ 42 } &&foo`
As | // `{ 42 } as usize`
// Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect
// NotEqual | // `{ 42 } != { 42 } struct literals parser recovery.
Colon => true, // `{ 42 }: usize`
_ => false,
}
}

That function lists all of the operators that can't start an expression, but only continue it.
LAnd (&&) is incorrectly included, as &&expr is parsed the same as & &expr at the start of an expression.

cc @estebank

@eddyb eddyb added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jul 11, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 11, 2020
@eddyb
Copy link
Member Author

eddyb commented Jul 11, 2020

I've left some comments on #61500 (a partial fix for a regression that seems similar to this, but more specific), e.g.: #61500 (comment)

Looking again at this, I don't think this PR was necessary, it seems to have worked around the bug without fully fixing it.
As per #74233, can_continue_expr_unambiguously should've never returned true for LAnd, preventing the regression.

@jonas-schievink jonas-schievink added A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 11, 2020
@spastorino
Copy link
Member

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@spastorino spastorino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. P-high High priority labels Jul 15, 2020
@estebank estebank self-assigned this Jul 22, 2020
tmandry added a commit to tmandry/rust that referenced this issue Aug 14, 2020
@bors bors closed this as completed in 9b5a974 Aug 14, 2020
@estebank estebank added the relnotes Marks issues that should be documented in the release notes of the next release. label Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. relnotes Marks issues that should be documented in the release notes of the next release. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants