mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Merge pull request #2952 from rtfeldman/ability-unused-method-reporting
Ability unused method reporting
This commit is contained in:
commit
e736adaa24
3 changed files with 7 additions and 72 deletions
|
@ -203,7 +203,7 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
env: &mut Env<'a>,
|
||||
mut output: Output,
|
||||
var_store: &mut VarStore,
|
||||
original_scope: &Scope,
|
||||
mut scope: Scope,
|
||||
loc_defs: &'a [&'a Loc<ast::Def<'a>>],
|
||||
pattern_type: PatternType,
|
||||
) -> (CanDefs, Scope, Output, MutMap<Symbol, Region>) {
|
||||
|
@ -224,30 +224,19 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
// This naturally handles recursion too, because a given expr which refers
|
||||
// to itself won't be processed until after its def has been added to scope.
|
||||
|
||||
// Record both the original and final idents from the scope,
|
||||
// so we can diff them while detecting unused defs.
|
||||
let mut scope = original_scope.clone();
|
||||
let num_defs = loc_defs.len();
|
||||
|
||||
let mut type_defs = Vec::with_capacity(num_defs);
|
||||
let mut pending_type_defs = Vec::with_capacity(num_defs);
|
||||
let mut value_defs = Vec::with_capacity(num_defs);
|
||||
|
||||
for loc_def in loc_defs {
|
||||
match loc_def.value.unroll_def() {
|
||||
Ok(type_def) => type_defs.push(Loc::at(loc_def.region, type_def)),
|
||||
Ok(type_def) => {
|
||||
pending_type_defs.push(to_pending_type_def(env, type_def, &mut scope, pattern_type))
|
||||
}
|
||||
Err(value_def) => value_defs.push(Loc::at(loc_def.region, value_def)),
|
||||
}
|
||||
}
|
||||
|
||||
// We need to canonicalize all the type defs first.
|
||||
// Clippy is wrong - we do need the collect, otherwise "env" and "scope" are captured for
|
||||
// longer than we'd like.
|
||||
#[allow(clippy::needless_collect)]
|
||||
let pending_type_defs = type_defs
|
||||
.into_iter()
|
||||
.map(|loc_def| to_pending_type_def(env, loc_def.value, &mut scope, pattern_type))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
env.home.register_debug_idents(&env.ident_ids);
|
||||
}
|
||||
|
@ -452,7 +441,6 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
&mut output,
|
||||
var_store,
|
||||
&mut scope,
|
||||
&mut symbols_introduced,
|
||||
abilities,
|
||||
&abilities_in_scope,
|
||||
pattern_type,
|
||||
|
@ -554,7 +542,6 @@ fn resolve_abilities<'a>(
|
|||
output: &mut Output,
|
||||
var_store: &mut VarStore,
|
||||
scope: &mut Scope,
|
||||
symbols_introduced: &mut MutMap<Symbol, Region>,
|
||||
abilities: MutMap<Symbol, (Loc<Symbol>, &[AbilityMember])>,
|
||||
abilities_in_scope: &[Symbol],
|
||||
pattern_type: PatternType,
|
||||
|
@ -598,8 +585,6 @@ fn resolve_abilities<'a>(
|
|||
}
|
||||
};
|
||||
|
||||
symbols_introduced.insert(member_sym, name_region);
|
||||
|
||||
if pattern_type == PatternType::TopLevelDef {
|
||||
env.top_level_symbols.insert(member_sym);
|
||||
}
|
||||
|
@ -1402,7 +1387,7 @@ pub fn can_defs_with_return<'a>(
|
|||
env,
|
||||
Output::default(),
|
||||
var_store,
|
||||
&scope,
|
||||
scope,
|
||||
loc_defs,
|
||||
PatternType::DefExpr,
|
||||
);
|
||||
|
|
|
@ -289,7 +289,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
&mut env,
|
||||
Output::default(),
|
||||
var_store,
|
||||
&scope,
|
||||
scope,
|
||||
&desugared,
|
||||
PatternType::TopLevelDef,
|
||||
);
|
||||
|
|
|
@ -9203,16 +9203,6 @@ I need all branches in an `if` to have the same type!
|
|||
| a has Ability
|
||||
|
||||
at the end of the type.
|
||||
|
||||
── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
`ab` is not used anywhere in your code.
|
||||
|
||||
3│ Ability has ab : a -> {} | a has Ability
|
||||
^^
|
||||
|
||||
If you didn't intend on using `ab` then remove it so future readers of
|
||||
your code don't wonder why it is there.
|
||||
"#
|
||||
),
|
||||
)
|
||||
|
@ -9289,16 +9279,6 @@ I need all branches in an `if` to have the same type!
|
|||
|
||||
If you didn't intend on using `Ability` then remove it so future readers
|
||||
of your code don't wonder why it is there.
|
||||
|
||||
── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
`ab` is not used anywhere in your code.
|
||||
|
||||
3│ Ability has ab : {} -> {}
|
||||
^^
|
||||
|
||||
If you didn't intend on using `ab` then remove it so future readers of
|
||||
your code don't wonder why it is there.
|
||||
"#
|
||||
),
|
||||
)
|
||||
|
@ -9330,16 +9310,6 @@ I need all branches in an `if` to have the same type!
|
|||
are a part of.
|
||||
|
||||
Hint: Did you mean to bind the `Hash` ability instead?
|
||||
|
||||
── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
`hash` is not used anywhere in your code.
|
||||
|
||||
4│ Hash has hash : a, b -> Num.U64 | a has Eq, b has Hash
|
||||
^^^^
|
||||
|
||||
If you didn't intend on using `hash` then remove it so future readers of
|
||||
your code don't wonder why it is there.
|
||||
"#
|
||||
),
|
||||
)
|
||||
|
@ -9371,16 +9341,6 @@ I need all branches in an `if` to have the same type!
|
|||
looking at specializations!
|
||||
|
||||
Hint: Did you mean to only bind `a` to `Eq`?
|
||||
|
||||
── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
`eq` is not used anywhere in your code.
|
||||
|
||||
3│ Eq has eq : a, b -> Bool.Bool | a has Eq, b has Eq
|
||||
^^
|
||||
|
||||
If you didn't intend on using `eq` then remove it so future readers of
|
||||
your code don't wonder why it is there.
|
||||
"#
|
||||
),
|
||||
)
|
||||
|
@ -9424,16 +9384,6 @@ I need all branches in an `if` to have the same type!
|
|||
a has Hash
|
||||
|
||||
Otherwise, the function does not need to be part of the ability!
|
||||
|
||||
── UNUSED DEFINITION ───────────────────────────────────── /code/proj/Main.roc ─
|
||||
|
||||
`hash` is not used anywhere in your code.
|
||||
|
||||
3│ Hash has hash : (a | a has Hash) -> Num.U64
|
||||
^^^^
|
||||
|
||||
If you didn't intend on using `hash` then remove it so future readers of
|
||||
your code don't wonder why it is there.
|
||||
"#
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue