mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
Add a few missing #[return_ref]
attributes (#13223)
This commit is contained in:
parent
54df960a4a
commit
599103c933
5 changed files with 11 additions and 7 deletions
|
@ -361,6 +361,7 @@ impl<'db> Type<'db> {
|
|||
#[salsa::interned]
|
||||
pub struct FunctionType<'db> {
|
||||
/// name of the function at definition
|
||||
#[return_ref]
|
||||
pub name: ast::name::Name,
|
||||
|
||||
definition: Definition<'db>,
|
||||
|
@ -408,6 +409,7 @@ impl<'db> FunctionType<'db> {
|
|||
#[salsa::interned]
|
||||
pub struct ClassType<'db> {
|
||||
/// Name of the class at definition
|
||||
#[return_ref]
|
||||
pub name: ast::name::Name,
|
||||
|
||||
definition: Definition<'db>,
|
||||
|
@ -464,6 +466,7 @@ impl<'db> ClassType<'db> {
|
|||
#[salsa::interned]
|
||||
pub struct UnionType<'db> {
|
||||
/// The union type includes values in any of these types.
|
||||
#[return_ref]
|
||||
elements: FxOrderSet<Type<'db>>,
|
||||
}
|
||||
|
||||
|
@ -476,6 +479,7 @@ impl<'db> UnionType<'db> {
|
|||
#[salsa::interned]
|
||||
pub struct IntersectionType<'db> {
|
||||
/// The intersection type includes only values in all of these types.
|
||||
#[return_ref]
|
||||
positive: FxOrderSet<Type<'db>>,
|
||||
|
||||
/// The intersection type does not include any value in any of these types.
|
||||
|
@ -483,6 +487,7 @@ pub struct IntersectionType<'db> {
|
|||
/// Negation types aren't expressible in annotations, and are most likely to arise from type
|
||||
/// narrowing along with intersections (e.g. `if not isinstance(...)`), so we represent them
|
||||
/// directly in intersections rather than as a separate type.
|
||||
#[return_ref]
|
||||
negative: FxOrderSet<Type<'db>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<'db> UnionBuilder<'db> {
|
|||
pub(crate) fn add(mut self, ty: Type<'db>) -> Self {
|
||||
match ty {
|
||||
Type::Union(union) => {
|
||||
self.elements.extend(&union.elements(self.db));
|
||||
self.elements.extend(union.elements(self.db));
|
||||
}
|
||||
Type::Never => {}
|
||||
_ => {
|
||||
|
@ -284,7 +284,7 @@ mod tests {
|
|||
|
||||
impl<'db> UnionType<'db> {
|
||||
fn elements_vec(self, db: &'db TestDb) -> Vec<Type<'db>> {
|
||||
self.elements(db).into_iter().collect()
|
||||
self.elements(db).into_iter().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,11 +389,11 @@ mod tests {
|
|||
|
||||
impl<'db> IntersectionType<'db> {
|
||||
fn pos_vec(self, db: &'db TestDb) -> Vec<Type<'db>> {
|
||||
self.positive(db).into_iter().collect()
|
||||
self.positive(db).into_iter().copied().collect()
|
||||
}
|
||||
|
||||
fn neg_vec(self, db: &'db TestDb) -> Vec<Type<'db>> {
|
||||
self.negative(db).into_iter().collect()
|
||||
self.negative(db).into_iter().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Display for DisplayType<'_> {
|
|||
}
|
||||
// TODO functions and classes should display using a fully qualified name
|
||||
Type::Class(class) => write!(f, "Literal[{}]", class.name(self.db)),
|
||||
Type::Instance(class) => f.write_str(&class.name(self.db)),
|
||||
Type::Instance(class) => f.write_str(class.name(self.db)),
|
||||
Type::Function(function) => write!(f, "Literal[{}]", function.name(self.db)),
|
||||
Type::Union(union) => union.display(self.db).fmt(f),
|
||||
Type::Intersection(intersection) => intersection.display(self.db).fmt(f),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue