djc / bb8

Full-featured async (tokio-based) postgres connection pool (like r2d2)
MIT License
753 stars 110 forks source link

Considerable number of pedantic lints reported by clippy #131

Open nyurik opened 2 years ago

nyurik commented 2 years ago

Hi, I ran cargo clippy -- -W clippy::pedantic --no-deps and it seems there are quiet a few lints being reported, some possibly more important than others. Are you interesting in a fix for any of those, or do you think they are ok to ignore? Thx!

full output ``` warning: redundant else block --> bb8/src/inner.rs:219:28 | 219 | } else { | ____________________________^ 220 | | delay = max(Duration::from_millis(200), delay); 221 | | delay = min(self.inner.statics.connection_timeout / 2, delay * 2); 222 | | sleep(delay).await; 223 | | } | |_____________________^ | = note: `-W clippy::redundant-else` implied by `-W clippy::pedantic` = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:44:5 | 44 | pub fn builder() -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn builder() -> Builder` | = note: `-W clippy::must-use-candidate` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:49:5 | 49 | pub fn state(&self) -> State { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn state(&self) -> State` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: docs for function returning `Result` missing `# Errors` section --> bb8/src/api.rs:54:5 | 54 | / pub async fn get(&self) -> Result, RunError> { 55 | | self.inner.get().await 56 | | } | |_____^ | = note: `-W clippy::missing-errors-doc` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc warning: docs for function returning `Result` missing `# Errors` section --> bb8/src/api.rs:62:5 | 62 | / pub async fn get_owned(&self) -> Result, RunError> { 63 | | self.inner.get_owned().await 64 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc warning: docs for function returning `Result` missing `# Errors` section --> bb8/src/api.rs:72:5 | 72 | / pub async fn dedicated_connection(&self) -> Result { 73 | | self.inner.connect().await 74 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:122:5 | 122 | pub fn new() -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn new() -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: calling `api::Builder::default()` is more clear than this expression --> bb8/src/api.rs:123:9 | 123 | Default::default() | ^^^^^^^^^^^^^^^^^^ help: try: `api::Builder::default()` | = note: `-W clippy::default-trait-access` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:129:5 | 129 | pub fn max_size(mut self, max_size: u32) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn max_size(mut self, max_size: u32) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: docs for function which may panic missing `# Panics` section --> bb8/src/api.rs:129:5 | 129 | / pub fn max_size(mut self, max_size: u32) -> Builder { 130 | | assert!(max_size > 0, "max_size must be greater than zero!"); 131 | | self.max_size = max_size; 132 | | self 133 | | } | |_____^ | = note: `-W clippy::missing-panics-doc` implied by `-W clippy::pedantic` note: first possible panic found here --> bb8/src/api.rs:130:9 | 130 | assert!(max_size > 0, "max_size must be greater than zero!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:129:5 | 129 | / pub fn max_size(mut self, max_size: u32) -> Builder { 130 | | assert!(max_size > 0, "max_size must be greater than zero!"); 131 | | self.max_size = max_size; 132 | | self 133 | | } | |_____^ | = note: `-W clippy::return-self-not-must-use` implied by `-W clippy::pedantic` = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:141:5 | 141 | pub fn min_idle(mut self, min_idle: Option) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn min_idle(mut self, min_idle: Option) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:141:5 | 141 | / pub fn min_idle(mut self, min_idle: Option) -> Builder { 142 | | self.min_idle = min_idle; 143 | | self 144 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:150:5 | 150 | pub fn test_on_check_out(mut self, test_on_check_out: bool) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn test_on_check_out(mut self, test_on_check_out: bool) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:150:5 | 150 | / pub fn test_on_check_out(mut self, test_on_check_out: bool) -> Builder { 151 | | self.test_on_check_out = test_on_check_out; 152 | | self 153 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:164:5 | 164 | pub fn max_lifetime(mut self, max_lifetime: Option) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn max_lifetime(mut self, max_lifetime: Option) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: docs for function which may panic missing `# Panics` section --> bb8/src/api.rs:164:5 | 164 | / pub fn max_lifetime(mut self, max_lifetime: Option) -> Builder { 165 | | assert_ne!( 166 | | max_lifetime, 167 | | Some(Duration::from_secs(0)), ... | 171 | | self 172 | | } | |_____^ | note: first possible panic found here --> bb8/src/api.rs:165:9 | 165 | / assert_ne!( 166 | | max_lifetime, 167 | | Some(Duration::from_secs(0)), 168 | | "max_lifetime must be greater than zero!" 169 | | ); | |_________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:164:5 | 164 | / pub fn max_lifetime(mut self, max_lifetime: Option) -> Builder { 165 | | assert_ne!( 166 | | max_lifetime, 167 | | Some(Duration::from_secs(0)), ... | 171 | | self 172 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:180:5 | 180 | pub fn idle_timeout(mut self, idle_timeout: Option) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn idle_timeout(mut self, idle_timeout: Option) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: docs for function which may panic missing `# Panics` section --> bb8/src/api.rs:180:5 | 180 | / pub fn idle_timeout(mut self, idle_timeout: Option) -> Builder { 181 | | assert_ne!( 182 | | idle_timeout, 183 | | Some(Duration::from_secs(0)), ... | 187 | | self 188 | | } | |_____^ | note: first possible panic found here --> bb8/src/api.rs:181:9 | 181 | / assert_ne!( 182 | | idle_timeout, 183 | | Some(Duration::from_secs(0)), 184 | | "idle_timeout must be greater than zero!" 185 | | ); | |_________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:180:5 | 180 | / pub fn idle_timeout(mut self, idle_timeout: Option) -> Builder { 181 | | assert_ne!( 182 | | idle_timeout, 183 | | Some(Duration::from_secs(0)), ... | 187 | | self 188 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:196:5 | 196 | pub fn connection_timeout(mut self, connection_timeout: Duration) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn connection_timeout(mut self, connection_timeout: Duration) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: docs for function which may panic missing `# Panics` section --> bb8/src/api.rs:196:5 | 196 | / pub fn connection_timeout(mut self, connection_timeout: Duration) -> Builder { 197 | | assert!( 198 | | connection_timeout > Duration::from_secs(0), 199 | | "connection_timeout must be non-zero" ... | 202 | | self 203 | | } | |_____^ | note: first possible panic found here --> bb8/src/api.rs:197:9 | 197 | / assert!( 198 | | connection_timeout > Duration::from_secs(0), 199 | | "connection_timeout must be non-zero" 200 | | ); | |_________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:196:5 | 196 | / pub fn connection_timeout(mut self, connection_timeout: Duration) -> Builder { 197 | | assert!( 198 | | connection_timeout > Duration::from_secs(0), 199 | | "connection_timeout must be non-zero" ... | 202 | | self 203 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:209:5 | 209 | pub fn error_sink(mut self, error_sink: Box>) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn error_sink(mut self, error_sink: Box>) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:209:5 | 209 | / pub fn error_sink(mut self, error_sink: Box>) -> Builder { 210 | | self.error_sink = error_sink; 211 | | self 212 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:216:5 | 216 | pub fn reaper_rate(mut self, reaper_rate: Duration) -> Builder { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn reaper_rate(mut self, reaper_rate: Duration) -> Builder` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:216:5 | 216 | / pub fn reaper_rate(mut self, reaper_rate: Duration) -> Builder { 217 | | self.reaper_rate = reaper_rate; 218 | | self 219 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: this method could have a `#[must_use]` attribute --> bb8/src/api.rs:222:5 | 222 | / pub fn connection_customizer( 223 | | mut self, 224 | | connection_customizer: Box>, 225 | | ) -> Builder { | |___________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate help: add the attribute | 222 ~ #[must_use] pub fn connection_customizer( 223 + mut self, 224 + connection_customizer: Box>, 225 ~ ) -> Builder { | warning: missing `#[must_use]` attribute on a method returning `Self` --> bb8/src/api.rs:222:5 | 222 | / pub fn connection_customizer( 223 | | mut self, 224 | | connection_customizer: Box>, 225 | | ) -> Builder { 226 | | self.connection_customizer = Some(connection_customizer); 227 | | self 228 | | } | |_____^ | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: docs for function returning `Result` missing `# Errors` section --> bb8/src/api.rs:247:5 | 247 | / pub async fn build(self, manager: M) -> Result, M::Error> { 248 | | let pool = self.build_inner(manager); 249 | | pool.inner.start_connections().await.map(|()| pool) 250 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc warning: non-binding `let` on a type that implements `Drop` --> bb8/src/api.rs:315:9 | 315 | let _ = self.conn.take(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-W clippy::let-underscore-drop` implied by `-W clippy::pedantic` = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_drop warning: consider adding a `;` to the last statement for consistent formatting --> bb8/src/api.rs:366:9 | 366 | self.pool.as_ref().put_back(self.conn.take()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.pool.as_ref().put_back(self.conn.take());` | = note: `-W clippy::semicolon-if-nothing-returned` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned warning: consider adding a `;` to the last statement for consistent formatting --> bb8/src/inner.rs:46:13 | 46 | result? | ^^^^^^^ help: add a `;` here: `result?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned warning: unnecessary boolean `not` operation --> bb8/src/inner.rs:157:13 | 157 | / if !self.inner.manager.has_broken(&mut conn.conn) { 158 | | Some(conn) 159 | | } else { 160 | | None 161 | | } | |_____________^ | = note: `-W clippy::if-not-else` implied by `-W clippy::pedantic` = help: remove the `!` and swap the blocks of the `if`/`else` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> bb8/src/inner.rs:165:9 | 165 | / match conn { 166 | | Some(conn) => locked.put(conn, None, self.inner.clone()), 167 | | None => { 168 | | let approvals = locked.dropped(1, &self.inner.statics); 169 | | self.spawn_replenishing_approvals(approvals); 170 | | } 171 | | } | |_________^ | = note: `-W clippy::single-match-else` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try this | 165 ~ if let Some(conn) = conn { locked.put(conn, None, self.inner.clone()) } else { 166 + let approvals = locked.dropped(1, &self.inner.statics); 167 + self.spawn_replenishing_approvals(approvals); 168 + } | warning: consider adding a `;` to the last statement for consistent formatting --> bb8/src/inner.rs:265:17 | 265 | PoolInner { inner }.reap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `PoolInner { inner }.reap();` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned warning: this argument is passed by value, but not consumed in the function body --> bb8/src/internals.rs:63:19 | 63 | approval: Option, | ^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option` | = note: `-W clippy::needless-pass-by-value` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> bb8/src/internals.rs:97:25 | 97 | let available = self.conns.len() as u32 + self.pending_conns; | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-W clippy::cast-possible-truncation` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> bb8/src/internals.rs:145:22 | 145 | self.dropped((before - self.conns.len()) as u32, config) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> bb8/src/internals.rs:151:31 | 151 | idle_connections: self.conns.len() as u32, | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation warning: you seem to be trying to use `match` for an equality check. Consider using `if` --> bb8/src/internals.rs:206:9 | 206 | / match self.num { 207 | | 0 => None, 208 | | _ => { 209 | | self.num -= 1; 210 | | Some(Approval { _priv: () }) 211 | | } 212 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try this | 206 ~ if self.num == 0 { None } else { 207 + self.num -= 1; 208 + Some(Approval { _priv: () }) 209 + } | warning: `bb8` (lib) generated 42 warnings warning: docs for function returning `Result` missing `# Errors` section --> postgres/src/lib.rs:35:5 | 35 | / pub fn new_from_stringlike( 36 | | params: T, 37 | | tls: Tls, 38 | | ) -> Result, Error> ... | 44 | | Ok(Self::new(config, tls)) 45 | | } | |_____^ | = note: `-W clippy::missing-errors-doc` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc warning: this argument is passed by value, but not consumed in the function body --> postgres/src/lib.rs:36:17 | 36 | params: T, | ^ help: consider taking a reference instead: `&T` | = note: `-W clippy::needless-pass-by-value` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value warning: this trait bound is already specified in the where clause --> postgres/src/lib.rs:52:46 | 52 | >::Stream: Send + Sync, | ^^^^ | = note: `-W clippy::trait-duplication-in-bounds` implied by `-W clippy::pedantic` = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds warning: docs for function returning `Result` missing `# Errors` section --> redis/src/lib.rs:54:5 | 54 | / pub fn new(info: T) -> Result { 55 | | Ok(RedisConnectionManager { 56 | | client: Client::open(info.into_connection_info()?)?, 57 | | }) 58 | | } | |_____^ | = note: `-W clippy::missing-errors-doc` implied by `-W clippy::pedantic` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc warning: `bb8-postgres` (lib) generated 3 warnings warning: `bb8-redis` (lib) generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.05s ```
djc commented 2 years ago

Let's start with a PR that fixes these: return_self_not_must_use, missing_panic_docs, trait-duplication-in-bounds, semicolon-if-nothing-returned, default-trait-access, then we can go from there.