mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +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 {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::borrow::Borrow;
|
||||
use std::ops::Deref;
|
||||
use std::path;
|
||||
|
||||
|
@ -23,6 +24,10 @@ impl VendoredPath {
|
|||
self.0.as_str()
|
||||
}
|
||||
|
||||
pub fn as_utf8_path(&self) -> &camino::Utf8Path {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn as_std_path(&self) -> &path::Path {
|
||||
self.0.as_std_path()
|
||||
}
|
||||
|
@ -69,6 +74,14 @@ impl VendoredPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToOwned for VendoredPath {
|
||||
type Owned = VendoredPathBuf;
|
||||
|
||||
fn to_owned(&self) -> VendoredPathBuf {
|
||||
self.to_path_buf()
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
|
||||
pub struct VendoredPathBuf(Utf8PathBuf);
|
||||
|
@ -84,6 +97,7 @@ impl VendoredPathBuf {
|
|||
Self(Utf8PathBuf::new())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_path(&self) -> &VendoredPath {
|
||||
VendoredPath::new(&self.0)
|
||||
}
|
||||
|
@ -93,6 +107,12 @@ impl VendoredPathBuf {
|
|||
}
|
||||
}
|
||||
|
||||
impl Borrow<VendoredPath> for VendoredPathBuf {
|
||||
fn borrow(&self) -> &VendoredPath {
|
||||
self.as_path()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<VendoredPath> for VendoredPathBuf {
|
||||
fn as_ref(&self) -> &VendoredPath {
|
||||
self.as_path()
|
||||
|
@ -106,6 +126,20 @@ impl AsRef<VendoredPath> for VendoredPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRef<VendoredPath> for Utf8Path {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &VendoredPath {
|
||||
VendoredPath::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<VendoredPath> for Utf8PathBuf {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &VendoredPath {
|
||||
VendoredPath::new(self.as_path())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<VendoredPath> for str {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &VendoredPath {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue