Comments (13)
What does that even mean? A mutable pointer to a mutable pointer?
It'd be easy to match but what should clippy suggest (apart from a visit to a good psychiatrist)?
from rust-clippy.
&mut T
I guess? It's really hard to tell what the person actually wanted, you just know it probably wasn't that.
from rust-clippy.
Ok, so we assume that &mut &mut T
is a copy'n'paste mistake, and the dev would want any of &mut &T
, & &mut T
or &mut T
.
&mut is matched by either Ty{node: TyPtr(MutTy{ty: ref pty, mutbl:MutMutable}), ..}
or Ty{node: TyRPtr(_, MutTy{ty: ref pty, mutbl:MutMutable}), ..}
, where the ref pty
is the reference. So if we have a fn match_mut(&Ty) -> Option(&Ty) that will do the above match and return
ptyor
None, we can check
match_mut(ty).and_then(|ty| match_mut(ty)).is_some()(we need the closure to auto-deref the
ptr::P`) to find the pattern.
from rust-clippy.
I have a half-baked version in my tree, but it doesn't catch all cases. Simply using check_ty
doesn't cut it, and there are all kinds of expressions where we need to unpack Ty
s.
from rust-clippy.
Uh, just unwrap the sty
with ty_ptr
of the ty::Ty
coming out of expr_ty
? in check_expr
?
from rust-clippy.
I already did that, but it failed to catch
const this_is_deranged : &mut &mut u32 = &mut &mut 1u32;
from rust-clippy.
Why? The RHS is an expr which should be a ty_ptr(ty_ptr(ty_int))
or something
from rust-clippy.
In fact, it's an ExprAddrOf(MutMutable, ..ExprAddrOf(MutMutable, _)). And I found it.
from rust-clippy.
Ah, you misunderstand me.
While we do want to catch types which are &mut &mut Foo
or expressions which are &mut &mut foo
; that's not all we want to do. Those are pure AST checks.
We also want to catch cases where an &mut
ptr is being needlessly re-&mut
-ed. This is done by using expr_ty
on an expression and checking its actual type. (The type info isn't part of the AST, it's part of the tcx)
To make this robust, I would suggest, in check_expr
:
- If it's
&mut _
, runexpr_ty
on the inner thingy and make sure it's not a mutablety_ptr
. If it is, then lint that reborrowing might be preferable. - If it's
&mut &mut
, do as we do now - If it's neither, run
expr_ty
on the whole expr and check that it's not a double mutable ptr (and warn if so)
from rust-clippy.
(So thanks for the lint ❤️, but there's more work to be done to close this issue 😄 )
from rust-clippy.
Ah, thank you for the clarification. I will extend the lint as you suggested.
from rust-clippy.
Thanks!
from rust-clippy.
And...done (At least I hope so).
from rust-clippy.
Related Issues (20)
- `into_iter_without_iter` warns when code blocks are in particular order
- `manual_unwrap_or_default` invalid suggestion on macro expanded code HOT 1
- `clippy::explicit_auto_deref` incorrectly removes deref when ampersand is present
- or_fun_call misses nested calls
- Warn if a `[patch.*]` section is used on a dependency of a library
- consider making clippy_lints into a dylib for faster recompilation.
- `Option::and_then(|v| ...(&v).then_some(v))` to `Option::filter(|v| ...(v))` HOT 1
- ICE in clippy::borrow_interior_mutable_const HOT 1
- arc_with_non_send_sync warns on the caller of a function instead of the function itself
- Typealias shouldn't be expanded when suggesting casts/transmutes/type annotations HOT 1
- Add new style lint: Warn if first paragraph in docstring is too long. HOT 1
- ref_binding_to_reference false negative in expressions misclassified as postfix
- `cast_lossless` does not effect on some cases HOT 1
- `manual_unwrap_or_default` triggered for tuple unpacked with `_` HOT 1
- `unnecessary_struct_initialization` triggers in proc-macros
- clippy::needless_update with Default..default() is not usable HOT 1
- Clippy removing parenthesis from clap derive label makes the program fail to compile HOT 2
- Slightly underindented continuation should be accepted
- Confusing message (empty attribute) in double_must_use HOT 1
- Lint for highlighting possibly invalid coercion `Box<dyn Any>` -> `&dyn Any` with implicit deref
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-clippy.