diff --git a/bin/main.ml b/bin/main.ml index 7bbd6711..29dd8144 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -181,9 +181,10 @@ let find_root () = List.fold_left l ~init:max_int ~f:(fun acc (prio, _, _) -> min acc prio) in - match List.find l ~f:(fun (prio, _, _) -> prio = lowest_priority) with - | None -> assert false - | Some (_, dir, to_cwd) -> (dir, to_cwd) + let (_, dir, to_cwd) = + List.find_exn l ~f:(fun (prio, _, _) -> prio = lowest_priority) + in + (dir, to_cwd) let package_name = Arg.conv ((fun p -> Ok (Package.Name.of_string p)), Package.Name.pp) @@ -896,11 +897,7 @@ let external_lib_deps = in if only_missing then begin let context = - match - List.find setup.contexts ~f:(fun c -> c.name = context_name) - with - | None -> assert false - | Some c -> c + List.find_exn setup.contexts ~f:(fun c -> c.name = context_name) in let missing = String.Map.filteri externals ~f:(fun name _ -> diff --git a/src/build_system.ml b/src/build_system.ml index 05653005..b49b7e1d 100644 --- a/src/build_system.ml +++ b/src/build_system.ml @@ -160,9 +160,9 @@ module Internal_rule = struct last_requested_file :: acc else let requested_file, rev_dep = - Option.value_exn - (List.find t.rev_deps ~f:(fun (_, t) -> - Id.Set.mem t.transitive_rev_deps last.id)) + List.find_exn + t.rev_deps + ~f:(fun (_, t) -> Id.Set.mem t.transitive_rev_deps last.id) in build_loop (requested_file :: acc) rev_dep in diff --git a/src/stdune/list.ml b/src/stdune/list.ml index 2cc7655a..c24031c3 100644 --- a/src/stdune/list.ml +++ b/src/stdune/list.ml @@ -77,6 +77,11 @@ let rec find l ~f = | [] -> None | x :: l -> if f x then Some x else find l ~f +let find_exn l ~f = + match find l ~f with + | Some x -> x + | None -> invalid_arg "List.find_exn" + let rec last = function | [] -> None | [x] -> Some x diff --git a/src/stdune/list.mli b/src/stdune/list.mli index 3e310f4a..6aa7dcd6 100644 --- a/src/stdune/list.mli +++ b/src/stdune/list.mli @@ -28,6 +28,7 @@ val rev_filter_partition_map -> 'b t * 'c t val find : 'a t -> f:('a -> bool ) -> 'a option +val find_exn : 'a t -> f:('a -> bool ) -> 'a val find_map : 'a t -> f:('a -> 'b option) -> 'b option val last : 'a t -> 'a option