Skip to content

Commit aeedd7e

Browse files
committed
Use the counted_array macro for the ARGS arrays
One of the most annoying thing from using static arrays in rust is that there is no size inference, and you end up having to give the proper size. Which makes updates to the arrays cumbersome. I was reading "This Week in Rust 252", which linked to (RFC: Elide array size)[rust-lang/rfcs#2545], set to address this very problem, and @durka linked to his counted-arrays crate, which already existed and essentially implements the idea behind the RFC.
1 parent dda88a6 commit aeedd7e

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ byteorder = "1.0"
2929
bytes = "0.4"
3030
chrono = { version = "0.4", optional = true }
3131
clap = "2.23.0"
32+
counted-array = "0.1"
3233
directories = "1"
3334
env_logger = "0.5"
3435
error-chain = { version = "0.12", default-features = false }

src/compiler/clang.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl CCompilerImpl for Clang {
8181
}
8282
}
8383

84-
pub static ARGS: [ArgInfo<gcc::ArgData>; 10] = [
84+
counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
8585
take_arg!("--serialize-diagnostics", OsString, Separated, PassThrough),
8686
take_arg!("--target", OsString, Separated, PassThrough),
8787
// TODO: should be extracted and reprocessed, though bear in mind some
@@ -95,7 +95,7 @@ pub static ARGS: [ArgInfo<gcc::ArgData>; 10] = [
9595
take_arg!("-gcc-toolchain", OsString, Separated, PassThrough),
9696
take_arg!("-include-pch", PathBuf, CanBeSeparated, PreprocessorArgumentPath),
9797
take_arg!("-target", OsString, Separated, PassThrough),
98-
];
98+
]);
9999

100100
#[cfg(test)]
101101
mod test {

src/compiler/gcc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ArgData!{ pub
9797
use self::ArgData::*;
9898

9999
// Mostly taken from https://github.com/ccache/ccache/blob/master/src/compopt.c#L32-L84
100-
pub static ARGS: [ArgInfo<ArgData>; 65] = [
100+
counted_array!(pub static ARGS: [ArgInfo<ArgData>; _] = [
101101
flag!("-", TooHardFlag),
102102
flag!("--coverage", Coverage),
103103
take_arg!("--param", OsString, Separated, PassThrough),
@@ -163,7 +163,7 @@ pub static ARGS: [ArgInfo<ArgData>; 65] = [
163163
take_arg!("-u", OsString, CanBeSeparated, PassThrough),
164164
take_arg!("-x", OsString, CanBeSeparated, Language),
165165
take_arg!("@", OsString, Concatenated, TooHard),
166-
];
166+
]);
167167

168168
/// Parse `arguments`, determining whether it is supported.
169169
///

src/compiler/msvc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ ArgData!{
219219

220220
use self::ArgData::*;
221221

222-
static ARGS: [ArgInfo<ArgData>; 23] = [
222+
counted_array!(static ARGS: [ArgInfo<ArgData>; _] = [
223223
take_arg!("-D", OsString, Concatenated, PreprocessorArgument),
224224
take_arg!("-FA", OsString, Concatenated, TooHard),
225225
take_arg!("-FI", PathBuf, CanBeSeparated, PreprocessorArgumentPath),
@@ -243,7 +243,7 @@ static ARGS: [ArgInfo<ArgData>; 23] = [
243243
take_arg!("-o", PathBuf, Separated, Output), // Deprecated but valid
244244
flag!("-showIncludes", ShowIncludes),
245245
take_arg!("@", PathBuf, Concatenated, TooHardPath),
246-
];
246+
]);
247247

248248
pub fn parse_arguments(arguments: &[OsString], cwd: &Path, is_clang: bool) -> CompilerArguments<ParsedArguments> {
249249
let mut output_arg = None;

src/compiler/rust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ ArgData!{
576576
use self::ArgData::*;
577577

578578
// These are taken from https://github.com/rust-lang/rust/blob/b671c32ddc8c36d50866428d83b7716233356721/src/librustc/session/config.rs#L1186
579-
static ARGS: [ArgInfo<ArgData>; 33] = [
579+
counted_array!(static ARGS: [ArgInfo<ArgData>; _] = [
580580
flag!("-", TooHardFlag),
581581
take_arg!("--allow", OsString, CanBeSeparated('='), PassThrough),
582582
take_arg!("--cap-lints", OsString, CanBeSeparated('='), PassThrough),
@@ -610,7 +610,7 @@ static ARGS: [ArgInfo<ArgData>; 33] = [
610610
take_arg!("-Z", OsString, CanBeSeparated, PassThrough),
611611
take_arg!("-l", ArgLinkLibrary, CanBeSeparated, LinkLibrary),
612612
take_arg!("-o", PathBuf, CanBeSeparated, TooHardPath),
613-
];
613+
]);
614614

615615
fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<ParsedArguments>
616616
{

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern crate bytes;
2525
extern crate chrono;
2626
#[macro_use]
2727
extern crate clap;
28+
#[macro_use]
29+
extern crate counted_array;
2830
#[cfg(feature = "rust-crypto")]
2931
extern crate crypto;
3032
#[cfg(unix)]

0 commit comments

Comments
 (0)