mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[ty] Prevent union builder construction for just one declaration (#18954)
## Summary Avoid the construction of the `DeclaredTypeBuilder` if there is just one declared type.
This commit is contained in:
parent
b01003f81d
commit
c0beb3412f
1 changed files with 17 additions and 11 deletions
|
@ -1120,7 +1120,7 @@ fn place_from_declarations_impl<'db>(
|
|||
|
||||
let mut all_declarations_definitely_reachable = true;
|
||||
|
||||
let types = declarations.filter_map(
|
||||
let mut types = declarations.filter_map(
|
||||
|DeclarationWithConstraint {
|
||||
declaration,
|
||||
reachability_constraint,
|
||||
|
@ -1147,18 +1147,24 @@ fn place_from_declarations_impl<'db>(
|
|||
},
|
||||
);
|
||||
|
||||
let mut types = types.peekable();
|
||||
if let Some(first) = types.next() {
|
||||
let declared = if let Some(second) = types.next() {
|
||||
let mut builder = DeclaredTypeBuilder::new(db);
|
||||
builder.add(first);
|
||||
builder.add(second);
|
||||
for element in types {
|
||||
builder.add(element);
|
||||
}
|
||||
let (union, conflicting) = builder.build();
|
||||
|
||||
if types.peek().is_some() {
|
||||
let mut builder = DeclaredTypeBuilder::new(db);
|
||||
for element in types {
|
||||
builder.add(element);
|
||||
}
|
||||
let (declared, conflicting) = builder.build();
|
||||
if !conflicting.is_empty() {
|
||||
return Err((union, conflicting));
|
||||
}
|
||||
|
||||
if !conflicting.is_empty() {
|
||||
return Err((declared, conflicting));
|
||||
}
|
||||
union
|
||||
} else {
|
||||
first
|
||||
};
|
||||
|
||||
let boundness = match boundness_analysis {
|
||||
BoundnessAnalysis::AssumeBound => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue