From dfee65882b6ec7b8af15fcbbdde076de15cfbde3 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 3 Sep 2024 15:02:50 +0100 Subject: [PATCH] [red-knot] Inline `Type::is_literal` (#13230) --- crates/red_knot_python_semantic/src/types.rs | 13 ------------- .../red_knot_python_semantic/src/types/display.rs | 10 +++++++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs index 5673b628a2..e39b82b9fe 100644 --- a/crates/red_knot_python_semantic/src/types.rs +++ b/crates/red_knot_python_semantic/src/types.rs @@ -220,19 +220,6 @@ impl<'db> Type<'db> { matches!(self, Type::Never) } - /// Returns `true` if this type should be displayed as a literal value. - pub const fn is_literal(&self) -> bool { - matches!( - self, - Type::IntLiteral(_) - | Type::BooleanLiteral(_) - | Type::StringLiteral(_) - | Type::BytesLiteral(_) - | Type::Class(_) - | Type::Function(_) - ) - } - pub const fn into_class_type(self) -> Option> { match self { Type::Class(class_type) => Some(class_type), diff --git a/crates/red_knot_python_semantic/src/types/display.rs b/crates/red_knot_python_semantic/src/types/display.rs index 542eaea29b..8b27f1a197 100644 --- a/crates/red_knot_python_semantic/src/types/display.rs +++ b/crates/red_knot_python_semantic/src/types/display.rs @@ -27,7 +27,15 @@ pub struct DisplayType<'db> { impl Display for DisplayType<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let representation = self.ty.representation(self.db); - if self.ty.is_literal() { + if matches!( + self.ty, + Type::IntLiteral(_) + | Type::BooleanLiteral(_) + | Type::StringLiteral(_) + | Type::BytesLiteral(_) + | Type::Class(_) + | Type::Function(_) + ) { write!(f, "Literal[{representation}]",) } else { representation.fmt(f)