mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 00:20:38 +00:00
Re-order some code in scope.rs (#4255)
This commit is contained in:
parent
a9fc648faf
commit
cd27b39aff
1 changed files with 35 additions and 35 deletions
|
@ -104,41 +104,6 @@ impl<'a> Scope<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Id uniquely identifying a scope in a program.
|
||||
///
|
||||
/// Using a `u32` is sufficient because Ruff only supports parsing documents with a size of max `u32::max`
|
||||
/// and it is impossible to have more scopes than characters in the file (because defining a function or class
|
||||
/// requires more than one character).
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub struct ScopeId(u32);
|
||||
|
||||
impl ScopeId {
|
||||
/// Returns the ID for the global scope
|
||||
#[inline]
|
||||
pub const fn global() -> Self {
|
||||
ScopeId(0)
|
||||
}
|
||||
|
||||
/// Returns `true` if this is the id of the global scope
|
||||
pub const fn is_global(&self) -> bool {
|
||||
self.0 == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<usize> for ScopeId {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
fn try_from(value: usize) -> Result<Self, Self::Error> {
|
||||
Ok(Self(u32::try_from(value)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ScopeId> for usize {
|
||||
fn from(value: ScopeId) -> Self {
|
||||
value.0 as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, is_macro::Is)]
|
||||
pub enum ScopeKind<'a> {
|
||||
Class(ClassDef<'a>),
|
||||
|
@ -181,6 +146,41 @@ pub struct Lambda<'a> {
|
|||
pub body: &'a Expr,
|
||||
}
|
||||
|
||||
/// Id uniquely identifying a scope in a program.
|
||||
///
|
||||
/// Using a `u32` is sufficient because Ruff only supports parsing documents with a size of max `u32::max`
|
||||
/// and it is impossible to have more scopes than characters in the file (because defining a function or class
|
||||
/// requires more than one character).
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub struct ScopeId(u32);
|
||||
|
||||
impl ScopeId {
|
||||
/// Returns the ID for the global scope
|
||||
#[inline]
|
||||
pub const fn global() -> Self {
|
||||
ScopeId(0)
|
||||
}
|
||||
|
||||
/// Returns `true` if this is the id of the global scope
|
||||
pub const fn is_global(&self) -> bool {
|
||||
self.0 == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<usize> for ScopeId {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
fn try_from(value: usize) -> Result<Self, Self::Error> {
|
||||
Ok(Self(u32::try_from(value)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ScopeId> for usize {
|
||||
fn from(value: ScopeId) -> Self {
|
||||
value.0 as usize
|
||||
}
|
||||
}
|
||||
|
||||
/// The scopes of a program indexed by [`ScopeId`]
|
||||
#[derive(Debug)]
|
||||
pub struct Scopes<'a>(Vec<Scope<'a>>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue