Fix style check for Rust 1.88#1333
Conversation
|
However, Rust does not seem to allow inlining format args that are expressions. E.g. in By default, I find this a bit inconsistent. We may want to set @wks What do you think? |
|
I feel like this lint is silly. It doesn't really help with readability specially if the string gets too long/there is a mix of the arguments. I'm inclined to say that we just disable |
I don't quite like this lint either, but it does help in some cases. Like, our current code has this (this is the required format by trace!(
"Immix nursery object {} is being traced without moving",
object
);When the arg gets inlined, it becomes one line: trace!("Immix nursery object {object} is being traced without moving"); |
|
The In my opinion, inlining format arguments is not really more readable than not inlining them, and mixing inlined and un-inlined args makes it even less readable. As the author of rust-lang/rust-clippy#15151 said, the inlined syntax still doesn't support field access expressions, not to mention arithmetic expressions like |
|
Ah. The rust-analyzer reason is even more relevant. I didn't realize that use-case would break. |
I read through the issues you mentioned. There were actual issues with this lint, which was the reason why the lint got downgraded. I assume those issues were resolved at some point, and this lint was upgraded again as a default lint. Our general philosophy is to stick with the community's standards, and only deviate from it when we have good reasons. The following is one example where we disabled a lint, as we have Line 9 in efe7b41 However, for this case, I don't see clear reasons yet why we should disable this lint.
Inlining the args does not make things worse though.
Yes. But if we set |
|
Expressions as inlined format args seem to be explicitly not supported: https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html#alternative-solution---interpolation |
The community is different from the Rust developers. From rust-lang/rust-clippy#15151, I am seeing push-backs from the community.
In this case, the preference of style varies from people to people. For example, -error!("LOS Object {} is not marked", object);
+error!("LOS Object {object} is not marked");This is a simple case. It makes the expression terse. - trace!(
- "Reserved pages = {}, used pages: {}, collection reserve: {}, VM live pages: {}",
- total,
- used_pages,
- collection_reserve,
- vm_live_pages,
- );
+trace!("Reserved pages = {total}, used pages: {used_pages}, collection reserve: {collection_reserve}, VM live pages: {vm_live_pages}");This is a bit complex. We may argue that inlining the args makes the What could make things worse, is something like this: assert!(
size >= bin_range.unwrap().0 && bin < bin_range.unwrap().1,
"Assigning size={} to bin={} ({:?}) incorrect",
size,
bin,
bin_range.unwrap()
);This is kept as is because it contains a method call expression. But think if the message only has the two args at one time, which is So I would prefer allowing us to have both styles, as long as they are both reasonably readable. And we can wait for a few weeks to see how the Rust community react to this change. In other words, Let The Bullets Fly for a while before we make the decision. |
|
Clippy developers changed |
|
This PR can be closed without merging, as we don't need to adapt the code base to the |
Mostly https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args. Rust allows inlining identifiers for format args, such as
println!("a = {a}"), clippy by default deney uninlined format args if they can be inlined (println!("a = {}", a)) is not allowed).