Skip to content

Commit c7610c4

Browse files
committed
well, separate function is not required when it comes to triggering lifetime-related compiler errors
1 parent ced8f3b commit c7610c4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/nla.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,6 @@ mod tests {
375375
assert_eq!(nla_align!(get_len() - 3), usize::MAX);
376376
}
377377

378-
// compile-time test: it should be possible to pass &[u8] through
379-
// NlasIterator and return one of its output &[u8]s without facing
380-
// compiler error about lifetimes and returning borrows from something
381-
// that this funciton owns
382-
fn last_nla_from_buffer(nlas: &[u8]) -> Option<Result<&[u8], DecodeError>> {
383-
NlasIterator::new(nlas).last()
384-
.map(|nla| nla.map(|nla| nla.value()))
385-
}
386-
387378
#[test]
388379
fn test_nlas_iterator() {
389380
// sample NFTA_LIST_ELEM from nftables, with nested nlas at the end
@@ -404,6 +395,16 @@ mod tests {
404395

405396
// this sholud be an Err()
406397
let truncated = &NESTED_NLAS[ .. NESTED_NLAS.len()-1];
407-
assert!(last_nla_from_buffer(truncated).unwrap().is_err());
398+
assert!(NlasIterator::new(truncated).last().unwrap().is_err());
399+
400+
let last = {
401+
// it should be possible to pass &[u8] through
402+
// NlasIterator and return one of its output &[u8]s without facing
403+
// compiler error about lifetimes and returning borrows from
404+
// something is limited to this scope
405+
let last = NlasIterator::new(NESTED_NLAS).last();
406+
last.unwrap().unwrap().value()
407+
};
408+
assert_eq!(last, &NESTED_NLAS[16..]);
408409
}
409410
}

0 commit comments

Comments
 (0)