mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
[red-knot] Refactor path.rs
in the module resolver (#12494)
This commit is contained in:
parent
e047b9685a
commit
5ce80827d2
6 changed files with 681 additions and 967 deletions
|
@ -3,6 +3,7 @@
|
|||
// but there's no compile time guarantee that a [`OsSystem`] never gets an untitled file path.
|
||||
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use std::borrow::Borrow;
|
||||
use std::fmt::Formatter;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, StripPrefixError};
|
||||
|
@ -402,6 +403,14 @@ impl SystemPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToOwned for SystemPath {
|
||||
type Owned = SystemPathBuf;
|
||||
|
||||
fn to_owned(&self) -> Self::Owned {
|
||||
self.to_path_buf()
|
||||
}
|
||||
}
|
||||
|
||||
/// An owned, mutable path on [`System`](`super::System`) (akin to [`String`]).
|
||||
///
|
||||
/// The path is guaranteed to be valid UTF-8.
|
||||
|
@ -470,6 +479,12 @@ impl SystemPathBuf {
|
|||
}
|
||||
}
|
||||
|
||||
impl Borrow<SystemPath> for SystemPathBuf {
|
||||
fn borrow(&self) -> &SystemPath {
|
||||
self.as_path()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for SystemPathBuf {
|
||||
fn from(value: &str) -> Self {
|
||||
SystemPathBuf::from_utf8_path_buf(Utf8PathBuf::from(value))
|
||||
|
@ -496,6 +511,20 @@ impl AsRef<SystemPath> for SystemPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRef<SystemPath> for Utf8Path {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &SystemPath {
|
||||
SystemPath::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<SystemPath> for Utf8PathBuf {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &SystemPath {
|
||||
SystemPath::new(self.as_path())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<SystemPath> for str {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &SystemPath {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue