Auto merge of #125070 - tbu-:pr_set_extension_panic, r=jhpratt · model-checking/verify-rust-std@4014081

Original file line numberDiff line numberDiff line change

@@ -1425,6 +1425,11 @@ impl PathBuf {

14251425

/// If `extension` is the empty string, [`self.extension`] will be [`None`]

14261426

/// afterwards, not `Some("")`.

14271427

///

1428+

/// # Panics

1429+

///

1430+

/// Panics if the passed extension contains a path separator (see

1431+

/// [`is_separator`]).

1432+

///

14281433

/// # Caveats

14291434

///

14301435

/// The new `extension` may contain dots and will be used in its entirety,

@@ -1470,6 +1475,14 @@ impl PathBuf {

14701475

}

14711476
14721477

fn _set_extension(&mut self, extension: &OsStr) -> bool {

1478+

for &b in extension.as_encoded_bytes() {

1479+

if b < 128 {

1480+

if is_separator(b as char) {

1481+

panic!("extension cannot contain path separators: {:?}", extension);

1482+

}

1483+

}

1484+

}

1485+
14731486

let file_stem = match self.file_stem() {

14741487

None => return false,

14751488

Some(f) => f.as_encoded_bytes(),