unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 26486@debbugs.gnu.org, John Williams <jrw@pobox.com>,
	Noam Postavsky <npostavs@users.sourceforge.net>
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	[thread overview]
Message-ID: <jwvczrwyedo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87mtr0x025.fsf_-_@gnus.org> (Lars Ingebrigtsen's message of "Mon, 05 Jul 2021 17:17:06 +0200")

Lars Ingebrigtsen [2021-07-05 17:17:06] wrote:

> Noam Postavsky <npostavs@users.sourceforge.net> 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






  reply	other threads:[~2021-07-05 15:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 18:59 bug#26486: 25.1.91; spurious warnings from cconv.el John Williams
2017-04-13 19:28 ` Noam Postavsky
2021-07-05 15:17   ` bug#26486: 25.1.91; unused var warning from cconv.el can't be suppressed Lars Ingebrigtsen
2021-07-05 15:29     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-07-06 14:48       ` Lars Ingebrigtsen
2021-07-06 19:53     ` Basil L. Contovounesios
2021-07-06 20:03       ` Lars Ingebrigtsen
2021-07-06 20:04         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvczrwyedo.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=26486@debbugs.gnu.org \
    --cc=jrw@pobox.com \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=npostavs@users.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).