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

Emit error when range pattern is empty #2795

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

braw-lee
Copy link
Contributor

I couldn't find a cleaner way to get values of upper and lower bound. Tell me if there is a better way to get those values.
@CohenArthur @P-E-P

Fixes Rust-GCC#2794

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Check values of lower and upper bounds and emit E0030 if needed.
	* checks/errors/rust-ast-validation.h:
	Add function declaration for validation of `AST::RangePattern`.
	* parse/rust-parse-impl.h (Parser::parse_literal_or_range_pattern):
	Added missed parameter.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2794.rs: New test.

Signed-off-by: Kushal Pal <[email protected]>
@P-E-P
Copy link
Member

P-E-P commented Jan 15, 2024

I'm unsure this should be done at this stage of the compiler, this surely is simpler after a bit of desugaring. Have you taken a look at rustc's way of doing this ? Is it doing it this early ?

@powerboat9
Copy link
Contributor

powerboat9 commented Jan 16, 2024

https://godbolt.org/z/sThP53WbG

pub fn main() {
    let _a = 1..=0;

    match 0 {
        1..=0 => {},
        _ => {}
    }

    let (1..=0, _b) = (1, 0);
}

It looks like the error only happens in match-like statements (the first line of the main function does not produce an error with rustc 1.49)

@braw-lee
Copy link
Contributor Author

I wonder if that is the intended behaviour. I will ask in rustc if this is what they want or a missed case.

@braw-lee
Copy link
Contributor Author

I'm unsure this should be done at this stage of the compiler, this surely is simpler after a bit of desugaring. Have you taken a look at rustc's way of doing this ? Is it doing it this early ?

you are right, rustc actually handles this error in typed-hir stage.

@CohenArthur
Copy link
Member

@braw-lee do you want some help on moving this to the typechecking phase?

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