Skip to content

Commit b82ec64

Browse files
committed
Add non_exhaustive to all public enums that may be extended
1 parent f8e6431 commit b82ec64

File tree

8 files changed

+32
-19
lines changed

8 files changed

+32
-19
lines changed

examples/nm.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,20 @@ fn print_symbol(symbol: &Symbol<'_, '_>, section_kinds: &HashMap<SectionIndex, S
6161
}
6262

6363
let mut kind = match symbol.section() {
64-
SymbolSection::Unknown | SymbolSection::None => '?',
6564
SymbolSection::Undefined => 'U',
6665
SymbolSection::Absolute => 'A',
6766
SymbolSection::Common => 'C',
6867
SymbolSection::Section(index) => match section_kinds.get(&index) {
69-
None
70-
| Some(SectionKind::Unknown)
71-
| Some(SectionKind::Other)
72-
| Some(SectionKind::OtherString)
73-
| Some(SectionKind::Debug)
74-
| Some(SectionKind::Linker)
75-
| Some(SectionKind::Note)
76-
| Some(SectionKind::Metadata)
77-
| Some(SectionKind::Elf(_)) => '?',
7868
Some(SectionKind::Text) => 't',
7969
Some(SectionKind::Data) | Some(SectionKind::Tls) | Some(SectionKind::TlsVariables) => {
8070
'd'
8171
}
8272
Some(SectionKind::ReadOnlyData) | Some(SectionKind::ReadOnlyString) => 'r',
8373
Some(SectionKind::UninitializedData) | Some(SectionKind::UninitializedTls) => 'b',
8474
Some(SectionKind::Common) => 'C',
75+
_ => '?',
8576
},
77+
_ => '?',
8678
};
8779

