@@ -568,7 +568,7 @@ impl<'a> DoubleEndedIterator for Values<'a> {
568
568
impl < ' a > ExactSizeIterator for Values < ' a > { }
569
569
570
570
/// Creates an empty iterator.
571
- impl Default for Values < ' static > {
571
+ impl < ' a > Default for Values < ' a > {
572
572
fn default ( ) -> Self {
573
573
static EMPTY : [ OsString ; 0 ] = [ ] ;
574
574
// This is never called because the iterator is empty:
@@ -583,6 +583,13 @@ fn test_default_values() {
583
583
assert_eq ! ( values. next( ) , None ) ;
584
584
}
585
585
586
+ #[ test]
587
+ fn test_default_values_with_shorter_lifetime ( ) {
588
+ let matches = ArgMatches :: new ( ) ;
589
+ let mut values = matches. values_of ( "" ) . unwrap_or_default ( ) ;
590
+ assert_eq ! ( values. next( ) , None ) ;
591
+ }
592
+
586
593
/// An iterator for getting multiple values out of an argument via the [`ArgMatches::values_of_os`]
587
594
/// method. Usage of this iterator allows values which contain invalid UTF-8 code points unlike
588
595
/// [`Values`].
@@ -622,7 +629,7 @@ impl<'a> DoubleEndedIterator for OsValues<'a> {
622
629
}
623
630
624
631
/// Creates an empty iterator.
625
- impl Default for OsValues < ' static > {
632
+ impl < ' a > Default for OsValues < ' a > {
626
633
fn default ( ) -> Self {
627
634
static EMPTY : [ OsString ; 0 ] = [ ] ;
628
635
// This is never called because the iterator is empty:
@@ -636,3 +643,10 @@ fn test_default_osvalues() {
636
643
let mut values: OsValues = OsValues :: default ( ) ;
637
644
assert_eq ! ( values. next( ) , None ) ;
638
645
}
646
+
647
+ #[ test]
648
+ fn test_default_osvalues_with_shorter_lifetime ( ) {
649
+ let matches = ArgMatches :: new ( ) ;
650
+ let mut values = matches. values_of_os ( "" ) . unwrap_or_default ( ) ;
651
+ assert_eq ! ( values. next( ) , None ) ;
652
+ }
0 commit comments