@@ -422,6 +422,7 @@ impl<'a> PrefixComponent<'a> {
422
422
/// See [`Prefix`]'s documentation for more information on the different
423
423
/// kinds of prefixes.
424
424
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
425
+ #[ must_use]
425
426
#[ inline]
426
427
pub fn kind ( & self ) -> Prefix < ' a > {
427
428
self . parsed
@@ -583,6 +584,7 @@ impl AsRef<Path> for Component<'_> {
583
584
///
584
585
/// [`components`]: Path::components
585
586
#[ derive( Clone ) ]
587
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
586
588
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
587
589
pub struct Components < ' a > {
588
590
// The path left to parse components from
@@ -609,6 +611,7 @@ pub struct Components<'a> {
609
611
///
610
612
/// [`iter`]: Path::iter
611
613
#[ derive( Clone ) ]
614
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
612
615
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
613
616
pub struct Iter < ' a > {
614
617
inner : Components < ' a > ,
@@ -1051,6 +1054,7 @@ fn compare_components(mut left: Components<'_>, mut right: Components<'_>) -> cm
1051
1054
///
1052
1055
/// [`ancestors`]: Path::ancestors
1053
1056
#[ derive( Copy , Clone , Debug ) ]
1057
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1054
1058
#[ stable( feature = "path_ancestors" , since = "1.28.0" ) ]
1055
1059
pub struct Ancestors < ' a > {
1056
1060
next : Option < & ' a Path > ,
@@ -1459,6 +1463,7 @@ impl PathBuf {
1459
1463
///
1460
1464
/// [`capacity`]: OsString::capacity
1461
1465
#[ stable( feature = "path_buf_capacity" , since = "1.44.0" ) ]
1466
+ #[ must_use]
1462
1467
#[ inline]
1463
1468
pub fn capacity ( & self ) -> usize {
1464
1469
self . inner . capacity ( )
@@ -2103,6 +2108,7 @@ impl Path {
2103
2108
/// assert_eq!(grand_parent.parent(), None);
2104
2109
/// ```
2105
2110
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2111
+ #[ must_use]
2106
2112
pub fn parent ( & self ) -> Option < & Path > {
2107
2113
let mut comps = self . components ( ) ;
2108
2114
let comp = comps. next_back ( ) ;
@@ -2169,6 +2175,7 @@ impl Path {
2169
2175
/// assert_eq!(None, Path::new("/").file_name());
2170
2176
/// ```
2171
2177
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2178
+ #[ must_use]
2172
2179
pub fn file_name ( & self ) -> Option < & OsStr > {
2173
2180
self . components ( ) . next_back ( ) . and_then ( |p| match p {
2174
2181
Component :: Normal ( p) => Some ( p) ,
@@ -2241,6 +2248,7 @@ impl Path {
2241
2248
/// assert!(!Path::new("/etc/foo.rs").starts_with("/etc/foo"));
2242
2249
/// ```
2243
2250
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2251
+ #[ must_use]
2244
2252
pub fn starts_with < P : AsRef < Path > > ( & self , base : P ) -> bool {
2245
2253
self . _starts_with ( base. as_ref ( ) )
2246
2254
}
@@ -2268,6 +2276,7 @@ impl Path {
2268
2276
/// assert!(!path.ends_with("conf")); // use .extension() instead
2269
2277
/// ```
2270
2278
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2279
+ #[ must_use]
2271
2280
pub fn ends_with < P : AsRef < Path > > ( & self , child : P ) -> bool {
2272
2281
self . _ends_with ( child. as_ref ( ) )
2273
2282
}
@@ -2303,6 +2312,7 @@ impl Path {
2303
2312
/// [`Path::file_prefix`]: Path::file_prefix
2304
2313
///
2305
2314
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2315
+ #[ must_use]
2306
2316
pub fn file_stem ( & self ) -> Option < & OsStr > {
2307
2317
self . file_name ( ) . map ( rsplit_file_at_dot) . and_then ( |( before, after) | before. or ( after) )
2308
2318
}
@@ -2336,6 +2346,7 @@ impl Path {
2336
2346
/// [`Path::file_stem`]: Path::file_stem
2337
2347
///
2338
2348
#[ unstable( feature = "path_file_prefix" , issue = "86319" ) ]
2349
+ #[ must_use]
2339
2350
pub fn file_prefix ( & self ) -> Option < & OsStr > {
2340
2351
self . file_name ( ) . map ( split_file_at_dot) . and_then ( |( before, _after) | Some ( before) )
2341
2352
}
@@ -2360,6 +2371,7 @@ impl Path {
2360
2371
/// assert_eq!("gz", Path::new("foo.tar.gz").extension().unwrap());
2361
2372
/// ```
2362
2373
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2374
+ #[ must_use]
2363
2375
pub fn extension ( & self ) -> Option < & OsStr > {
2364
2376
self . file_name ( ) . map ( rsplit_file_at_dot) . and_then ( |( before, after) | before. and ( after) )
2365
2377
}
@@ -2403,6 +2415,7 @@ impl Path {
2403
2415
/// assert_eq!(path.with_file_name("var"), PathBuf::from("/var"));
2404
2416
/// ```
2405
2417
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2418
+ #[ must_use]
2406
2419
pub fn with_file_name < S : AsRef < OsStr > > ( & self , file_name : S ) -> PathBuf {
2407
2420
self . _with_file_name ( file_name. as_ref ( ) )
2408
2421
}
@@ -2660,6 +2673,7 @@ impl Path {
2660
2673
/// This is a convenience function that coerces errors to false. If you want to
2661
2674
/// check errors, call [`fs::metadata`].
2662
2675
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
2676
+ #[ must_use]
2663
2677
#[ inline]
2664
2678
pub fn exists ( & self ) -> bool {
2665
2679
fs:: metadata ( self ) . is_ok ( )
@@ -2781,6 +2795,7 @@ impl Path {
2781
2795
/// Converts a [`Box<Path>`](Box) into a [`PathBuf`] without copying or
2782
2796
/// allocating.
2783
2797
#[ stable( feature = "into_boxed_path" , since = "1.20.0" ) ]
2798
+ #[ must_use = "`self` will be dropped if the result is not used" ]
2784
2799
pub fn into_path_buf ( self : Box < Path > ) -> PathBuf {
2785
2800
let rw = Box :: into_raw ( self ) as * mut OsStr ;
2786
2801
let inner = unsafe { Box :: from_raw ( rw) } ;
0 commit comments