-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Place tail expression behind terminating scope #125293
base: master
Are you sure you want to change the base?
Place tail expression behind terminating scope #125293
Conversation
rustbot has assigned @petrochenkov. Use |
cc @traviscross for edition 2024 update cc @eholk for context who has worked on async iterator |
r? compiler |
This comment was marked as resolved.
This comment was marked as resolved.
21d1190
to
2f0ad0d
Compare
|
||
fn main() { | ||
let _ = f(); | ||
} |
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.
Many tests should be added. Such as
- code will still panic, but leave the mutex unpoisoned
fn f(m: &Mutex<i32>) -> i32 {
let _x = PanicOnDrop;
*m.lock().unwrap()
}
- mutable reference
fn main() {
let c = std::cell::RefCell::new(123);
if let Ok(mut b) = c.try_borrow_mut() {
*b = 321;
}
}
-
Explicit drop order
https://github.com/rust-lang/rfcs/pull/3606/files#r1548272644 -
injects a borrow to a temporary into an already existing local variable that borrows it on drop
fn why_would_you_do_this() -> bool {
let mut x = None;
// Make a temporary `RefCell` and put a `Ref` that borrows it in `x`.
x.replace(RefCell::new(123).borrow()).is_some()
}
- block could be a subexpression of a larger expression
let zero = { String::new().as_str() }.len();
Considering this is a breaking feature, more tests would be better.
17a40e2
to
75d038e
Compare
75d038e
to
66c2762
Compare
This PR implements #123739 so that we can do further experiments in nightly.
A little rewrite has been applied to
for await
lowering. It was previouslyunsafe { Pin::unchecked_new(into_async_iter(..)) }
. Under the edition 2024 rule, however,into_async_iter
gets dropped at the end of theunsafe
block. This presumably the first Edition 2024 migration rule goes by hoistinginto_async_iter(..)
intomatch
one level above, so it now looks like the following.