Skip to content

Commit 0d7dd0b

Browse files
committed
unused value declarations
1 parent 6f4dcdb commit 0d7dd0b

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

compiler/ext/warnings.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,6 @@ let message = function
380380
"this pattern-matching is not exhaustive.\n\
381381
All clauses in this pattern-matching are guarded."
382382
| Unused_var v | Unused_var_strict v ->
383-
(* TODO(actions) Prefix with `_` *)
384-
(* TODO(actions) Remove variable *)
385383
Format.sprintf
386384
"unused variable %s.\n\n\
387385
Fix this by:\n\
@@ -397,9 +395,7 @@ let message = function
397395
| Duplicate_definitions (kind, cname, tc1, tc2) ->
398396
Printf.sprintf "the %s %s is defined in both types %s and %s." kind cname
399397
tc1 tc2
400-
| Unused_value_declaration v ->
401-
(* TODO(actions) Remove value declaration *)
402-
"unused value " ^ v ^ "."
398+
| Unused_value_declaration v -> "unused value " ^ v ^ "."
403399
| Unused_open s -> "unused open " ^ s ^ "."
404400
| Unused_type_declaration s ->
405401
(* TODO(actions) Remove type declaration *)

compiler/ml/cmt_utils.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type action_type =
1414
| PrefixVariableWithUnderscore
1515
| RemoveUnusedVariable
1616

17+
(* TODO:
18+
- Unused var in patterns (and aliases )*)
19+
1720
type cmt_action = {loc: Location.t; action: action_type; description: string}
1821

1922
let action_to_string = function
@@ -53,7 +56,7 @@ let emit_possible_actions_from_warning loc w =
5356
| Unused_match | Unreachable_case ->
5457
add_possible_action
5558
{loc; action = RemoveSwitchCase; description = "Remove switch case"}
56-
| Unused_var _ | Unused_var_strict _ ->
59+
| Unused_var _ | Unused_var_strict _ | Unused_value_declaration _ ->
5760
add_possible_action
5861
{
5962
loc;

compiler/ml/typedecl.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,6 @@ let transl_value_decl env loc valdecl =
19061906
in
19071907
let id, newenv =
19081908
Env.enter_value valdecl.pval_name.txt v env ~check:(fun s ->
1909-
(* TODO(actions) Remove unused value or prefix with underscore *)
19101909
Warnings.Unused_value_declaration s)
19111910
in
19121911
let desc =
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// actionFilter=RemoveUnusedVariable
2+
module M: {} = {}
3+
4+
/* === AVAILABLE ACTIONS:
5+
- RemoveUnusedVariable - Remove unused variable
6+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// actionFilter=RemoveUnusedVariable
2+
module M: {} = {
3+
let x = 12
4+
}

tools/src/tools.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,14 @@ module Actions = struct
13181318
| None -> Some str_item)
13191319
| _ -> Some str_item)
13201320
in
1321-
Ast_mapper.default_mapper.structure mapper items);
1321+
let items = Ast_mapper.default_mapper.structure mapper items in
1322+
1323+
(* Cleanup if needed *)
1324+
items
1325+
|> List.filter_map (fun (str_item : Parsetree.structure_item) ->
1326+
match str_item.pstr_desc with
1327+
| Pstr_value (_, []) -> None
1328+
| _ -> Some str_item));
13221329
value_bindings =
13231330
(fun mapper bindings ->
13241331
let remove_unused_variables_action_locs =

0 commit comments

Comments
 (0)