From 403df4ab203f77094627824c1a20c3fb633f4f56 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Sun, 6 Oct 2019 17:25:14 -0500 Subject: [PATCH] Deprecate let%lwt at the structure item level --- src/ppx/ppx_lwt.ml | 10 +++++++++- test/ppx_expect/cases/run_1.expect | 3 +++ test/ppx_expect/cases/run_1.ml | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ppx/ppx_lwt.ml b/src/ppx/ppx_lwt.ml index 74af739e89..4d996460dd 100644 --- a/src/ppx/ppx_lwt.ml +++ b/src/ppx/ppx_lwt.ml @@ -465,7 +465,15 @@ let mapper = default_loc := stri.pstr_loc; match stri with | [%stri let%lwt [%p? var] = [%e? exp]] -> - [%stri let [%p var] = Lwt_main.run [%e mapper.expr mapper exp]] + let warning = + str + ("let%lwt should not be used at the module item level.\n" ^ + "Replace let%lwt x = e by let x = Lwt_main.run (e)") + in + [%stri + let [%p var] = + (Lwt_main.run [@ocaml.ppwarning [%e warning]]) + [%e mapper.expr mapper exp]] [@metaloc !default_loc] | x -> default_mapper.structure_item mapper x); diff --git a/test/ppx_expect/cases/run_1.expect b/test/ppx_expect/cases/run_1.expect index e69de29bb2..e406a70a00 100644 --- a/test/ppx_expect/cases/run_1.expect +++ b/test/ppx_expect/cases/run_1.expect @@ -0,0 +1,3 @@ +File "run_1.ml", line 2, characters 0-26: +Warning 22: let%lwt should not be used at the module item level. +Replace let%lwt x = e by let x = Lwt_main.run (e) diff --git a/test/ppx_expect/cases/run_1.ml b/test/ppx_expect/cases/run_1.ml index 405ff9425e..11f9c72889 100644 --- a/test/ppx_expect/cases/run_1.ml +++ b/test/ppx_expect/cases/run_1.ml @@ -1,2 +1,2 @@ -let%lwt () = - Lwt.return () +(* On one line for error message compatibility with 4.09. *) +let%lwt () = Lwt.return ()