-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Allow try
-blocks in places where an open delim is expected
#70657
Conversation
src/librustc_lint/unused.rs
Outdated
@@ -371,7 +371,7 @@ trait UnusedDelimLint { | |||
fn is_expr_delims_necessary(inner: &ast::Expr, followed_by_block: bool) -> bool { | |||
followed_by_block | |||
&& match inner.kind { | |||
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true, | |||
ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::TryBlock(_) => true, |
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.
This feels like a parser bug to me. We have:
fn is_try_block(&self) -> bool {
self.token.is_keyword(kw::Try) &&
self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) &&
self.token.uninterpolated_span().rust_2018() &&
// Prevent `while try {} {}`, `if try {} {} else {}`, etc.
!self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
}
but we allow this for unsafe {}
, async {}
, etc.
This comment has been minimized.
This comment has been minimized.
Waited for a comment by @petrochenkov on this, as this changes the purpose of this PR. I changed the parser to allow try in scrutinee position/in places where open braces are expected. // This now compiles
match try {} {
Ok(()) | Err(()) => (),
} |
try
-blocks in places where an open delim is expected
Did you intend to include that submodule bump? |
I rarely do 😆 thank you for catching this |
4010c1d
to
f74e466
Compare
📌 Commit f74e466771ad79410b84b2034d45cc3cc1d84855 has been approved by |
@bors r+ |
📌 Commit 81a3cd7 has been approved by |
Allow `try`-blocks in places where an open delim is expected Closes rust-lang#70490 Closes rust-lang#56828 r? @Centril
Rollup of 8 pull requests Successful merges: - rust-lang#70657 (Allow `try`-blocks in places where an open delim is expected) - rust-lang#70947 (tighten CTFE safety net for accesses to globals) - rust-lang#70949 (simplify `vec!` macro) - rust-lang#71002 (fix target & runtool args order) - rust-lang#71082 (ptr: introduce len() method on raw slices) - rust-lang#71128 (Remove unused single_step flag) - rust-lang#71133 (Tighten time complexity on the doc of sort_by_key) - rust-lang#71135 (Update books) Failed merges: r? @ghost
Closes #70490
Closes #56828
r? @Centril