Skip to content

Commit be35407

Browse files
committed
Fix a panic uncovered during testing
`occupied_entry()` is documented as being for a specific use case of mutating the flags for the *key*, using `occupied_entry()` with `insert` runs afoul of this by assuming it can also return a value previously associated with the key. This is a case where the header's valueless key API doesn't coincide very well with the existing `std::collections` entry API. In a sense `Header` can be occupied with a key *without* any associated value. While for the `std::collections` entry API the existence of a key implies the existence of a value. This fixes the problematic usage of the API, but it would be good to revisit the non_standard `occupied_entry()` function, and try to make another API that is more misuse resistent such as perhaps `key_entry` which allows you to modify the flags associated with a key, but doesn't assume the existence of a value.
1 parent 483f3e0 commit be35407

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

nimbleparse/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ fn main() {
141141
};
142142
let entry = match header.entry("yacckind".to_string()) {
143143
Entry::Occupied(_) => unreachable!("Header should be empty"),
144-
Entry::Vacant(v) => v.occupied_entry(),
144+
Entry::Vacant(v) => v,
145145
};
146146
match matches.opt_str("y") {
147147
None => {}
148148
Some(s) => {
149-
entry.insert(HeaderValue(
149+
entry.insert_entry(HeaderValue(
150150
Location::CommandLine,
151151
Value::try_from(match &*s.to_lowercase() {
152152
"eco" => YaccKind::Eco,

0 commit comments

Comments
 (0)