mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-18 11:41:21 +00:00
[ty] Use CompactStr for StringLiteralType (#21497)
This commit is contained in:
parent
d9fc0f08b4
commit
58fa1d71b6
2 changed files with 5 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use compact_str::{CompactString, ToCompactString};
|
||||
use infer::nearest_enclosing_class;
|
||||
use itertools::{Either, Itertools};
|
||||
use ruff_db::parsed::parsed_module;
|
||||
|
|
@ -7497,7 +7498,7 @@ impl<'db> Type<'db> {
|
|||
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
|
||||
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
|
||||
db,
|
||||
known_instance.repr(db).to_string().into_boxed_str(),
|
||||
known_instance.repr(db).to_compact_string(),
|
||||
)),
|
||||
// TODO: handle more complex types
|
||||
_ => KnownClass::Str.to_instance(db),
|
||||
|
|
@ -7519,7 +7520,7 @@ impl<'db> Type<'db> {
|
|||
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
|
||||
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
|
||||
db,
|
||||
known_instance.repr(db).to_string().into_boxed_str(),
|
||||
known_instance.repr(db).to_compact_string(),
|
||||
)),
|
||||
// TODO: handle more complex types
|
||||
_ => KnownClass::Str.to_instance(db),
|
||||
|
|
@ -12388,7 +12389,7 @@ impl<'db> IntersectionType<'db> {
|
|||
#[derive(PartialOrd, Ord)]
|
||||
pub struct StringLiteralType<'db> {
|
||||
#[returns(deref)]
|
||||
value: Box<str>,
|
||||
value: CompactString,
|
||||
}
|
||||
|
||||
// The Salsa heap is tracked separately.
|
||||
|
|
|
|||
|
|
@ -436,7 +436,7 @@ where
|
|||
.with_failure_code(server::ErrorCode::InternalError)
|
||||
}
|
||||
|
||||
/// Sends back a response to the server, but only if the request wasn't cancelled.
|
||||
/// Sends back a response to the client, but only if the request wasn't cancelled.
|
||||
fn respond<Req>(
|
||||
id: &RequestId,
|
||||
result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue