warning: calls to `push` immediately after creation
--> sharpview/src/main.rs:561:5
|
561 | / let mut grids = Vec::new();
562 | | // Replay feature only if replay enabled
563 | | #[cfg (feature="replay")]
564 | | #[allow(clippy::vec_init_then_push)] // Clippy doesn't understand the conditional compilation here.
... |
583 | | login_url: Some("http://login.osgrid.org".to_string()),
584 | | });
| |_______^ help: consider using the `vec![]` macro: `let mut grids = vec![..];`
|
= note: `#[warn(clippy::vec_init_then_push)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master
Here, Clippy is complaining about creating an empty vector, followed by a "push". But the first push is inside a conditionally compiled code block, so it might be turned off.
the problem is that I can't get Clippy to shut up about this by adding
That works. I try to use those "allow" instructions at statement scope, but maybe that doesn't work on lints that involve two separate statements.
I have misgivings about using #cfg in the middle of an expression. The Rust Reference says: "The cfgattribute conditionally includes the thing it is attached to based on a configuration predicate."
The "thing it is attached to" is rather vague. "Attribute" is defined as " Outer attributes, written without the bang after the hash, apply to the thing that follows the attribute." "Thing" does not seem to be defined anywhere.
So, #cfg, in the middle of an expression, might be considered using undefined behavior.
An attribute can be attached to an expression, statement, or item, and extends to cover just that syntax node. Anywhere an attribute is allowed it's fully unambiguous which is being decorated.
Rest assured that this is covered under the stability guarantee, even if it's undocumented at the moment.