GNU bug report logs - #26486
25.1.91; unused var warning from cconv.el can't be suppressed

Previous Next

Package: emacs;

Reported by: John Williams <jrw <at> pobox.com>

Date: Thu, 13 Apr 2017 19:13:01 UTC

Severity: minor

Tags: confirmed, moreinfo, patch

Found in versions 28.0.50, 25.1.91

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #26 received at 26486 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 26486 <at> debbugs.gnu.org, John Williams <jrw <at> pobox.com>,
 Noam Postavsky <npostavs <at> users.sourceforge.net>
Subject: Re: bug#26486: 25.1.91; unused var warning from cconv.el can't be
 suppressed
Date: Mon, 05 Jul 2021 11:29:40 -0400
Lars Ingebrigtsen [2021-07-05 17:17:06] wrote:

> Noam Postavsky <npostavs <at> 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





This bug report was last modified 4 years and 39 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.