stop scope diffing in when canonicalization

This commit is contained in:
Folkert 2022-04-27 17:57:42 +02:00
parent 984ef53e75
commit 2d0a9c8531
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 17 additions and 24 deletions

View file

@ -1099,23 +1099,17 @@ fn canonicalize_when_branch<'a>(
}
};
// Now that we've collected all the references for this branch, check to see if
// any of the new idents it defined were unused. If any were, report it.
for (symbol, region) in scope.symbols() {
let symbol = *symbol;
if !output.references.has_type_or_value_lookup(symbol)
&& !branch_output.references.has_type_or_value_lookup(symbol)
&& !original_scope.contains_symbol(symbol)
&& !scope.abilities_store.is_specialization_name(symbol)
{
env.problem(Problem::UnusedDef(symbol, *region));
}
}
let references = branch_output.references.clone();
output.union(branch_output);
// Now that we've collected all the references for this branch, check to see if
// any of the new idents it defined were unused. If any were, report it.
for (symbol, region) in bindings_from_patterns(patterns.iter()) {
if !output.references.has_value_lookup(symbol) {
env.problem(Problem::UnusedDef(symbol, region));
}
}
(
WhenBranch {
patterns,

View file

@ -687,12 +687,15 @@ fn add_bindings_from_patterns(
add_bindings_from_patterns(&loc_arg.region, &loc_arg.value, answer);
}
RecordDestructure { destructs, .. } => {
for Loc {
region,
value: RecordDestruct { symbol, .. },
} in destructs
{
answer.push((*symbol, *region));
for loc_destruct in destructs {
match loc_destruct.value.typ {
DestructType::Required | DestructType::Optional(_, _) => {
answer.push((loc_destruct.value.symbol, loc_destruct.region));
}
DestructType::Guard(_, _) => {
// a guard does not introduce the symbol
}
}
}
}
NumLiteral(..)

View file

@ -104,10 +104,6 @@ impl Scope {
self.idents.contains_key(ident)
}
pub fn contains_symbol(&self, symbol: Symbol) -> bool {
self.symbols.contains_key(&symbol)
}
pub fn num_idents(&self) -> usize {
self.idents.len()
}