diff --git a/Makefile b/Makefile index 278f7fe4e47..2f29e1d04f1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,12 @@ +# TODO: consider adding these clippy fixes and/or some other? +# -D clippy::default-trait-access \ +# -D clippy::explicit-iter-loop \ +# -D clippy::map-unwrap-or \ +# -D clippy::range-plus-one \ + +CLIPPY_FLAGS = \ + -D clippy::unnested-or-patterns + help: ## Display this help @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) @@ -51,10 +60,16 @@ doc: ## Run cargo doc on all crates cargo doc --features=max,lean,small clippy: ## Run cargo clippy on all crates - cargo clippy --all --tests --examples - cargo clippy --all --no-default-features --features small - cargo clippy --all --no-default-features --features max-pure - cargo clippy --all --no-default-features --features lean-async --tests + cargo clippy --all --tests --examples -- $(CLIPPY_FLAGS) + cargo clippy --all --no-default-features --features small -- $(CLIPPY_FLAGS) + cargo clippy --all --no-default-features --features max-pure -- $(CLIPPY_FLAGS) + cargo clippy --all --no-default-features --features lean-async --tests -- $(CLIPPY_FLAGS) + +fix-clippy: ## Run cargo clippy on all crates, fixing what can be fixed + cargo clippy --fix --all --tests --examples -- $(CLIPPY_FLAGS) + cargo clippy --fix --allow-dirty --all --no-default-features --features small -- $(CLIPPY_FLAGS) + cargo clippy --fix --allow-dirty --all --no-default-features --features max-pure -- $(CLIPPY_FLAGS) + cargo clippy --fix --allow-dirty --all --no-default-features --features lean-async --tests -- $(CLIPPY_FLAGS) check-msrv: ## run cargo msrv to validate the current msrv requirements, similar to what CI does cd gix && cargo check --package gix --no-default-features --features async-network-client,max-performance @@ -342,4 +357,3 @@ fmt: ## run nightly rustfmt for its extra features, but check that it won't upse try-publish-all: ## Dry-run publish all crates in the currently set version if they are not published yet. (cd cargo-smart-release && cargo build --bin cargo-smart-release) && cargo-smart-release/target/debug/cargo-smart-release smart-release gitoxide - diff --git a/cargo-smart-release/src/changelog/parse.rs b/cargo-smart-release/src/changelog/parse.rs index 5af17f429f1..042ba9fc03e 100644 --- a/cargo-smart-release/src/changelog/parse.rs +++ b/cargo-smart-release/src/changelog/parse.rs @@ -437,10 +437,12 @@ fn track_unknown_event(unknown_event: Event<'_>, unknown: &mut String) { | Event::Code(text) | Event::Text(text) | Event::FootnoteReference(text) - | Event::Start(Tag::FootnoteDefinition(text)) - | Event::Start(Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(text))) - | Event::Start(Tag::Link(_, text, _)) - | Event::Start(Tag::Image(_, text, _)) => unknown.push_str(text.as_ref()), + | Event::Start( + Tag::FootnoteDefinition(text) + | Tag::CodeBlock(pulldown_cmark::CodeBlockKind::Fenced(text)) + | Tag::Link(_, text, _) + | Tag::Image(_, text, _), + ) => unknown.push_str(text.as_ref()), _ => {} } } diff --git a/cargo-smart-release/src/git/history.rs b/cargo-smart-release/src/git/history.rs index 96a6342046a..6a9e0780feb 100644 --- a/cargo-smart-release/src/git/history.rs +++ b/cargo-smart-release/src/git/history.rs @@ -249,7 +249,7 @@ fn add_item_if_package_changed<'a>( } history.push(item) } - (None, Some(_)) | (None, None) => {} + (None, _) => {} }; } Filter::Slow { ref components } => { @@ -269,7 +269,7 @@ fn add_item_if_package_changed<'a>( } } (Some(_), None) => history.push(item), - (None, Some(_)) | (None, None) => {} + (None, _) => {} }; } }; diff --git a/gitoxide-core/src/repository/config.rs b/gitoxide-core/src/repository/config.rs index 5ec1bedba6e..7b215196628 100644 --- a/gitoxide-core/src/repository/config.rs +++ b/gitoxide-core/src/repository/config.rs @@ -81,8 +81,8 @@ impl Filter { return false; } } - (None, None) | (None, Some(_)) => {} - _ => return false, + (None, _) => {} + (Some(_), None) => return false, }; true } diff --git a/gix-credentials/src/program/main.rs b/gix-credentials/src/program/main.rs index 062bcfc99a3..b3417f92372 100644 --- a/gix-credentials/src/program/main.rs +++ b/gix-credentials/src/program/main.rs @@ -18,9 +18,9 @@ impl TryFrom for Action { fn try_from(value: OsString) -> Result { Ok(match value.to_str() { - Some("fill") | Some("get") => Action::Get, - Some("approve") | Some("store") => Action::Store, - Some("reject") | Some("erase") => Action::Erase, + Some("fill" | "get") => Action::Get, + Some("approve" | "store") => Action::Store, + Some("reject" | "erase") => Action::Erase, _ => return Err(Error::ActionInvalid { name: value }), }) } diff --git a/gix-discover/src/upwards/mod.rs b/gix-discover/src/upwards/mod.rs index 87e6a18b4d2..e3bbc7a2bd8 100644 --- a/gix-discover/src/upwards/mod.rs +++ b/gix-discover/src/upwards/mod.rs @@ -169,7 +169,7 @@ pub(crate) mod function { if dir_made_absolute || matches!( cursor.components().next(), - Some(std::path::Component::RootDir) | Some(std::path::Component::Prefix(_)) + Some(std::path::Component::RootDir | std::path::Component::Prefix(_)) ) { break Err(Error::NoGitRepository { path: dir.into_owned() }); diff --git a/gix-features/src/zlib/stream/inflate.rs b/gix-features/src/zlib/stream/inflate.rs index 007ecedc693..f68f45f57c9 100644 --- a/gix-features/src/zlib/stream/inflate.rs +++ b/gix-features/src/zlib/stream/inflate.rs @@ -46,11 +46,11 @@ pub fn read(rd: &mut impl BufRead, state: &mut Decompress, mut dst: &mut [u8]) - // The stream has officially ended, nothing more to do here. Ok(Status::StreamEnd) => return Ok(total_written), // Either input our output are depleted even though the stream is not depleted yet. - Ok(Status::Ok) | Ok(Status::BufError) if eof || dst.is_empty() => return Ok(total_written), + Ok(Status::Ok | Status::BufError) if eof || dst.is_empty() => return Ok(total_written), // Some progress was made in both the input and the output, it must continue to reach the end. - Ok(Status::Ok) | Ok(Status::BufError) if consumed != 0 || written != 0 => continue, + Ok(Status::Ok | Status::BufError) if consumed != 0 || written != 0 => continue, // A strange state, where zlib makes no progress but isn't done either. Call it out. - Ok(Status::Ok) | Ok(Status::BufError) => unreachable!("Definitely a bug somewhere"), + Ok(Status::Ok | Status::BufError) => unreachable!("Definitely a bug somewhere"), Err(..) => return Err(io::Error::new(io::ErrorKind::InvalidInput, "corrupt deflate stream")), } } diff --git a/gix-object/src/commit/ref_iter.rs b/gix-object/src/commit/ref_iter.rs index 313f90945b8..5d350de031a 100644 --- a/gix-object/src/commit/ref_iter.rs +++ b/gix-object/src/commit/ref_iter.rs @@ -68,7 +68,7 @@ impl<'a> CommitRefIter<'a> { /// Errors are not the common case - if an error needs to be detectable, use this instance as iterator. pub fn signatures(self) -> impl Iterator> + 'a { self.filter_map(|t| match t { - Ok(Token::Author { signature }) | Ok(Token::Committer { signature }) => Some(signature), + Ok(Token::Author { signature } | Token::Committer { signature }) => Some(signature), _ => None, }) } diff --git a/gix-odb/src/store_impls/dynamic/prefix.rs b/gix-odb/src/store_impls/dynamic/prefix.rs index 9097c8cf66f..c39e2031fb9 100644 --- a/gix-odb/src/store_impls/dynamic/prefix.rs +++ b/gix-odb/src/store_impls/dynamic/prefix.rs @@ -184,7 +184,7 @@ where fn check_candidate(lookup_result: Option, candidate: &mut Option) -> bool { match (lookup_result, &*candidate) { (Some(Ok(oid)), Some(candidate)) if *candidate != oid => false, - (Some(Ok(_)), Some(_)) | (None, None) | (None, Some(_)) => true, + (Some(Ok(_)) | None, Some(_)) | (None, None) => true, (Some(Err(())), _) => false, (Some(Ok(oid)), None) => { *candidate = Some(oid); diff --git a/gix-odb/src/store_impls/dynamic/types.rs b/gix-odb/src/store_impls/dynamic/types.rs index df2365433de..c77cf21096e 100644 --- a/gix-odb/src/store_impls/dynamic/types.rs +++ b/gix-odb/src/store_impls/dynamic/types.rs @@ -214,16 +214,16 @@ impl OnDiskFile { match std::mem::replace(&mut self.state, OnDiskFileState::Missing) { OnDiskFileState::Garbage(v) => self.state = OnDiskFileState::Loaded(v), OnDiskFileState::Missing => self.state = OnDiskFileState::Unloaded, - other @ OnDiskFileState::Loaded(_) | other @ OnDiskFileState::Unloaded => self.state = other, + other @ (OnDiskFileState::Loaded(_) | OnDiskFileState::Unloaded) => self.state = other, } } pub fn trash(&mut self) { match std::mem::replace(&mut self.state, OnDiskFileState::Missing) { OnDiskFileState::Loaded(v) => self.state = OnDiskFileState::Garbage(v), - other @ OnDiskFileState::Garbage(_) - | other @ OnDiskFileState::Unloaded - | other @ OnDiskFileState::Missing => self.state = other, + other @ (OnDiskFileState::Garbage(_) | OnDiskFileState::Unloaded | OnDiskFileState::Missing) => { + self.state = other + } } } } diff --git a/gix-path/src/realpath.rs b/gix-path/src/realpath.rs index 807cb74ccf6..8b88eb15eb6 100644 --- a/gix-path/src/realpath.rs +++ b/gix-path/src/realpath.rs @@ -58,7 +58,7 @@ pub(crate) mod function { let mut components = path.components(); while let Some(component) = components.next() { match component { - part @ RootDir | part @ Prefix(_) => real_path.push(part), + part @ (RootDir | Prefix(_)) => real_path.push(part), CurDir => {} ParentDir => { if !real_path.pop() { diff --git a/gix-ref/src/store/file/transaction/prepare.rs b/gix-ref/src/store/file/transaction/prepare.rs index ede962faed7..4790572cc2b 100644 --- a/gix-ref/src/store/file/transaction/prepare.rs +++ b/gix-ref/src/store/file/transaction/prepare.rs @@ -75,17 +75,17 @@ impl<'s, 'p> Transaction<'s, 'p> { (PreviousValue::MustNotExist, _) => { panic!("BUG: MustNotExist constraint makes no sense if references are to be deleted") } - (PreviousValue::ExistingMustMatch(_), None) - | (PreviousValue::MustExist, Some(_)) - | (PreviousValue::Any, Some(_)) - | (PreviousValue::Any, None) => {} - (PreviousValue::MustExist, None) | (PreviousValue::MustExistAndMatch(_), None) => { + (PreviousValue::ExistingMustMatch(_) | PreviousValue::Any, None) + | (PreviousValue::MustExist | PreviousValue::Any, Some(_)) => {} + (PreviousValue::MustExist | PreviousValue::MustExistAndMatch(_), None) => { return Err(Error::DeleteReferenceMustExist { full_name: change.name(), }) } - (PreviousValue::MustExistAndMatch(previous), Some(existing)) - | (PreviousValue::ExistingMustMatch(previous), Some(existing)) => { + ( + PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous), + Some(existing), + ) => { let actual = existing.target.clone(); if *previous != actual { let expected = previous.clone(); @@ -124,8 +124,7 @@ impl<'s, 'p> Transaction<'s, 'p> { match (&expected, &existing_ref) { (PreviousValue::Any, _) | (PreviousValue::MustExist, Some(_)) - | (PreviousValue::MustNotExist, None) - | (PreviousValue::ExistingMustMatch(_), None) => {} + | (PreviousValue::MustNotExist | PreviousValue::ExistingMustMatch(_), None) => {} (PreviousValue::MustExist, None) => { let expected = Target::Peeled(store.object_hash.null()); let full_name = change.name(); @@ -141,8 +140,10 @@ impl<'s, 'p> Transaction<'s, 'p> { }); } } - (PreviousValue::MustExistAndMatch(previous), Some(existing)) - | (PreviousValue::ExistingMustMatch(previous), Some(existing)) => { + ( + PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous), + Some(existing), + ) => { if *previous != existing.target { let actual = existing.target.clone(); let expected = previous.to_owned(); diff --git a/gix-ref/src/transaction/mod.rs b/gix-ref/src/transaction/mod.rs index d13ff2e7015..77ab7349d6d 100644 --- a/gix-ref/src/transaction/mod.rs +++ b/gix-ref/src/transaction/mod.rs @@ -96,19 +96,11 @@ impl Change { match self { // TODO: use or-patterns once MRV is larger than 1.52 (and this is supported) Change::Update { - expected: PreviousValue::MustExistAndMatch(previous), - .. - } - | Change::Update { - expected: PreviousValue::ExistingMustMatch(previous), - .. - } - | Change::Delete { - expected: PreviousValue::MustExistAndMatch(previous), + expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous), .. } | Change::Delete { - expected: PreviousValue::ExistingMustMatch(previous), + expected: PreviousValue::MustExistAndMatch(previous) | PreviousValue::ExistingMustMatch(previous), .. } => previous, _ => return None, diff --git a/gix-refspec/src/match_group/util.rs b/gix-refspec/src/match_group/util.rs index 5339aef3285..7606dbe8aba 100644 --- a/gix-refspec/src/match_group/util.rs +++ b/gix-refspec/src/match_group/util.rs @@ -20,7 +20,7 @@ impl<'a> Matcher<'a> { match (self.lhs, self.rhs) { (Some(lhs), None) => (lhs.matches(item).is_match(), None), (Some(lhs), Some(rhs)) => lhs.matches(item).into_match_outcome(rhs, item), - (None, None) | (None, Some(_)) => { + (None, _) => { unreachable!("For all we know, the lefthand side is never empty. Push specs might change that.") } } diff --git a/gix-transport/src/client/blocking_io/http/curl/remote.rs b/gix-transport/src/client/blocking_io/http/curl/remote.rs index 8f58676980c..3b435423d75 100644 --- a/gix-transport/src/client/blocking_io/http/curl/remote.rs +++ b/gix-transport/src/client/blocking_io/http/curl/remote.rs @@ -322,7 +322,7 @@ pub fn new() -> ( handler.receive_body.take(); match (handler.send_header.take(), handler.send_data.take()) { (Some(header), mut data) => { - if let Err(TrySendError::Disconnected(err)) | Err(TrySendError::Full(err)) = + if let Err(TrySendError::Disconnected(err) | TrySendError::Full(err)) = header.channel.try_send(err) { if let Some(body) = data.take() { diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index c6af57c7d61..513de3d9cf0 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -987,7 +987,7 @@ fn stdin_or_bail() -> Result> { fn verify_mode(decode: bool, re_encode: bool) -> verify::Mode { match (decode, re_encode) { (true, false) => verify::Mode::HashCrc32Decode, - (true, true) | (false, true) => verify::Mode::HashCrc32DecodeEncode, + (_, true) => verify::Mode::HashCrc32DecodeEncode, (false, false) => verify::Mode::HashCrc32, } } diff --git a/src/shared.rs b/src/shared.rs index 5fc2ab8eeac..0133bcf939e 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -89,7 +89,7 @@ pub mod pretty { res } #[cfg(not(feature = "prodash-render-tui"))] - (true, true) | (false, true) => { + (_, true) => { unreachable!("BUG: This branch can't be run without a TUI built-in") } } @@ -134,11 +134,11 @@ pub mod pretty { res } #[cfg(not(feature = "prodash-render-tui"))] - (true, true) | (false, true) => { + (_, true) => { unreachable!("BUG: This branch can't be run without a TUI built-in") } #[cfg(feature = "prodash-render-tui")] - (true, true) | (false, true) => { + (_, true) => { use std::io::Write; use crate::shared;