@@ -398,14 +398,23 @@ pub fn lint_level(
398
398
}
399
399
}
400
400
401
- // Finally, run `decorate`. This is guarded by a `can_emit_warnings()` check so that any
402
- // `def_path_str` called within `decorate` won't trigger a `must_produce_diag` ICE if the
403
- // `err` isn't eventually emitted (e.g. due to `-A warnings`). If an `err` is force-warn,
404
- // it's going to be emitted anyway.
405
- if matches ! ( err_level, rustc_errors:: Level :: ForceWarning ( _) )
406
- || sess. dcx ( ) . can_emit_warnings ( )
401
+ // Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly),
402
+ // so we need to make sure when we do call `decorate` that the diagnostic is eventually
403
+ // emitted or we'll get a `must_produce_diag` ICE.
404
+ //
405
+ // When is a diagnostic *eventually* emitted? Well, that is determined by 2 factors:
406
+ // 1. If the corresponding `rustc_errors::Level` is beyond warning, i.e. `ForceWarning(_)`
407
+ // or `Error`, then the diagnostic will be emitted regardless of CLI options.
408
+ // 2. If the corresponding `rustc_errors::Level` is warning, then that can be affected by
409
+ // `-A warnings` or `--cap-lints=xxx` on the command line. In which case, the diagnostic
410
+ // will be emitted if `can_emit_warnings` is true.
407
411
{
408
- decorate ( & mut err) ;
412
+ use rustc_errors:: Level as ELevel ;
413
+ if matches ! ( err_level, ELevel :: ForceWarning ( _) | ELevel :: Error )
414
+ || sess. dcx ( ) . can_emit_warnings ( )
415
+ {
416
+ decorate ( & mut err) ;
417
+ }
409
418
}
410
419
411
420
explain_lint_level_source ( lint, level, src, & mut err) ;
0 commit comments