aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock195
-rw-r--r--Cargo.toml2
-rw-r--r--src/args.rs4
-rw-r--r--src/main.rs7
-rw-r--r--src/makefile/command_line.rs9
-rw-r--r--src/makefile/functions.rs26
-rw-r--r--src/makefile/inference_rules.rs7
-rw-r--r--src/makefile/input.rs29
-rw-r--r--src/makefile/macro.rs10
-rw-r--r--src/makefile/mod.rs18
-rw-r--r--src/makefile/target.rs10
-rw-r--r--src/makefile/token.rs2
12 files changed, 150 insertions, 169 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8e07f7d..50053e7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,9 +4,9 @@ version = 3
[[package]]
name = "addr2line"
-version = "0.14.1"
+version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7"
+checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
@@ -28,9 +28,9 @@ dependencies = [
[[package]]
name = "anstream"
-version = "0.6.15"
+version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
+checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
@@ -43,51 +43,46 @@ dependencies = [
[[package]]
name = "anstyle"
-version = "1.0.8"
+version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
+checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
-version = "0.2.5"
+version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
+checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
-version = "1.1.1"
+version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
+checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
- "windows-sys 0.52.0",
+ "windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
-version = "3.0.4"
+version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
+checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
- "windows-sys 0.52.0",
+ "windows-sys 0.59.0",
]
[[package]]
-name = "autocfg"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
-
-[[package]]
name = "backtrace"
-version = "0.3.56"
+version = "0.3.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
+checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
dependencies = [
"addr2line",
+ "cc",
"cfg-if",
"libc",
"miniz_oxide",
@@ -102,6 +97,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
+name = "cc"
+version = "1.1.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf"
+dependencies = [
+ "shlex",
+]
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -139,7 +143,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
- "syn 2.0.87",
+ "syn",
]
[[package]]
@@ -150,9 +154,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
[[package]]
name = "color-eyre"
-version = "0.5.10"
+version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b29030875fd8376e4a28ef497790d5b4a7843d8d1396bf08ce46f5eec562c5c"
+checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5"
dependencies = [
"backtrace",
"color-spantrace",
@@ -165,9 +169,9 @@ dependencies = [
[[package]]
name = "color-spantrace"
-version = "0.1.6"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b6eee477a4a8a72f4addd4de416eb56d54bc307b284d6601bafdee1f4ea462d1"
+checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
dependencies = [
"once_cell",
"owo-colors",
@@ -177,9 +181,9 @@ dependencies = [
[[package]]
name = "colorchoice"
-version = "1.0.2"
+version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
+checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "dirs"
@@ -247,9 +251,9 @@ dependencies = [
[[package]]
name = "fastrand"
-version = "2.1.1"
+version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
+checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4"
[[package]]
name = "getrandom"
@@ -264,9 +268,9 @@ dependencies = [
[[package]]
name = "gimli"
-version = "0.23.0"
+version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce"
+checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "glob"
@@ -299,15 +303,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
-name = "jane-eyre"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7ccd957c837e264dcbc6e75b58fcf85fd329a66e4836f820779c40563a2d0be0"
-dependencies = [
- "color-eyre",
-]
-
-[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -315,9 +310,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
-version = "0.2.159"
+version = "0.2.162"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
+checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
[[package]]
name = "libredox"
@@ -346,11 +341,11 @@ name = "makers"
version = "0.7.0"
dependencies = [
"clap",
+ "color-eyre",
"dirs",
"env_logger",
"eyre",
"glob",
- "jane-eyre",
"lazy_static",
"log",
"nom",
@@ -372,12 +367,11 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
-version = "0.4.4"
+version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
+checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
- "autocfg",
]
[[package]]
@@ -392,9 +386,12 @@ dependencies = [
[[package]]
name = "object"
-version = "0.23.0"
+version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
+checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
+dependencies = [
+ "memchr",
+]
[[package]]
name = "once_cell"
@@ -410,15 +407,15 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "owo-colors"
-version = "1.3.0"
+version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55"
+checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "pin-project-lite"
-version = "0.2.6"
+version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
+checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff"
[[package]]
name = "proc-macro2"
@@ -451,9 +448,9 @@ dependencies = [
[[package]]
name = "regex"
-version = "1.11.0"
+version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8"
+checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
@@ -480,15 +477,15 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "rustc-demangle"
-version = "0.1.18"
+version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
+checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustix"
-version = "0.38.37"
+version = "0.38.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
+checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0"
dependencies = [
"bitflags",
"errno",
@@ -499,29 +496,24 @@ dependencies = [
[[package]]
name = "sharded-slab"
-version = "0.1.1"
+version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3"
+checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
-name = "strsim"
-version = "0.11.1"
+name = "shlex"
+version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
-name = "syn"
-version = "1.0.109"
+name = "strsim"
+version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
@@ -536,9 +528,9 @@ dependencies = [
[[package]]
name = "tempfile"
-version = "3.13.0"
+version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b"
+checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c"
dependencies = [
"cfg-if",
"fastrand",
@@ -559,70 +551,59 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.39"
+version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c"
+checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.39"
+version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
+checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
- "syn 1.0.109",
+ "syn",
]
[[package]]
name = "thread_local"
-version = "1.1.3"
+version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
+checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
+ "cfg-if",
"once_cell",
]
[[package]]
name = "tracing"
-version = "0.1.25"
+version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f"
+checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
- "cfg-if",
"pin-project-lite",
- "tracing-attributes",
"tracing-core",
]
[[package]]
-name = "tracing-attributes"
-version = "0.1.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
-
-[[package]]
name = "tracing-core"
-version = "0.1.17"
+version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f"
+checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
- "lazy_static",
+ "once_cell",
+ "valuable",
]
[[package]]
name = "tracing-error"
-version = "0.1.2"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24"
+checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
@@ -630,9 +611,9 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
-version = "0.2.17"
+version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "705096c6f83bf68ea5d357a6aa01829ddbdac531b357b45abeca842938085baa"
+checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"sharded-slab",
"thread_local",
@@ -652,6 +633,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
+name = "valuable"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
+
+[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index b684995..fb8f888 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,11 +16,11 @@ full = ['dirs', 'glob']
[dependencies]
clap = { version = "4.5.20", features = ["derive", "wrap_help"] }
+color-eyre = "0.6.3"
dirs = { version = "5.0.1", optional = true }
env_logger = "0.11.5"
eyre = "0.6.12"
glob = { version = "0.3.1", optional = true }
-jane-eyre = "0.3.0"
lazy_static = "1.5.0"
log = "0.4.22"
nom = "7.1.3"
diff --git a/src/args.rs b/src/args.rs
index b4e6f84..baddb47 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -157,9 +157,7 @@ impl Args {
// so we need to make sure it goes in before MAKEFLAGS
let arg_0 = args.next().unwrap_or_else(|| env!("CARGO_PKG_NAME").into());
- let args = iter::once(arg_0)
- .chain(env_makeflags.into_iter())
- .chain(args);
+ let args = iter::once(arg_0).chain(env_makeflags).chain(args);
Self::parse_from(args)
}
diff --git a/src/main.rs b/src/main.rs
index 8fa4efd..d4c0cdc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,7 +11,7 @@
clippy::nursery,
clippy::str_to_string,
clippy::unwrap_used,
- clippy::integer_arithmetic,
+ clippy::arithmetic_side_effects,
clippy::panic,
clippy::unimplemented,
clippy::todo,
@@ -43,7 +43,7 @@ const DEFAULT_PATHS: &[&str] = &[
fn main() -> Result<()> {
env_logger::init();
- jane_eyre::install()?;
+ color_eyre::install()?;
let mut args = Args::from_env_and_args();
#[cfg(feature = "full")]
@@ -66,13 +66,12 @@ fn main() -> Result<()> {
let mut makefile = Makefile::new(&args);
let paths = Default::default();
for filename in &args.makefile {
+ let macros = makefile.macros.with_overlay();
if filename == &PathBuf::from("-") {
- let macros = makefile.macros.with_overlay();
let file = MakefileReader::read(&args, macros, stdin().lock(), "-", Rc::clone(&paths))?
.finish();
makefile.extend(file)?;
} else {
- let macros = makefile.macros.with_overlay();
let file =
MakefileReader::read_file(&args, macros, filename, Rc::clone(&paths))?.finish();
makefile.extend(file)?;
diff --git a/src/makefile/command_line.rs b/src/makefile/command_line.rs
index 6a45c18..ae6c9e9 100644
--- a/src/makefile/command_line.rs
+++ b/src/makefile/command_line.rs
@@ -94,14 +94,13 @@ impl CommandLine {
#[cfg(feature = "full")]
{
let is_just_one_macro_expansion = self.execution_line.tokens().count() == 1
- && self.execution_line.tokens().all(|x| match x {
- Token::MacroExpansion { .. } => true,
- Token::FunctionCall { .. } => true,
- _ => false,
+ && self.execution_line.tokens().all(|x| {
+ matches!(x, Token::MacroExpansion { .. } | Token::FunctionCall { .. })
});
// unfortunately, if we had a multiline macro somewhere with non-escaped newlines, now we have to run each of them as separate lines
lazy_static! {
- static ref UNESCAPED_NEWLINE: Regex = Regex::new(r"([^\\])\n").unwrap();
+ static ref UNESCAPED_NEWLINE: Regex = #[allow(clippy::unwrap_used)]
+ Regex::new(r"([^\\])\n").unwrap();
}
if is_just_one_macro_expansion && UNESCAPED_NEWLINE.is_match(&execution_line) {
let lines = UNESCAPED_NEWLINE
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index a78d582..5d5e222 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -10,6 +10,7 @@ use super::r#macro::{Macro, Set as MacroSet};
use super::token::TokenString;
use super::ItemSource;
+#[allow(clippy::cognitive_complexity)]
pub fn expand_call(
name: &str,
args: &[TokenString],
@@ -174,17 +175,14 @@ mod text {
let from = macros.expand(from)?;
let to = macros.expand(to)?;
let text = macros.expand(text)?;
- let words = text
- .split_whitespace()
- .map(|word| {
- let pattern_match = r#match(&from, word)?.and_then(|x| x.get(1));
- Ok(if let Some(pm) = pattern_match {
- to.replace('%', pm.as_str())
- } else {
- word.to_owned()
+ let words =
+ text.split_whitespace()
+ .map(|word| {
+ let pattern_match = r#match(&from, word)?.and_then(|x| x.get(1));
+ Ok(pattern_match
+ .map_or_else(|| word.to_owned(), |pm| to.replace('%', pm.as_str())))
})
- })
- .collect::<Result<Vec<_>>>()?;
+ .collect::<Result<Vec<_>>>()?;
Ok(words.join(" "))
}
@@ -273,7 +271,7 @@ mod text {
pub fn firstword(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
- Ok(words.split_whitespace().nth(0).unwrap_or("").to_owned())
+ Ok(words.split_whitespace().next().unwrap_or("").to_owned())
}
pub fn lastword(macros: &MacroSet, words: &TokenString) -> Result<String> {
@@ -419,11 +417,7 @@ mod conditional {
condition.trim_end();
let condition = macros.expand(&condition)?;
if condition.is_empty() {
- if let Some(if_false) = if_false {
- macros.expand(if_false)
- } else {
- Ok(String::new())
- }
+ if_false.map_or_else(|| Ok(String::new()), |if_false| macros.expand(if_false))
} else {
macros.expand(if_true)
}
diff --git a/src/makefile/inference_rules.rs b/src/makefile/inference_rules.rs
index 368d72b..f8bdd65 100644
--- a/src/makefile/inference_rules.rs
+++ b/src/makefile/inference_rules.rs
@@ -1,6 +1,6 @@
use std::fmt;
-use eyre::{eyre, Result};
+use eyre::{eyre, OptionExt, Result};
use regex::Captures;
use super::command_line::CommandLine;
@@ -49,7 +49,10 @@ impl InferenceRule {
let capture = self
.first_match(target_name)?
.ok_or_else(|| eyre!("asked non-matching inference rule for prerequisites"))?;
- let percent_expansion = capture.get(1).expect("should've matched the %").as_str();
+ let percent_expansion = capture
+ .get(1)
+ .ok_or_eyre("should've matched the %")?
+ .as_str();
Ok(self
.prerequisites
.iter()
diff --git a/src/makefile/input.rs b/src/makefile/input.rs
index 318493b..ed1140e 100644
--- a/src/makefile/input.rs
+++ b/src/makefile/input.rs
@@ -96,9 +96,11 @@ fn inference_match<'a>(
prerequisites: &[String],
) -> Option<InferenceMatch<'a>> {
lazy_static! {
- static ref INFERENCE_RULE: Regex =
- Regex::new(r"^(?P<s2>(\.[^/.]+)?)(?P<s1>\.[^/.]+)$").unwrap();
- static ref SPECIAL_TARGET: Regex = Regex::new(r"^\.[A-Z]+$").unwrap();
+ static ref INFERENCE_RULE: Regex = #[allow(clippy::unwrap_used)]
+ Regex::new(r"^(?P<s2>(\.[^/.]+)?)(?P<s1>\.[^/.]+)$")
+ .unwrap();
+ static ref SPECIAL_TARGET: Regex = #[allow(clippy::unwrap_used)]
+ Regex::new(r"^\.[A-Z]+$").unwrap();
}
let inference_match = INFERENCE_RULE.captures(targets[0]);
@@ -109,6 +111,7 @@ fn inference_match<'a>(
&& inference_match.is_some()
&& special_target_match.is_none();
if inference_rule {
+ #[allow(clippy::unwrap_used)]
inference_match.map(|x| InferenceMatch {
s1: x.name("s1").unwrap().as_str(),
s2: x.name("s2").unwrap().as_str(),
@@ -128,7 +131,7 @@ where
E: StdError + Send + Sync + 'static,
Inner: Iterator<Item = Result<T, E>>,
{
- fn new(inner: Inner) -> Self {
+ const fn new(inner: Inner) -> Self {
Self(inner, 0)
}
}
@@ -302,7 +305,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
let line_type = LineType::of(&line_tokens);
// before we actually test it, see if it's only visible after expanding macros
- let (line_tokens, line_type) = if let LineType::Unknown = line_type {
+ let (line_tokens, line_type) = if matches!(line_type, LineType::Unknown) {
let line_tokens = TokenString::text(
self.expand_macros(&line_tokens)
.wrap_err_with(|| format!("while parsing line {}", line_number))?
@@ -365,8 +368,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
} else {
let exported = if line_tokens.contains_text("=") {
// that's an assignment!
- let new_macro = self.read_macro(line_tokens, line_number)?;
- new_macro
+ self.read_macro(line_tokens, line_number)?
} else {
self.expand_macros(&line_tokens)?
};
@@ -401,7 +403,8 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
fn next_line(&mut self, settings: NextLineSettings) -> Option<(usize, Result<String>)> {
lazy_static! {
- static ref COMMENT: Regex = Regex::new(r"(^|[^\\])#.*$").unwrap();
+ static ref COMMENT: Regex = #[allow(clippy::unwrap_used)]
+ Regex::new(r"(^|[^\\])#.*$").unwrap();
}
let escaped_newline_replacement = settings.escaped_newline_replacement;
if let Some((line_number, line)) = self.pending_line.take() {
@@ -522,17 +525,13 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
}
fn special_target_has_prereq(&self, target: &str, name: &str, empty_counts: bool) -> bool {
- match self
- .targets
+ self.targets
.get(target)
.or_else(|| self.built_in_targets.get(target))
- {
- Some(target) => {
+ .map_or(false, |target| {
(empty_counts && target.prerequisites.is_empty())
|| target.prerequisites.iter().any(|e| e == name)
- }
- None => false,
- }
+ })
}
fn read_include(&mut self, mut line_tokens: TokenString, line_number: usize) -> Result<()> {
diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs
index 25f8627..daf770d 100644
--- a/src/makefile/macro.rs
+++ b/src/makefile/macro.rs
@@ -191,10 +191,10 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> {
sne.extend(one);
}
(ExportConfig::Only(se), ExportConfig::AllBut(one)) => {
- se.extend(other.keys().cloned().filter(|name| !one.contains(name)));
+ se.extend(other.keys().filter(|name| !one.contains(*name)).cloned());
}
(ExportConfig::AllBut(sne), ExportConfig::Only(oe)) => {
- sne.extend(other.keys().cloned().filter(|name| !oe.contains(name)));
+ sne.extend(other.keys().filter(|name| !oe.contains(*name)).cloned());
}
}
self.data.extend(other);
@@ -397,6 +397,12 @@ impl fmt::Display for Set<'_, '_> {
}
}
+impl Default for Set<'_, '_> {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
fn builtins() -> Vec<(&'static str, TokenString)> {
// Fuck it, might as well.
macro_rules! handle {
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index 74f1f4b..62cc416 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -161,13 +161,10 @@ impl<'a> Makefile<'a> {
}
fn special_target_has_prereq(&self, target: &str, name: &str) -> bool {
- match self.targets.get(target) {
- Some(target) => {
- let target = target.borrow();
- target.prerequisites.is_empty() || target.prerequisites.iter().any(|e| e == name)
- }
- None => false,
- }
+ self.targets.get(target).map_or(false, |target| {
+ let target = target.borrow();
+ target.prerequisites.is_empty() || target.prerequisites.iter().any(|e| e == name)
+ })
}
fn infer_target(
@@ -326,10 +323,9 @@ impl<'a> Makefile<'a> {
self.targets.put(new_target);
}
- Ok(self
- .targets
+ self.targets
.get(name)
- .ok_or_else(|| eyre!("Target {:?} not found!", name))?)
+ .ok_or_else(|| eyre!("Target {:?} not found!", name))
}
pub fn update_target(&self, name: &str) -> Result<()> {
@@ -376,7 +372,7 @@ impl<'a> Makefile<'a> {
// chosen for the target. In the .DEFAULT rule, the $< macro
// shall evaluate to the current target name.
// TODO make that actually be the case (rn exists_but_inferring_anyway might fuck that up)
- vec![target.prerequisites.get(0).cloned().unwrap_or_default()]
+ vec![target.prerequisites.first().cloned().unwrap_or_default()]
} else if macro_name.starts_with('*') {
// The $* macro shall evaluate to the current target name with
// its suffix deleted. (GNUism: the match stem)
diff --git a/src/makefile/target.rs b/src/makefile/target.rs
index c3431e4..d6fac2c 100644
--- a/src/makefile/target.rs
+++ b/src/makefile/target.rs
@@ -22,7 +22,7 @@ pub struct Target {
}
impl Target {
- pub fn extend(&mut self, other: Target) {
+ pub fn extend(&mut self, other: Self) {
assert_eq!(&self.name, &other.name);
match (self.commands.is_empty(), other.commands.is_empty()) {
(false, false) => {
@@ -154,9 +154,9 @@ impl StaticTargetSet {
}
}
-impl Into<HashMap<String, Target>> for StaticTargetSet {
- fn into(self) -> HashMap<String, Target> {
- self.data
+impl From<StaticTargetSet> for HashMap<String, Target> {
+ fn from(value: StaticTargetSet) -> Self {
+ value.data
}
}
@@ -168,7 +168,7 @@ pub struct DynamicTargetSet {
impl DynamicTargetSet {
pub fn get(&self, name: &str) -> Option<Rc<RefCell<Target>>> {
- self.data.borrow().get(name).map(|x| Rc::clone(x))
+ self.data.borrow().get(name).map(Rc::clone)
}
pub fn put(&self, target: Target) {
diff --git a/src/makefile/token.rs b/src/makefile/token.rs
index 418baf5..396380b 100644
--- a/src/makefile/token.rs
+++ b/src/makefile/token.rs
@@ -128,7 +128,7 @@ impl TokenString {
}
pub fn is_empty(&self) -> bool {
- match self.0.get(0) {
+ match self.0.first() {
None => true,
Some(Token::Text(t)) if t.is_empty() && self.0.len() == 1 => true,
_ => false,