mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
factor out to separate function
This commit is contained in:
parent
fe72008845
commit
66676e0ab9
1 changed files with 27 additions and 21 deletions
|
@ -1551,6 +1551,32 @@ fn debug_print_ir(state: &State, flag: &str) {
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Report modules that are imported, but from which nothing is used
|
||||||
|
fn report_unused_imported_modules<'a>(
|
||||||
|
state: &mut State<'a>,
|
||||||
|
module_id: ModuleId,
|
||||||
|
constrained_module: &ConstrainedModule,
|
||||||
|
) {
|
||||||
|
let mut unused_imported_modules = constrained_module.imported_modules.clone();
|
||||||
|
|
||||||
|
for symbol in constrained_module.module.referenced_values.iter() {
|
||||||
|
unused_imported_modules.remove(&symbol.module_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
for symbol in constrained_module.module.referenced_types.iter() {
|
||||||
|
unused_imported_modules.remove(&symbol.module_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
let existing = match state.module_cache.can_problems.entry(module_id) {
|
||||||
|
Vacant(entry) => entry.insert(std::vec::Vec::new()),
|
||||||
|
Occupied(entry) => entry.into_mut(),
|
||||||
|
};
|
||||||
|
|
||||||
|
for (unused, region) in unused_imported_modules.drain() {
|
||||||
|
existing.push(roc_problem::can::Problem::UnusedImport(unused, region));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update<'a>(
|
fn update<'a>(
|
||||||
mut state: State<'a>,
|
mut state: State<'a>,
|
||||||
msg: Msg<'a>,
|
msg: Msg<'a>,
|
||||||
|
@ -1728,27 +1754,7 @@ fn update<'a>(
|
||||||
state.module_cache.documentation.insert(module_id, docs);
|
state.module_cache.documentation.insert(module_id, docs);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
report_unused_imported_modules(&mut state, module_id, &constrained_module);
|
||||||
// see if there are imported modules from which nothing is actually used
|
|
||||||
let mut unused_imported_modules = constrained_module.imported_modules.clone();
|
|
||||||
|
|
||||||
for symbol in constrained_module.module.referenced_values.iter() {
|
|
||||||
unused_imported_modules.remove(&symbol.module_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
for symbol in constrained_module.module.referenced_types.iter() {
|
|
||||||
unused_imported_modules.remove(&symbol.module_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
let existing = match state.module_cache.can_problems.entry(module_id) {
|
|
||||||
Vacant(entry) => entry.insert(std::vec::Vec::new()),
|
|
||||||
Occupied(entry) => entry.into_mut(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for (unused, region) in unused_imported_modules.drain() {
|
|
||||||
existing.push(roc_problem::can::Problem::UnusedImport(unused, region));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
state
|
state
|
||||||
.module_cache
|
.module_cache
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue