mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 05:20:49 -05:00
[ty] Derive Default in a few more places in place.rs (#22481)
This commit is contained in:
@@ -156,9 +156,10 @@ impl<'db> DefinedPlace<'db> {
|
||||
/// bound_or_declared: Place::Defined(DefinedPlace { ty: Literal[1], origin: TypeOrigin::Inferred, definedness: Definedness::PossiblyUndefined, .. }),
|
||||
/// non_existent: Place::Undefined,
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
|
||||
pub(crate) enum Place<'db> {
|
||||
Defined(DefinedPlace<'db>),
|
||||
#[default]
|
||||
Undefined,
|
||||
}
|
||||
|
||||
@@ -592,6 +593,7 @@ type DeclaredTypeAndConflictingTypes<'db> = (
|
||||
);
|
||||
|
||||
/// The result of looking up a declared type from declarations; see [`place_from_declarations`].
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct PlaceFromDeclarationsResult<'db> {
|
||||
place_and_quals: PlaceAndQualifiers<'db>,
|
||||
conflicting_types: Option<Box<indexmap::set::Slice<Type<'db>>>>,
|
||||
@@ -641,21 +643,12 @@ impl<'db> PlaceFromDeclarationsResult<'db> {
|
||||
/// that this comes with a [`CLASS_VAR`] type qualifier.
|
||||
///
|
||||
/// [`CLASS_VAR`]: crate::types::TypeQualifiers::CLASS_VAR
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
|
||||
#[derive(Debug, Clone, Default, Copy, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
|
||||
pub(crate) struct PlaceAndQualifiers<'db> {
|
||||
pub(crate) place: Place<'db>,
|
||||
pub(crate) qualifiers: TypeQualifiers,
|
||||
}
|
||||
|
||||
impl Default for PlaceAndQualifiers<'_> {
|
||||
fn default() -> Self {
|
||||
PlaceAndQualifiers {
|
||||
place: Place::Undefined,
|
||||
qualifiers: TypeQualifiers::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> PlaceAndQualifiers<'db> {
|
||||
/// Constructor that creates a [`PlaceAndQualifiers`] instance with a [`TodoType`] type
|
||||
/// and no qualifiers.
|
||||
@@ -669,10 +662,7 @@ impl<'db> PlaceAndQualifiers<'db> {
|
||||
}
|
||||
|
||||
pub(crate) fn unbound() -> Self {
|
||||
PlaceAndQualifiers {
|
||||
place: Place::Undefined,
|
||||
qualifiers: TypeQualifiers::empty(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub(crate) fn is_undefined(&self) -> bool {
|
||||
@@ -1567,11 +1557,7 @@ fn place_from_declarations_impl<'db>(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PlaceFromDeclarationsResult {
|
||||
place_and_quals: Place::Undefined.into(),
|
||||
conflicting_types: None,
|
||||
first_declaration: None,
|
||||
}
|
||||
PlaceFromDeclarationsResult::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1893,7 +1879,7 @@ mod tests {
|
||||
let ty1 = Type::IntLiteral(1);
|
||||
let ty2 = Type::IntLiteral(2);
|
||||
|
||||
let unbound = || Place::Undefined.with_qualifiers(TypeQualifiers::empty());
|
||||
let unbound = || PlaceAndQualifiers::default();
|
||||
|
||||
let possibly_unbound_ty1 = || {
|
||||
Place::Defined(DefinedPlace {
|
||||
|
||||
@@ -3479,7 +3479,7 @@ impl<'db> ClassLiteral<'db> {
|
||||
}
|
||||
|
||||
if union.is_empty() {
|
||||
Place::Undefined.with_qualifiers(TypeQualifiers::empty())
|
||||
PlaceAndQualifiers::default()
|
||||
} else {
|
||||
let boundness = if is_definitely_bound {
|
||||
Definedness::AlwaysDefined
|
||||
|
||||
@@ -1800,12 +1800,11 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||
.index
|
||||
.place_table(scope)
|
||||
.place(declaration.place(self.db()));
|
||||
if let PlaceExprRef::Symbol(symbol) = &place {
|
||||
if scope.is_global() {
|
||||
module_type_implicit_global_symbol(self.db(), symbol.name())
|
||||
} else {
|
||||
Place::Undefined.into()
|
||||
}
|
||||
|
||||
if let PlaceExprRef::Symbol(symbol) = &place
|
||||
&& scope.is_global()
|
||||
{
|
||||
module_type_implicit_global_symbol(self.db(), symbol.name())
|
||||
} else {
|
||||
Place::Undefined.into()
|
||||
}
|
||||
@@ -9704,7 +9703,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||
}
|
||||
}
|
||||
|
||||
PlaceAndQualifiers::from(Place::Undefined)
|
||||
PlaceAndQualifiers::default()
|
||||
// If we're in a class body, check for implicit class body symbols first.
|
||||
// These take precedence over globals.
|
||||
.or_fall_back_to(db, || {
|
||||
|
||||
Reference in New Issue
Block a user