8880
if symbol.is_global() {

examples/objcopy.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ fn main() {
7878
continue;
7979
}
8080
let (section, value) = match in_symbol.section() {
81-
SymbolSection::Unknown => panic!("unknown symbol section for {:?}", in_symbol),
8281
SymbolSection::None => (write::SymbolSection::None, in_symbol.address()),
8382
SymbolSection::Undefined => (write::SymbolSection::Undefined, in_symbol.address()),
8483
SymbolSection::Absolute => (write::SymbolSection::Absolute, in_symbol.address()),
@@ -95,6 +94,7 @@ fn main() {
9594
continue;
9695
}
9796
}
97+
_ => panic!("unknown symbol section for {:?}", in_symbol),
9898
};
9999
let flags = match in_symbol.flags() {
100100
SymbolFlags::None => SymbolFlags::None,
@@ -111,6 +111,7 @@ fn main() {
111111
associative_section,
112112
}
113113
}
114+
_ => panic!("unknown symbol flags for {:?}", in_symbol),
114115
};
115116
let out_symbol = write::Symbol {
116117
name: in_symbol.name().unwrap_or("").as_bytes().to_vec(),
@@ -133,11 +134,11 @@ fn main() {
133134
let out_section = *out_sections.get(&in_section.index()).unwrap();
134135
for (offset, in_relocation) in in_section.relocations() {
135136
let symbol = match in_relocation.target() {
136-
RelocationTarget::Absolute => unimplemented!(),
137137
RelocationTarget::Symbol(symbol) => *out_symbols.get(&symbol).unwrap(),
138138
RelocationTarget::Section(section) => {
139139
out_object.section_symbol(*out_sections.get(&section).unwrap())
140140
}
141+
_ => panic!("unknown relocation target for {:?}", in_relocation),
141142
};
142143
let out_relocation = write::Relocation {
143144
offset,

examples/readobj.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3695,7 +3695,7 @@ mod macho {
36953695
p.field_hex("Reserved", x.reserved.get(endian));
36963696
});
36973697
}
3698-
LoadCommandVariant::Other => {
3698+
_ => {
36993699
p.group("LoadCommand", |p| {
37003700
p.field_enum("Cmd", command.cmd(), FLAGS_LC);
37013701
p.field_hex("CmdSize", command.cmdsize());

src/common.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/// A CPU architecture.
22
#[allow(missing_docs)]
33
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4+
#[non_exhaustive]
45
pub enum Architecture {
56
Unknown,
67
Aarch64,
78
Arm,
89
I386,
910
Mips,
1011
Mips64,
11-
S390x,
12-
Wasm32,
1312
PowerPc,
1413
PowerPc64,
1514
Riscv32,
1615
Riscv64,
16+
S390x,
17+
Wasm32,
1718
X86_64,
1819
}
1920

@@ -29,13 +30,13 @@ impl Architecture {
2930
Architecture::I386 => Some(AddressSize::U32),
3031
Architecture::Mips => Some(AddressSize::U32),
3132
Architecture::Mips64 => Some(AddressSize::U64),
32-
Architecture::S390x => Some(AddressSize::U64),
33-
Architecture::Wasm32 => Some(AddressSize::U32),
34-
Architecture::X86_64 => Some(AddressSize::U64),
3533
Architecture::PowerPc => Some(AddressSize::U32),
3634
Architecture::PowerPc64 => Some(AddressSize::U64),
37-
Architecture::Riscv64 => Some(AddressSize::U64),
3835
Architecture::Riscv32 => Some(AddressSize::U32),
36+
Architecture::Riscv64 => Some(AddressSize::U64),
37+
Architecture::S390x => Some(AddressSize::U64),
38+
Architecture::Wasm32 => Some(AddressSize::U32),
39+
Architecture::X86_64 => Some(AddressSize::U64),
3940
}
4041
}
4142
}
@@ -45,6 +46,7 @@ impl Architecture {
4546
/// This may differ from the address size supported by the file format (such as for COFF).
4647
#[allow(missing_docs)]
4748
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49+
#[non_exhaustive]
4850
#[repr(u8)]
4951
pub enum AddressSize {
5052
U32 = 4,
@@ -62,6 +64,7 @@ impl AddressSize {
6264
/// A binary file format.
6365
#[allow(missing_docs)]
6466
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
67+
#[non_exhaustive]
6568
pub enum BinaryFormat {
6669
Coff,
6770
Elf,
@@ -72,6 +75,7 @@ pub enum BinaryFormat {
7275

7376
/// The kind of a section.
7477
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
78+
#[non_exhaustive]
7579
pub enum SectionKind {
7680
/// The section kind is unknown.
7781
Unknown,
@@ -170,6 +174,7 @@ impl SectionKind {
170174
/// This determines the way in which the linker resolves multiple definitions of the COMDAT
171175
/// sections.
172176
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
177+
#[non_exhaustive]
173178
pub enum ComdatKind {
174179
/// The selection kind is unknown.
175180
Unknown,
@@ -201,6 +206,7 @@ pub enum ComdatKind {
201206

202207
/// The kind of a symbol.
203208
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
209+
#[non_exhaustive]
204210
pub enum SymbolKind {
205211
/// The symbol kind is unknown.
206212
Unknown,
@@ -249,6 +255,7 @@ pub enum SymbolScope {
249255
///
250256
/// 'XxxRelative' means 'Xxx + A - P'. 'XxxOffset' means 'S + A - Xxx'.
251257
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
258+
#[non_exhaustive]
252259
pub enum RelocationKind {
253260
/// S + A
254261
Absolute,
@@ -288,6 +295,7 @@ pub enum RelocationKind {
288295
/// This is usually architecture specific, such as specifying an addressing mode or
289296
/// a specific instruction.
290297
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
298+
#[non_exhaustive]
291299
pub enum RelocationEncoding {
292300
/// Generic encoding.
293301
Generic,
@@ -317,6 +325,7 @@ pub enum RelocationEncoding {
317325

318326
/// File flags that are specific to each file format.
319327
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
328+
#[non_exhaustive]
320329
pub enum FileFlags {
321330
/// No file flags.
322331
None,
@@ -339,6 +348,7 @@ pub enum FileFlags {
339348

340349
/// Section flags that are specific to each file format.
341350
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
351+
#[non_exhaustive]
342352
pub enum SectionFlags {
343353
/// No section flags.
344354
None,
@@ -361,6 +371,7 @@ pub enum SectionFlags {
361371

362372
/// Symbol flags that are specific to each file format.
363373
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
374+
#[non_exhaustive]
364375
pub enum SymbolFlags<Section> {
365376
/// No symbol flags.
366377
None,

src/read/archive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::read::{self, Error, ReadError, ReadRef};
88
/// The kind of archive format.
99
// TODO: Gnu64 and Darwin64 (and Darwin for writing)
1010
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11+
#[non_exhaustive]
1112
pub enum ArchiveKind {
1213
/// There are no special files that indicate the archive format.
1314
Unknown,

src/read/macho/load_command.rs

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impl<'data, E: Endian> LoadCommandData<'data, E> {
242242

243243
/// A `LoadCommand` that has been interpreted according to its `cmd` field.
244244
#[derive(Debug, Clone, Copy)]
245+
#[non_exhaustive]
245246
pub enum LoadCommandVariant<'data, E: Endian> {
246247
/// `LC_SEGMENT`
247248
Segment32(&'data macho::SegmentCommand32<E>, &'data [u8]),

src/read/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub struct SymbolIndex(pub usize);
233233

234234
/// The section where a symbol is defined.
235235
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
236+
#[non_exhaustive]
236237
pub enum SymbolSection {
237238
/// The section is unknown.
238239
Unknown,
@@ -489,6 +490,7 @@ impl<'data> CodeView<'data> {
489490

490491
/// The target referenced by a relocation.
491492
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
493+
#[non_exhaustive]
492494
pub enum RelocationTarget {
493495
/// The target is a symbol.
494496
Symbol(SymbolIndex),
@@ -558,6 +560,7 @@ impl Relocation {
558560

559561
/// A data compression format.
560562
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
563+
#[non_exhaustive]
561564
pub enum CompressionFormat {
562565
/// The data is uncompressed.
563566
None,

src/write/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ impl Object {
545545
/// A standard segment kind.
546546
#[allow(missing_docs)]
547547
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
548+
#[non_exhaustive]
548549
pub enum StandardSegment {
549550
Text,
550551
Data,
@@ -554,6 +555,7 @@ pub enum StandardSegment {
554555
/// A standard section kind.
555556
#[allow(missing_docs)]
556557
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
558+
#[non_exhaustive]
557559
pub enum StandardSection {
558560
Text,
559561
Data,
@@ -696,6 +698,7 @@ impl Section {
696698

697699
/// The section where a symbol is defined.
698700
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
701+
#[non_exhaustive]
699702
pub enum SymbolSection {
700703
/// The section is not applicable for this symbol (such as file symbols).
701704
None,
@@ -822,6 +825,7 @@ pub struct Comdat {
822825

823826
/// The symbol name mangling scheme.
824827
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
828+
#[non_exhaustive]
825829
pub enum Mangling {
826830
/// No symbol mangling.
827831
None,

0 commit comments

Comments
 (0)