-
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
Disallow cast with trailing braced macro in let-else #125049
Conversation
rustbot has assigned @compiler-errors. Use |
@@ -3,8 +3,7 @@ | |||
#![feature(explicit_tail_calls)] | |||
|
|||
fn a() { | |||
let foo = { | |||
//~^ WARN irrefutable `let...else` pattern |
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.
Did other errors in this file kill these suggestions?
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.
I removed them intentionally in f493143 because 48% of tests/ui/parser/bad-let-else-statement.stderr was these warnings unrelated to the thing that this file is trying to test (the parser), which seemed excessive.
The "irrefutable let...else pattern" warning is already tested independently by tests/ui/let-else/let-else-irrefutable.rs.
I consider this an extension to #119062. Let me look at this once again after dinner, but I'll probably approve it w/o another crater or lang FCP. |
Cast(_, ty) => { | ||
break type_trailing_brace(ty).then_some(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.
Only ast::TyKind::MacCall
could cause this to be trailed with }
(ast::TyKind::AnonStruct
and ast::TyKind::AnonStruct
can only be used in struct fields). So it will be more accurate to report the error using errors::WrapInParentheses::MacroArgs
in check_let_else_init_trailing_brace
.
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.
Good call. I have implemented this improvement.
@bors r+ |
Rollup of 5 pull requests Successful merges: - rust-lang#124896 (miri: rename intrinsic_fallback_checks_ub to intrinsic_fallback_is_spec) - rust-lang#125015 (Pattern types: Prohibit generic args on const params) - rust-lang#125049 (Disallow cast with trailing braced macro in let-else) - rust-lang#125259 (An async closure may implement `FnMut`/`Fn` if it has no self-borrows) - rust-lang#125296 (Fix `unexpected_cfgs` lint on std) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#125049 - dtolnay:castbrace, r=compiler-errors Disallow cast with trailing braced macro in let-else This fixes an edge case I noticed while porting rust-lang#118880 and rust-lang#119062 to syn. Previously, rustc incorrectly accepted code such as: ```rust let foo = &std::ptr::null as &'static dyn std::ops::Fn() -> *const primitive! { 8 } else { return; }; ``` even though a right curl brace `}` directly before `else` in a `let...else` statement is not supposed to be valid syntax.
bors sleepy @bors r- |
This fixes an edge case I noticed while porting #118880 and #119062 to syn.
Previously, rustc incorrectly accepted code such as:
even though a right curl brace
}
directly beforeelse
in alet...else
statement is not supposed to be valid syntax.