diff --git a/library/std/src/path.rs b/library/std/src/path.rs index d71e89d0eee68..26909ede0c7da 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -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() } } diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index ff94fda5a227b..bf512ac674096 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -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); +}