rust-lang/rust-clippy

Catch transmuting Option<&T> to Option<&mut T>

Open

#372 geöffnet am 8. Okt. 2015

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Rust (1.391 Forks)batch import
C-enhancementE-mediumT-middlegood first issue

Repository-Metriken

Stars
 (10.406 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 22h) (113 gemergte PRs in 30 T)

Beschreibung

Rustc already has a lint (mutable_transmutes) that catches transmutes from &T to &mut T, which can cause undefined behaviour. However, it doesn't catch minor variations of this problem, like Option<&T> -> Option<&mut T>, which are presumably just as dangerous. I've seen this particular example in real code. It would be nice to have a lint that catches this case (and ideally, other instances of the same problem, although this could get quite complex in the fully general case).

Contributor Guide