-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Remove let_chains unstable feature #143214
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
Merged
+1,053
−1,194
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// rustfmt-edition: 2024 | ||
|
||
fn main() { | ||
if let x = x && x {} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// rustfmt-edition: 2024 | ||
|
||
fn main() { | ||
if let x = x | ||
&& x | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// See drop-order-comparisons.rs | ||
|
||
//@ edition: 2024 | ||
//@ run-pass | ||
|
||
#![feature(if_let_guard)] | ||
|
||
fn t_if_let_chains_then() { | ||
let e = Events::new(); | ||
_ = if e.ok(1).is_ok() | ||
&& let true = e.ok(9).is_ok() | ||
&& let Ok(_v) = e.ok(8) | ||
&& let Ok(_) = e.ok(7) | ||
&& let Ok(_) = e.ok(6).as_ref() | ||
&& e.ok(2).is_ok() | ||
&& let Ok(_v) = e.ok(5) | ||
&& let Ok(_) = e.ok(4).as_ref() { | ||
e.mark(3); | ||
}; | ||
e.assert(9); | ||
} | ||
|
||
fn t_guard_if_let_chains_then() { | ||
let e = Events::new(); | ||
_ = match () { | ||
() if e.ok(1).is_ok() | ||
&& let true = e.ok(9).is_ok() | ||
&& let Ok(_v) = e.ok(8) | ||
&& let Ok(_) = e.ok(7) | ||
&& let Ok(_) = e.ok(6).as_ref() | ||
&& e.ok(2).is_ok() | ||
&& let Ok(_v) = e.ok(5) | ||
&& let Ok(_) = e.ok(4).as_ref() => { | ||
e.mark(3); | ||
} | ||
_ => {} | ||
}; | ||
e.assert(9); | ||
} | ||
|
||
fn t_if_let_chains_then_else() { | ||
let e = Events::new(); | ||
_ = if e.ok(1).is_ok() | ||
&& let true = e.ok(8).is_ok() | ||
&& let Ok(_v) = e.ok(7) | ||
&& let Ok(_) = e.ok(6) | ||
&& let Ok(_) = e.ok(5).as_ref() | ||
&& e.ok(2).is_ok() | ||
&& let Ok(_v) = e.ok(4) | ||
&& let Ok(_) = e.err(3) {} else { | ||
e.mark(9); | ||
}; | ||
e.assert(9); | ||
} | ||
|
||
fn t_guard_if_let_chains_then_else() { | ||
let e = Events::new(); | ||
_ = match () { | ||
() if e.ok(1).is_ok() | ||
&& let true = e.ok(8).is_ok() | ||
&& let Ok(_v) = e.ok(7) | ||
&& let Ok(_) = e.ok(6) | ||
&& let Ok(_) = e.ok(5).as_ref() | ||
&& e.ok(2).is_ok() | ||
&& let Ok(_v) = e.ok(4) | ||
&& let Ok(_) = e.err(3) => {} | ||
_ => { | ||
e.mark(9); | ||
} | ||
}; | ||
e.assert(9); | ||
} | ||
|
||
fn main() { | ||
t_if_let_chains_then(); | ||
t_guard_if_let_chains_then(); | ||
t_if_let_chains_then_else(); | ||
t_guard_if_let_chains_then_else(); | ||
} | ||
|
||
// # Test scaffolding | ||
|
||
use core::cell::RefCell; | ||
use std::collections::HashSet; | ||
|
||
/// A buffer to track the order of events. | ||
/// | ||
/// First, numbered events are logged into this buffer. | ||
/// | ||
/// Then, `assert` is called to verify that the correct number of | ||
/// events were logged, and that they were logged in the expected | ||
/// order. | ||
struct Events(RefCell<Option<Vec<u64>>>); | ||
|
||
impl Events { | ||
const fn new() -> Self { | ||
Self(RefCell::new(Some(Vec::new()))) | ||
} | ||
#[track_caller] | ||
fn assert(&self, max: u64) { | ||
let buf = &self.0; | ||
let v1 = buf.borrow().as_ref().unwrap().clone(); | ||
let mut v2 = buf.borrow().as_ref().unwrap().clone(); | ||
*buf.borrow_mut() = None; | ||
v2.sort(); | ||
let uniq_len = v2.iter().collect::<HashSet<_>>().len(); | ||
// Check that the sequence is sorted. | ||
assert_eq!(v1, v2); | ||
// Check that there are no duplicates. | ||
assert_eq!(v2.len(), uniq_len); | ||
// Check that the length is the expected one. | ||
assert_eq!(max, uniq_len as u64); | ||
// Check that the last marker is the expected one. | ||
assert_eq!(v2.last().unwrap(), &max); | ||
} | ||
/// Return an `Ok` value that logs its drop. | ||
fn ok(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> { | ||
Ok(LogDrop(self, m)) | ||
} | ||
/// Return an `Err` value that logs its drop. | ||
fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> { | ||
Err(LogDrop(self, m)) | ||
} | ||
/// Log an event. | ||
fn mark(&self, m: u64) { | ||
self.0.borrow_mut().as_mut().unwrap().push(m); | ||
} | ||
} | ||
|
||
impl Drop for Events { | ||
fn drop(&mut self) { | ||
if self.0.borrow().is_some() { | ||
panic!("failed to call `Events::assert()`"); | ||
} | ||
} | ||
} | ||
|
||
/// A type that logs its drop events. | ||
struct LogDrop<'b>(&'b Events, u64); | ||
|
||
impl<'b> Drop for LogDrop<'b> { | ||
fn drop(&mut self) { | ||
self.0.mark(self.1); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.