Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize std::path::Prefix::is_verbatim as const #76232

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,20 @@ impl<'a> Prefix<'a> {
/// assert!(!Disk(b'C').is_verbatim());
/// ```
#[inline]
#[rustc_const_stable(feature = "const_path_prefix", since = "1.48.0")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_verbatim(&self) -> bool {
pub const fn is_verbatim(&self) -> bool {
use self::Prefix::*;
matches!(*self, Verbatim(_) | VerbatimDisk(_) | VerbatimUNC(..))
}

#[inline]
fn is_drive(&self) -> bool {
const fn is_drive(&self) -> bool {
matches!(*self, Prefix::Disk(_))
}

#[inline]
fn has_implicit_root(&self) -> bool {
const fn has_implicit_root(&self) -> bool {
!self.is_drive()
}
}
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/path/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,3 +1392,13 @@ fn into_rc() {
assert_eq!(&*rc2, path);
assert_eq!(&*arc2, path);
}

#[test]
fn prefix_const() {
// test that the methods of `Prefix` are usable in a const context

const PREFIX: Prefix<'_> = Prefix::Disk(2);

const IS_VERBATIM: bool = PREFIX.is_verbatim();
assert!(!IS_VERBATIM);
}