From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#26486: 25.1.91; unused var warning from cconv.el can't be suppressed Date: Mon, 05 Jul 2021 11:29:40 -0400 Message-ID: References: <87mtr0x025.fsf_-_@gnus.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37561"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 26486@debbugs.gnu.org, John Williams , Noam Postavsky To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 05 17:31:04 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m0QYg-000985-FA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 05 Jul 2021 17:30:54 +0200 Original-Received: from localhost ([::1]:51966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0QYf-0007JU-CO for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 05 Jul 2021 11:30:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0QXq-00074C-SS for bug-gnu-emacs@gnu.org; Mon, 05 Jul 2021 11:30:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0QXq-00017p-JZ for bug-gnu-emacs@gnu.org; Mon, 05 Jul 2021 11:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m0QXq-0004Ea-ED for bug-gnu-emacs@gnu.org; Mon, 05 Jul 2021 11:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 05 Jul 2021 15:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26486 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch confirmed moreinfo Original-Received: via spool by 26486-submit@debbugs.gnu.org id=B26486.162549899616242 (code B ref 26486); Mon, 05 Jul 2021 15:30:02 +0000 Original-Received: (at 26486) by debbugs.gnu.org; 5 Jul 2021 15:29:56 +0000 Original-Received: from localhost ([127.0.0.1]:46485 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m0QXk-0004Du-6V for submit@debbugs.gnu.org; Mon, 05 Jul 2021 11:29:56 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:9030) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m0QXh-0004Df-7H for 26486@debbugs.gnu.org; Mon, 05 Jul 2021 11:29:54 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 361AB8090A; Mon, 5 Jul 2021 11:29:47 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 7607180323; Mon, 5 Jul 2021 11:29:41 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1625498981; bh=adHwiM++PNR8aNxWawQer/1+S41XSQnvDImr/DhAu18=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=f7XkYeftgPJudxY476ugdWBjuwVzXgd1GxS/uaSgDAHVZpvFXMys3G9B19Uv5PAmZ gWlsmglKA53f4UbUAiIdRbGm18fGZ22Y2lv7yzMhEmZWNDHUBT2k6P0nBaHPSxKZbP 9Fr0HRwcmdabij1deOjYLmUCTC+xTJL3wEslQLvuuEbCU/oRyTCoCFQ6I4UmTHMcoj wPR/ydMlbfFHzAqm6OKZ4uLiXBMT1Tmxsw+yMauPQZbpLQ4DdR0LH16L0JhlkDT2fy 2sETP/cQkm3yFMjPhPqGZ3fRkmoDqm/0ME421Oli0vmPhsndUOKLcya5RXRbUu8Nmi 2YQ3WfqB7KzKA== Original-Received: from alfajor (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 3D7F2120050; Mon, 5 Jul 2021 11:29:41 -0400 (EDT) In-Reply-To: <87mtr0x025.fsf_-_@gnus.org> (Lars Ingebrigtsen's message of "Mon, 05 Jul 2021 17:17:06 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:209472 Archived-At: Lars Ingebrigtsen [2021-07-05 17:17:06] wrote: > Noam Postavsky writes: > >> This happens also without a macro. >> >> ;; -*- lexical-binding: t; byte-compile-warnings: nil -*- >> (with-no-warnings (let (unused))) > > This currently gives a warning about both an unused variable and an > empty let body. > > The following seemingly straightforward patch fixes both these things, > I'd appreciate it if somebody had a look over it first, though. :-) > (So Stefan M added to the CCs.) [...] > @@ -259,7 +259,8 @@ cconv--warn-unused-msg > (not (intern-soft var)) > (eq ?_ (aref (symbol-name var) 0)) > ;; As a special exception, ignore "ignore". > - (eq var 'ignored)) > + (eq var 'ignored) > + (not (byte-compile-warning-enabled-p 'unbound var))) > (let ((suggestions (help-uni-confusable-suggestions (symbol-name var)))) > (format "Unused lexical %s `%S'%s" > varkind var LGTM, thank you. This said, I suspect that it may fail to correctly heed `with-suppressed-warnings`. More specifically, I think we may want to add a "category" argument to `macroexp-warn-and-return` which is then matched against `byte-compile-warnings` (either directly inside `macroexp-warn-and-return` or within the subsequent handling of `macroexp--funcall-if-compiled`). > diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el > index 70999648d4..d97bc1073b 100644 > --- a/lisp/emacs-lisp/bytecomp.el > +++ b/lisp/emacs-lisp/bytecomp.el > @@ -325,6 +325,7 @@ byte-compile-warnings > docstrings docstrings that are too wide (longer than 80 characters, > or `fill-column', whichever is bigger) > suspicious constructs that usually don't do what the coder wanted. > + empty-body the body of a binding form is empty. > > If the list begins with `not', then the remaining elements specify warnings to > suppress. For example, (not mapcar) will suppress warnings about mapcar." > diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el > index f663710902..f1579cda8b 100644 > --- a/lisp/emacs-lisp/cconv.el > +++ b/lisp/emacs-lisp/cconv.el > diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el > index df864464b7..e9c2eb3fee 100644 > --- a/lisp/emacs-lisp/macroexp.el > +++ b/lisp/emacs-lisp/macroexp.el > @@ -319,14 +319,16 @@ macroexp--expand-all > (`(,(and fun (or 'let 'let*)) . ,(or `(,bindings . ,body) > pcase--dontcare)) > (macroexp--cons fun > - (macroexp--cons (macroexp--all-clauses bindings 1) > - (if (null body) > - (macroexp-unprogn > - (macroexp-warn-and-return > - (format "Empty %s body" fun) > - nil t)) > - (macroexp--all-forms body)) > - (cdr form)) > + (macroexp--cons > + (macroexp--all-clauses bindings 1) > + (if (null body) > + (macroexp-unprogn > + (macroexp-warn-and-return > + (and (byte-compile-warning-enabled-p 'empty-body) > + (format "Empty %s body" fun)) > + nil t)) > + (macroexp--all-forms body)) > + (cdr form)) > form)) > (`(,(and fun `(lambda . ,_)) . ,args) > ;; Embedded lambda in function position. We already discussed the use(ful|less)ness of this empty-body warning, and I don't think it's useful enough to justify adding a new warning category for it. When `byte-compile-warnings` is nil, arguably `macroexp-warn-and-return` should just silence all warnings. Stefan