Skip to content

Add error message for AltPattern in let statements#2009

Merged
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
powerboat9:let-msg
Apr 21, 2023
Merged

Add error message for AltPattern in let statements#2009
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
powerboat9:let-msg

Conversation

@powerboat9

Copy link
Copy Markdown
Collaborator

Changes the rust_sorry_at for AltPattern in let statements to a rust_error_at.

@powerboat9

Copy link
Copy Markdown
Collaborator Author

Waiting on #2008.

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread gcc/testsuite/rust/compile/let_alt.rs Outdated
@@ -0,0 +1,5 @@
fn main() {
let a | a = 12;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, let (a | a) = 12; is allowed. I'm assuming this is already handled by our GroupedPattern?

Comment thread gcc/rust/backend/rust-compile-pattern.h Outdated
rust_sorry_at (pattern.get_locus (),
"alternate pattern let statements not supported");
rust_error_at (pattern.get_locus (),
"top-level or-patterns are not allowed in %<let%> bindings");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to use an error message different from rustc that suits our compiler logic better :) this is not a critic or anything, just something to keep in mind when you think about new errors

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@powerboat9

powerboat9 commented Mar 22, 2023

Copy link
Copy Markdown
Collaborator Author

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ee42aeacde34e226a86b584ff1a1eb73

enum O {
    A(i32),
    B(i32)
}

fn main() {
  let (O::A(x) | O::B(x)) = O::B(1);
  println!("{}", x)
}

Terrific

@CohenArthur

Copy link
Copy Markdown
Member

@powerboat9 I'm in favor of merging this once the CI passes :)

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-pattern.cc
	(ASTLoweringPattern::translate): Add is_let_top_level parameter.
	(ASTLoweringPattern::visit): Handle is_let_top_level.
	* hir/rust-ast-lower-pattern.h
	(class ASTLoweringPattern): Add is_let_top_level.
	* hir/rust-ast-lower-stmt.cc
	(ASTLoweringStmt::visit): Set is_let_top_level.

gcc/testsuite/ChangeLog:

	* rust/compile/let_alt.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
@CohenArthur CohenArthur added this pull request to the merge queue Apr 21, 2023
Merged via the queue into Rust-GCC:master with commit 428a318 Apr 21, 2023
@powerboat9 powerboat9 deleted the let-msg branch April 28, 2023 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants