@@ -331,18 +331,27 @@ suppress. For example, (not mapcar) will suppress warnings about mapcar."
331
331
,@(mapcar (lambda (x ) `(const , x ))
332
332
byte-compile-warning-types))))
333
333
334
+ (defvar byte-compile--suppressed-warnings nil
335
+ " Dynamically bound by `with-suppressed-warnings' to suppress warnings." )
336
+
334
337
;;;### autoload
335
338
(put 'byte-compile-warnings 'safe-local-variable
336
339
(lambda (v )
337
340
(or (symbolp v)
338
341
(null (delq nil (mapcar (lambda (x ) (not (symbolp x))) v))))))
339
342
340
- (defun byte-compile-warning-enabled-p (warning )
343
+ (defun byte-compile-warning-enabled-p (warning &optional symbol )
341
344
" Return non-nil if WARNING is enabled, according to `byte-compile-warnings' ."
342
- (or (eq byte-compile-warnings t )
343
- (if (eq (car byte-compile-warnings) 'not )
344
- (not (memq warning byte-compile-warnings))
345
- (memq warning byte-compile-warnings))))
345
+ (let ((suppress nil ))
346
+ (dolist (elem byte-compile--suppressed-warnings)
347
+ (when (and (eq (car elem) warning )
348
+ (memq symbol (cdr elem)))
349
+ (setq suppress t )))
350
+ (and (not suppress)
351
+ (or (eq byte-compile-warnings t )
352
+ (if (eq (car byte-compile-warnings) 'not )
353
+ (not (memq warning byte-compile-warnings))
354
+ (memq warning byte-compile-warnings))))))
346
355
347
356
;;;### autoload
348
357
(defun byte-compile-disable-warning (warning )
@@ -502,7 +511,16 @@ Return the compile-time value of FORM."
502
511
form
503
512
macroexpand-all-environment)))
504
513
(eval expanded lexical-binding)
505
- expanded))))))
514
+ expanded)))))
515
+ (with-suppressed-warnings
516
+ . ,(lambda (warnings &rest body )
517
+ ; ; This function doesn't exist, but is just a placeholder
518
+ ; ; symbol to hook up with the
519
+ ; ; `byte-hunk-handler'/`byte-defop-compiler-1' machinery.
520
+ `(internal--with-suppressed-warnings
521
+ ', warnings
522
+ ,(macroexpand-all `(progn ,@body )
523
+ macroexpand-all-environment)))))
506
524
" The default macro-environment passed to macroexpand by the compiler.
507
525
Placing a macro here will cause a macro to have different semantics when
508
526
expanded by the compiler as when expanded by the interpreter." )
@@ -1268,7 +1286,7 @@ function directly; use `byte-compile-warn' or
1268
1286
1269
1287
(defun byte-compile-warn-obsolete (symbol )
1270
1288
" Warn that SYMBOL (a variable or function) is obsolete."
1271
- (when (byte-compile-warning-enabled-p 'obsolete )
1289
+ (when (byte-compile-warning-enabled-p 'obsolete symbol )
1272
1290
(let* ((funcp (get symbol 'byte-obsolete-info ))
1273
1291
(msg (macroexp--obsolete-warning
1274
1292
symbol
@@ -2423,7 +2441,7 @@ list that represents a doc string reference.
2423
2441
(defun byte-compile--declare-var (sym )
2424
2442
(when (and (symbolp sym)
2425
2443
(not (string-match " [-*/:$]" (symbol-name sym)))
2426
- (byte-compile-warning-enabled-p 'lexical ))
2444
+ (byte-compile-warning-enabled-p 'lexical sym ))
2427
2445
(byte-compile-warn " global/dynamic var `%s' lacks a prefix"
2428
2446
sym))
2429
2447
(when (memq sym byte-compile-lexical-variables)
@@ -2521,6 +2539,15 @@ list that represents a doc string reference.
2521
2539
(mapc 'byte-compile-file-form (cdr form))
2522
2540
nil ))
2523
2541
2542
+ (put 'internal--with-suppressed-warnings 'byte-hunk-handler
2543
+ 'byte-compile-file-form-with-suppressed-warnings )
2544
+ (defun byte-compile-file-form-with-suppressed-warnings (form )
2545
+ ; ; cf byte-compile-file-form-progn.
2546
+ (let ((byte-compile--suppressed-warnings
2547
+ (append (cadadr form) byte-compile--suppressed-warnings)))
2548
+ (mapc 'byte-compile-file-form (cddr form))
2549
+ nil ))
2550
+
2524
2551
; ; Automatically evaluate define-obsolete-function-alias etc at top-level.
2525
2552
(put 'make-obsolete 'byte-hunk-handler 'byte-compile-file-form-make-obsolete )
2526
2553
(defun byte-compile-file-form-make-obsolete (form )
@@ -2559,7 +2586,7 @@ not to take responsibility for the actual compilation of the code."
2559
2586
(setq byte-compile-call-tree
2560
2587
(cons (list name nil nil ) byte-compile-call-tree))))
2561
2588
2562
- (if (byte-compile-warning-enabled-p 'redefine )
2589
+ (if (byte-compile-warning-enabled-p 'redefine name )
2563
2590
(byte-compile-arglist-warn name arglist macro))
2564
2591
2565
2592
(if byte-compile-verbose
@@ -2571,15 +2598,15 @@ not to take responsibility for the actual compilation of the code."
2571
2598
; ; This also silences "multiple definition" warnings for defmethods.
2572
2599
nil )
2573
2600
(that-one
2574
- (if (and (byte-compile-warning-enabled-p 'redefine )
2601
+ (if (and (byte-compile-warning-enabled-p 'redefine name )
2575
2602
; ; Don't warn when compiling the stubs in byte-run...
2576
2603
(not (assq name byte-compile-initial-macro-environment)))
2577
2604
(byte-compile-warn
2578
2605
" `%s' defined multiple times, as both function and macro"
2579
2606
name))
2580
2607
(setcdr that-one nil ))
2581
2608
(this-one
2582
- (when (and (byte-compile-warning-enabled-p 'redefine )
2609
+ (when (and (byte-compile-warning-enabled-p 'redefine name )
2583
2610
; ; Hack: Don't warn when compiling the magic internal
2584
2611
; ; byte-compiler macros in byte-run.el...
2585
2612
(not (assq name byte-compile-initial-macro-environment)))
@@ -2588,7 +2615,7 @@ not to take responsibility for the actual compilation of the code."
2588
2615
name)))
2589
2616
((eq (car-safe (symbol-function name))
2590
2617
(if macro 'lambda 'macro ))
2591
- (when (byte-compile-warning-enabled-p 'redefine )
2618
+ (when (byte-compile-warning-enabled-p 'redefine name )
2592
2619
(byte-compile-warn " %s `%s' being redefined as a %s"
2593
2620
(if macro " function" " macro" )
2594
2621
name
@@ -3153,7 +3180,7 @@ for symbols generated by the byte compiler itself."
3153
3180
(when (and (byte-compile-warning-enabled-p 'suspicious )
3154
3181
(macroexp--const-symbol-p fn))
3155
3182
(byte-compile-warn " `%s' called as a function" fn))
3156
- (when (and (byte-compile-warning-enabled-p 'interactive-only )
3183
+ (when (and (byte-compile-warning-enabled-p 'interactive-only fn )
3157
3184
interactive-only)
3158
3185
(byte-compile-warn " `%s' is for interactive use only%s"
3159
3186
fn
@@ -3194,8 +3221,8 @@ for symbols generated by the byte compiler itself."
3194
3221
(byte-compile-discard ))))
3195
3222
3196
3223
(defun byte-compile-normal-call (form )
3197
- (when (and (byte-compile-warning-enabled-p 'callargs )
3198
- (symbolp (car form)))
3224
+ (when (and (symbolp ( car form) )
3225
+ (byte-compile-warning-enabled-p 'callargs (car form)))
3199
3226
(if (memq (car form)
3200
3227
'(custom-declare-group custom-declare-variable
3201
3228
custom-declare-face))
@@ -3204,7 +3231,7 @@ for symbols generated by the byte compiler itself."
3204
3231
(if byte-compile-generate-call-tree
3205
3232
(byte-compile-annotate-call-tree form))
3206
3233
(when (and byte-compile--for-effect (eq (car form) 'mapcar )
3207
- (byte-compile-warning-enabled-p 'mapcar ))
3234
+ (byte-compile-warning-enabled-p 'mapcar 'mapcar ))
3208
3235
(byte-compile-set-symbol-position 'mapcar )
3209
3236
(byte-compile-warn
3210
3237
" `mapcar' called for effect; use `mapc' or `dolist' instead" ))
@@ -3340,7 +3367,8 @@ for symbols generated by the byte compiler itself."
3340
3367
(when (symbolp var)
3341
3368
(byte-compile-set-symbol-position var))
3342
3369
(cond ((or (not (symbolp var)) (macroexp--const-symbol-p var))
3343
- (when (byte-compile-warning-enabled-p 'constants )
3370
+ (when (byte-compile-warning-enabled-p 'constants
3371
+ (and (symbolp var) var))
3344
3372
(byte-compile-warn (if (eq access-type 'let-bind )
3345
3373
" attempt to let-bind %s `%s' "
3346
3374
" variable reference to %s `%s' " )
@@ -3377,7 +3405,7 @@ for symbols generated by the byte compiler itself."
3377
3405
; ; VAR is lexically bound
3378
3406
(byte-compile-stack-ref (cdr lex-binding))
3379
3407
; ; VAR is dynamically bound
3380
- (unless (or (not (byte-compile-warning-enabled-p 'free-vars ))
3408
+ (unless (or (not (byte-compile-warning-enabled-p 'free-vars var ))
3381
3409
(boundp var)
3382
3410
(memq var byte-compile-bound-variables)
3383
3411
(memq var byte-compile-free-references))
@@ -3393,7 +3421,7 @@ for symbols generated by the byte compiler itself."
3393
3421
; ; VAR is lexically bound.
3394
3422
(byte-compile-stack-set (cdr lex-binding))
3395
3423
; ; VAR is dynamically bound.
3396
- (unless (or (not (byte-compile-warning-enabled-p 'free-vars ))
3424
+ (unless (or (not (byte-compile-warning-enabled-p 'free-vars var ))
3397
3425
(boundp var)
3398
3426
(memq var byte-compile-bound-variables)
3399
3427
(memq var byte-compile-free-assignments))
@@ -3878,7 +3906,7 @@ discarding."
3878
3906
(defun byte-compile-function-form (form )
3879
3907
(let ((f (nth 1 form)))
3880
3908
(when (and (symbolp f)
3881
- (byte-compile-warning-enabled-p 'callargs ))
3909
+ (byte-compile-warning-enabled-p 'callargs f ))
3882
3910
(byte-compile-function-warn f t (byte-compile-fdefinition f nil )))
3883
3911
3884
3912
(byte-compile-constant (if (eq 'lambda (car-safe f))
@@ -3948,7 +3976,8 @@ discarding."
3948
3976
(let ((var (car-safe (cdr varexp))))
3949
3977
(and (or (not (symbolp var))
3950
3978
(macroexp--const-symbol-p var t ))
3951
- (byte-compile-warning-enabled-p 'constants )
3979
+ (byte-compile-warning-enabled-p 'constants
3980
+ (and (symbolp var) var))
3952
3981
(byte-compile-warn
3953
3982
" variable assignment to %s `%s' "
3954
3983
(if (symbolp var) " constant" " nonvariable" )
@@ -4609,7 +4638,7 @@ binding slots have been popped."
4609
4638
4610
4639
(defun byte-compile-save-excursion (form )
4611
4640
(if (and (eq 'set-buffer (car-safe (car-safe (cdr form))))
4612
- (byte-compile-warning-enabled-p 'suspicious ))
4641
+ (byte-compile-warning-enabled-p 'suspicious 'set-buffer ))
4613
4642
(byte-compile-warn
4614
4643
" Use `with-current-buffer' rather than save-excursion+set-buffer" ))
4615
4644
(byte-compile-out 'byte-save-excursion 0 )
@@ -4650,7 +4679,7 @@ binding slots have been popped."
4650
4679
; ; This is not used for file-level defvar/consts.
4651
4680
(when (and (symbolp (nth 1 form))
4652
4681
(not (string-match " [-*/:$]" (symbol-name (nth 1 form))))
4653
- (byte-compile-warning-enabled-p 'lexical ))
4682
+ (byte-compile-warning-enabled-p 'lexical ( nth 1 form) ))
4654
4683
(byte-compile-warn " global/dynamic var `%s' lacks a prefix"
4655
4684
(nth 1 form)))
4656
4685
(let ((fun (nth 0 form))
@@ -4767,6 +4796,13 @@ binding slots have been popped."
4767
4796
(let (byte-compile-warnings)
4768
4797
(byte-compile-form (cons 'progn (cdr form)))))
4769
4798
4799
+ (byte-defop-compiler-1 internal--with-suppressed-warnings
4800
+ byte-compile-suppressed-warnings)
4801
+ (defun byte-compile-suppressed-warnings (form )
4802
+ (let ((byte-compile--suppressed-warnings
4803
+ (append (cadadr form) byte-compile--suppressed-warnings)))
4804
+ (byte-compile-form (macroexp-progn (cddr form)))))
4805
+
4770
4806
; ; Warn about misuses of make-variable-buffer-local.
4771
4807
(byte-defop-compiler-1 make-variable-buffer-local
4772
4808
byte-compile-make-variable-buffer-local)
0 commit comments