From 0ccac34ff92fac4ddb488e8f1c7f9527e12b231b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 15 Nov 2024 19:24:46 -0800 Subject: [PATCH] Resolve question_mark clippy lint warning: this `match` expression can be replaced with `?` --> src/generics.rs:191:20 | 191 | let next = match self.0.next() { | ____________________^ 192 | | Some(item) => item, 193 | | None => return None, 194 | | }; | |_________^ help: try instead: `self.0.next()?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark = note: `-W clippy::question-mark` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::question_mark)]` warning: this `match` expression can be replaced with `?` --> src/generics.rs:209:20 | 209 | let next = match self.0.next() { | ____________________^ 210 | | Some(item) => item, 211 | | None => return None, 212 | | }; | |_________^ help: try instead: `self.0.next()?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark warning: this `match` expression can be replaced with `?` --> src/generics.rs:227:20 | 227 | let next = match self.0.next() { | ____________________^ 228 | | Some(item) => item, 229 | | None => return None, 230 | | }; | |_________^ help: try instead: `self.0.next()?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark warning: this `match` expression can be replaced with `?` --> src/generics.rs:245:20 | 245 | let next = match self.0.next() { | ____________________^ 246 | | Some(item) => item, 247 | | None => return None, 248 | | }; | |_________^ help: try instead: `self.0.next()?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark warning: this `match` expression can be replaced with `?` --> src/generics.rs:263:20 | 263 | let next = match self.0.next() { | ____________________^ 264 | | Some(item) => item, 265 | | None => return None, 266 | | }; | |_________^ help: try instead: `self.0.next()?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark warning: this `match` expression can be replaced with `?` --> src/generics.rs:281:20 | 281 | let next = match self.0.next() { | ____________________^ 282 | | Some(item) => item, 283 | | None => return None, 284 | | }; | |_________^ help: try instead: `self.0.next()?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark --- src/generics.rs | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/generics.rs b/src/generics.rs index 1e8fccf03..b0723691e 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -188,11 +188,7 @@ impl<'a> Iterator for Lifetimes<'a> { type Item = &'a LifetimeParam; fn next(&mut self) -> Option { - let next = match self.0.next() { - Some(item) => item, - None => return None, - }; - if let GenericParam::Lifetime(lifetime) = next { + if let GenericParam::Lifetime(lifetime) = self.0.next()? { Some(lifetime) } else { self.next() @@ -206,11 +202,7 @@ impl<'a> Iterator for LifetimesMut<'a> { type Item = &'a mut LifetimeParam; fn next(&mut self) -> Option { - let next = match self.0.next() { - Some(item) => item, - None => return None, - }; - if let GenericParam::Lifetime(lifetime) = next { + if let GenericParam::Lifetime(lifetime) = self.0.next()? { Some(lifetime) } else { self.next() @@ -224,11 +216,7 @@ impl<'a> Iterator for TypeParams<'a> { type Item = &'a TypeParam; fn next(&mut self) -> Option { - let next = match self.0.next() { - Some(item) => item, - None => return None, - }; - if let GenericParam::Type(type_param) = next { + if let GenericParam::Type(type_param) = self.0.next()? { Some(type_param) } else { self.next() @@ -242,11 +230,7 @@ impl<'a> Iterator for TypeParamsMut<'a> { type Item = &'a mut TypeParam; fn next(&mut self) -> Option { - let next = match self.0.next() { - Some(item) => item, - None => return None, - }; - if let GenericParam::Type(type_param) = next { + if let GenericParam::Type(type_param) = self.0.next()? { Some(type_param) } else { self.next() @@ -260,11 +244,7 @@ impl<'a> Iterator for ConstParams<'a> { type Item = &'a ConstParam; fn next(&mut self) -> Option { - let next = match self.0.next() { - Some(item) => item, - None => return None, - }; - if let GenericParam::Const(const_param) = next { + if let GenericParam::Const(const_param) = self.0.next()? { Some(const_param) } else { self.next() @@ -278,11 +258,7 @@ impl<'a> Iterator for ConstParamsMut<'a> { type Item = &'a mut ConstParam; fn next(&mut self) -> Option { - let next = match self.0.next() { - Some(item) => item, - None => return None, - }; - if let GenericParam::Const(const_param) = next { + if let GenericParam::Const(const_param) = self.0.next()? { Some(const_param) } else { self.next()