mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +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 mut all_declarations_definitely_reachable = true;
|
||||||
|
|
||||||
let types = declarations.filter_map(
|
let mut types = declarations.filter_map(
|
||||||
|DeclarationWithConstraint {
|
|DeclarationWithConstraint {
|
||||||
declaration,
|
declaration,
|
||||||
reachability_constraint,
|
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() {
|
if !conflicting.is_empty() {
|
||||||
let mut builder = DeclaredTypeBuilder::new(db);
|
return Err((union, conflicting));
|
||||||
for element in types {
|
}
|
||||||
builder.add(element);
|
|
||||||
}
|
|
||||||
let (declared, conflicting) = builder.build();
|
|
||||||
|
|
||||||
if !conflicting.is_empty() {
|
union
|
||||||
return Err((declared, conflicting));
|
} else {
|
||||||
}
|
first
|
||||||
|
};
|
||||||
|
|
||||||
let boundness = match boundness_analysis {
|
let boundness = match boundness_analysis {
|
||||||
BoundnessAnalysis::AssumeBound => {
|
BoundnessAnalysis::AssumeBound => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue