You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you have an incomplete match statement (i.e. not covering all pattern variants) and one or more of the arms has unsafe code inside of unsafe { .. } blocks, Rust Analyzer will incorrectly put warnings on each unsafe keyword saying the unsafe block is unnecessary.
This was quite confusing, as when I encountered this, although I was aware my match statement was incomplete and I was in the process of filling in the missing variants, I actually removed the unsafe blocks due to these warnings because I thought "oh, I must be inside an unsafe fn", only to find that once I filled in the missing variants, it wanted the unsafe blocks back.
sam0x17
changed the title
RA thinks unsafe is unnecessary on unsafe match arms when there are one or more missing match arms
RA thinks unsafe is unnecessary on unsafe match arms when the match is incomplete (missing arms)
Aug 25, 2023
rust-analyzer version:
0.3.1631-standalone
rustc version: rustc 1.72.0 (5680fa18f 2023-08-23)
When you have an incomplete match statement (i.e. not covering all pattern variants) and one or more of the arms has unsafe code inside of
unsafe { .. }
blocks, Rust Analyzer will incorrectly put warnings on eachunsafe
keyword saying theunsafe
block is unnecessary.This was quite confusing, as when I encountered this, although I was aware my match statement was incomplete and I was in the process of filling in the missing variants, I actually removed the
unsafe
blocks due to these warnings because I thought "oh, I must be inside an unsafe fn", only to find that once I filled in the missing variants, it wanted the unsafe blocks back.This toy example reproduces it:
Once you fill in the missing
MyEnum::Orange
variant, everything will compile and the warnings disappear.The text was updated successfully, but these errors were encountered: