-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Clippy interprets Bytes
type incorrectly as interior mutable which triggers errors on several lints
#5812
Comments
The problem here is, that Clippy detects the From the lint documentation:
I think this applies here. But I'm not sure, since I'm not familiar with the Tokio code base and what the intention behind this struct is. |
For Regarding |
I was thinking about implementing a |
Wouldn't it make more sense to simply make this lint use |
It looks like the lints already do since #11678. This issue is effectively complete. |
... some are still left, related to rust-lang/rust-clippy#5812
I tried this code:
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dec0c4a3d84023fdc3e8b27c6ed90c88
I expected to see this happen: Everything compiles fine and clippy checks succeed
Instead, this happened: Clippy emits a bunch of errors which abort compilation. For this particular piece of code it reports
However in other contexts - e.g. when I use
Bytes
as a key type in a map - I also get themutable_key_type
andborrow_interior_mutable_const
errors.I guess clippy doesn't understand the layout of
Bytes
, which uses interior raw pointers and a vtable: https://github.com/tokio-rs/bytes/blob/6fdb7391ce83dc71ccaeda6a54211ce723e5d9a5/src/bytes.rs#L71-L77While it is true that some data could be modified even from an immutable reference - e.g. due to a refcount change - the changes have no impact on the actual payload of the
Bytes
type - it always is an immutable byte array. Therefore I think the lints are wrongly applied here.I'm however not sure if this is something that would need to be fixed in clippy or could be fixed in
Bytes
Meta
cargo clippy -V
: e.g. 0.0.212 (2020-07-15 7e11379)rustc -Vv
:The text was updated successfully, but these errors were encountered: