-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[WIP] [let_chains, 4/N] Introduce hir::ExprKind::Let
#68577
Conversation
disallowed positions is checked in ast_validation in next commit
} | ||
|
||
/// Emits an error banning the `let` expression provided in the given location. | ||
fn ban_let_expr(&self, expr: &'a Expr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably a better idea to move this to feature gating under e.g. #![feature(let_expr)]
so that we can test ::Let
more than what let_chains
alone would allow. We could also move that, or the ast_validation logic, out of this PR and land it separately.
@@ -513,33 +513,6 @@ warning: the feature `let_chains` is incomplete and may cause the compiler to cr | |||
LL | #![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates in this test. | |||
| ^^^^^^^^^^ | |||
|
|||
error[E0658]: `match` is not allowed in a `const` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::Let
can result in switching on the discriminant, like or-patterns. Alone however, it is not control flow. That said, we should probably gate let p = s
here too?
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 6ed41a8 with merge 460f28a6daf1e5ebd90eb84972688220a0f03b6a... |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Some notes that seem important:
struct D(usize);
impl Drop for D {
fn drop(&mut self) {
dbg!(self.0);
}
}
fn main() {
if let Some(d) = Some(D(0)) {
D(1);
}
D(2);
let mut x = Some(D(3));
while let Some(d) = x.take() {
D(4);
}
D(5);
} should result in: [src/main.rs:5] self.0 = 1
[src/main.rs:5] self.0 = 0
[src/main.rs:5] self.0 = 2
[src/main.rs:5] self.0 = 4
[src/main.rs:5] self.0 = 3
[src/main.rs:5] self.0 = 5 That is: Note to self: Add a test for this!
match let Some(d) = Some(D(0)) {
// borrowck doesn't understand that `true` and the pattern matching conincide.
true => D(1),
_ => {} // make sure `d` is not available here.
}
D(2);
|
☀️ Try build successful - checks-azure |
Queued 460f28a6daf1e5ebd90eb84972688220a0f03b6a with parent 8a79d08, future comparison URL. |
@Centril any updates? |
Closing this for now. I'll need to think some more about how to make progress here. |
Introduce `hir::ExprKind::Let` - Take 2 Builds on rust-lang#68577 and depends on rust-lang#79328. cc rust-lang#53667
Introduces
hir::ExprKind::Let(&Pat<'_>, &Expr<'_>)
. That is, this introduceslet pat = expr
expressions.For now, this is very much WIP and probably depends on #67668 to remove the hacks in HAIR / region / generator_interior, but I thought it would be useful to have this open for discussion purposes and so that I can check perf.
cc #53667.
r? @matthewjasper cc @oli-obk