Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify infer.rs/report_mismatch using early return #615

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl UnificationContext {
.iter()
.find(|(_, m)| **m == m2 || self.resolve(**m) == m2)
.map(|a| a.0);
let err = if let (Some((node1, dir1)), Some((node2, dir2))) = (loc1, loc2) {
if let (Some((node1, dir1)), Some((node2, dir2))) = (loc1, loc2) {
// N.B. We're looking for the case where an equality constraint
// arose because the two locations are connected by an edge

Expand All @@ -392,43 +392,35 @@ impl UnificationContext {
[(node2, rs2.clone()), (node1, rs1.clone())]
};

if src_rs.is_subset(&tgt_rs) {
Some(InferExtensionError::EdgeMismatch(
ExtensionError::TgtExceedsSrcExtensions {
from: *src,
from_extensions: src_rs,
to: *tgt,
to_extensions: tgt_rs,
},
))
return InferExtensionError::EdgeMismatch(if src_rs.is_subset(&tgt_rs) {
ExtensionError::TgtExceedsSrcExtensions {
from: *src,
from_extensions: src_rs,
to: *tgt,
to_extensions: tgt_rs,
}
} else {
Some(InferExtensionError::EdgeMismatch(
ExtensionError::SrcExceedsTgtExtensions {
from: *src,
from_extensions: src_rs,
to: *tgt,
to_extensions: tgt_rs,
},
))
}
} else {
None
ExtensionError::SrcExceedsTgtExtensions {
from: *src,
from_extensions: src_rs,
to: *tgt,
to_extensions: tgt_rs,
}
});
}
} else {
None
};
}
if let (Some(loc1), Some(loc2)) = (loc1, loc2) {
err.unwrap_or(InferExtensionError::MismatchedConcreteWithLocations {
InferExtensionError::MismatchedConcreteWithLocations {
expected_loc: *loc1,
expected: rs1,
actual_loc: *loc2,
actual: rs2,
})
}
} else {
err.unwrap_or(InferExtensionError::MismatchedConcrete {
InferExtensionError::MismatchedConcrete {
expected: rs1,
actual: rs2,
})
}
}
}

Expand Down