1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]

use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
use rustc_errors::{add_elided_lifetime_in_path_suggestion, Diag};
use rustc_errors::{Applicability, SuggestionStyle};
use rustc_middle::middle::stability;
use rustc_session::config::ExpectedValues;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::Session;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::BytePos;

const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35;

fn check_cfg_expected_note(
    sess: &Session,
    possibilities: &[Symbol],
    type_: &str,
    name: Option<Symbol>,
    suffix: &str,
) -> String {
    use std::fmt::Write;

    let n_possibilities = if sess.opts.unstable_opts.check_cfg_all_expected {
        possibilities.len()
    } else {
        std::cmp::min(possibilities.len(), MAX_CHECK_CFG_NAMES_OR_VALUES)
    };

    let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
    possibilities.sort();

    let and_more = possibilities.len().saturating_sub(n_possibilities);
    let possibilities = possibilities[..n_possibilities].join("`, `");

    let mut note = String::with_capacity(50 + possibilities.len());

    write!(&mut note, "expected {type_}").unwrap();
    if let Some(name) = name {
        write!(&mut note, " for `{name}`").unwrap();
    }
    write!(&mut note, " are: {suffix}`{possibilities}`").unwrap();
    if and_more > 0 {
        write!(&mut note, " and {and_more} more").unwrap();
    }

    note
}

pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) {
    match diagnostic {
        BuiltinLintDiag::UnicodeTextFlow(span, content) => {
            let spans: Vec<_> = content
                .char_indices()
                .filter_map(|(i, c)| {
                    TEXT_FLOW_CONTROL_CHARS.contains(&c).then(|| {
                        let lo = span.lo() + BytePos(2 + i as u32);
                        (c, span.with_lo(lo).with_hi(lo + BytePos(c.len_utf8() as u32)))
                    })
                })
                .collect();
            let (an, s) = match spans.len() {
                1 => ("an ", ""),
                _ => ("", "s"),
            };
            diag.span_label(
                span,
                format!(
                    "this comment contains {an}invisible unicode text flow control codepoint{s}",
                ),
            );
            for (c, span) in &spans {
                diag.span_label(*span, format!("{c:?}"));
            }
            diag.note(
                "these kind of unicode codepoints change the way text flows on \
                         applications that support them, but can cause confusion because they \
                         change the order of characters on the screen",
            );
            if !spans.is_empty() {
                diag.multipart_suggestion_with_style(
                    "if their presence wasn't intentional, you can remove them",
                    spans.into_iter().map(|(_, span)| (span, "".to_string())).collect(),
                    Applicability::MachineApplicable,
                    SuggestionStyle::HideCodeAlways,
                );
            }
        }
        BuiltinLintDiag::Normal => (),
        BuiltinLintDiag::AbsPathWithModule(span) => {
            let (sugg, app) = match sess.source_map().span_to_snippet(span) {
                Ok(ref s) => {
                    // FIXME(Manishearth) ideally the emitting code
                    // can tell us whether or not this is global
                    let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" };

                    (format!("crate{opt_colon}{s}"), Applicability::MachineApplicable)
                }
                Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
            };
            diag.span_suggestion(span, "use `crate`", sugg, app);
        }
        BuiltinLintDiag::ProcMacroDeriveResolutionFallback(span) => {
            diag.span_label(
                span,
                "names from parent modules are not accessible without an explicit import",
            );
        }
        BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
            diag.span_note(span_def, "the macro is defined here");
        }
        BuiltinLintDiag::ElidedLifetimesInPaths(n, path_span, incl_angl_brckt, insertion_span) => {
            add_elided_lifetime_in_path_suggestion(
                sess.source_map(),
                diag,
                n,
                path_span,
                incl_angl_brckt,
                insertion_span,
            );
        }
        BuiltinLintDiag::UnknownCrateTypes(span, note, sugg) => {
            diag.span_suggestion(span, note, sugg, Applicability::MaybeIncorrect);
        }
        BuiltinLintDiag::UnusedImports(message, replaces, in_test_module) => {
            if !replaces.is_empty() {
                diag.tool_only_multipart_suggestion(
                    message,
                    replaces,
                    Applicability::MachineApplicable,
                );
            }

            if let Some(span) = in_test_module {
                diag.span_help(
                    sess.source_map().guess_head_span(span),
                    "if this is a test module, consider adding a `#[cfg(test)]` to the containing module",
                );
            }
        }
        BuiltinLintDiag::RedundantImport(spans, ident) => {
            for (span, is_imported) in spans {
                let introduced = if is_imported { "imported" } else { "defined" };
                let span_msg = if span.is_dummy() { "by prelude" } else { "here" };
                diag.span_label(
                    span,
                    format!("the item `{ident}` is already {introduced} {span_msg}"),
                );
            }
        }
        BuiltinLintDiag::DeprecatedMacro(suggestion, span) => {
            stability::deprecation_suggestion(diag, "macro", suggestion, span)
        }
        BuiltinLintDiag::UnusedDocComment(span) => {
            diag.span_label(span, "rustdoc does not generate documentation for macro invocations");
            diag.help("to document an item produced by a macro, \
                                  the macro must produce the documentation as part of its expansion");
        }
        BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident) => {
            diag.span_suggestion(
                span,
                "remove `mut` from the parameter",
                ident,
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::MissingAbi(span, default_abi) => {
            diag.span_label(span, "ABI should be specified here");
            diag.help(format!("the default ABI is {}", default_abi.name()));
        }
        BuiltinLintDiag::LegacyDeriveHelpers(span) => {
            diag.span_label(span, "the attribute is introduced here");
        }
        BuiltinLintDiag::ProcMacroBackCompat(note) => {
            diag.note(note);
        }
        BuiltinLintDiag::OrPatternsBackCompat(span, suggestion) => {
            diag.span_suggestion(
                span,
                "use pat_param to preserve semantics",
                suggestion,
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::ReservedPrefix(span) => {
            diag.span_label(span, "unknown prefix");
            diag.span_suggestion_verbose(
                span.shrink_to_hi(),
                "insert whitespace here to avoid this being parsed as a prefix in Rust 2021",
                " ",
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
            diag.span_note(
                        invoc_span,
                        format!("the built-in attribute `{attr_name}` will be ignored, since it's applied to the macro invocation `{macro_name}`")
                    );
        }
        BuiltinLintDiag::TrailingMacro(is_trailing, name) => {
            if is_trailing {
                diag.note("macro invocations at the end of a block are treated as expressions");
                diag.note(format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`"));
            }
        }
        BuiltinLintDiag::BreakWithLabelAndLoop(span) => {
            diag.multipart_suggestion(
                "wrap this expression in parentheses",
                vec![
                    (span.shrink_to_lo(), "(".to_string()),
                    (span.shrink_to_hi(), ")".to_string()),
                ],
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::NamedAsmLabel(help) => {
            diag.help(help);
            diag.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
        }
        BuiltinLintDiag::UnexpectedCfgName((name, name_span), value) => {
            #[allow(rustc::potential_query_instability)]
            let possibilities: Vec<Symbol> =
                sess.psess.check_config.expecteds.keys().copied().collect();

            let mut names_possibilities: Vec<_> = if value.is_none() {
                // We later sort and display all the possibilities, so the order here does not matter.
                #[allow(rustc::potential_query_instability)]
                sess.psess
                    .check_config
                    .expecteds
                    .iter()
                    .filter_map(|(k, v)| match v {
                        ExpectedValues::Some(v) if v.contains(&Some(name)) => Some(k),
                        _ => None,
                    })
                    .collect()
            } else {
                Vec::new()
            };

            let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
            let mut is_feature_cfg = name == sym::feature;

            if is_feature_cfg && is_from_cargo {
                diag.help("consider defining some features in `Cargo.toml`");
            // Suggest the most probable if we found one
            } else if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {
                if let Some(ExpectedValues::Some(best_match_values)) =
                    sess.psess.check_config.expecteds.get(&best_match)
                {
                    // We will soon sort, so the initial order does not matter.
                    #[allow(rustc::potential_query_instability)]
                    let mut possibilities =
                        best_match_values.iter().flatten().map(Symbol::as_str).collect::<Vec<_>>();
                    possibilities.sort();

                    let mut should_print_possibilities = true;
                    if let Some((value, value_span)) = value {
                        if best_match_values.contains(&Some(value)) {
                            diag.span_suggestion(
                                name_span,
                                "there is a config with a similar name and value",
                                best_match,
                                Applicability::MaybeIncorrect,
                            );
                            should_print_possibilities = false;
                        } else if best_match_values.contains(&None) {
                            diag.span_suggestion(
                                name_span.to(value_span),
                                "there is a config with a similar name and no value",
                                best_match,
                                Applicability::MaybeIncorrect,
                            );
                            should_print_possibilities = false;
                        } else if let Some(first_value) = possibilities.first() {
                            diag.span_suggestion(
                                name_span.to(value_span),
                                "there is a config with a similar name and different values",
                                format!("{best_match} = \"{first_value}\""),
                                Applicability::MaybeIncorrect,
                            );
                        } else {
                            diag.span_suggestion(
                                name_span.to(value_span),
                                "there is a config with a similar name and different values",
                                best_match,
                                Applicability::MaybeIncorrect,
                            );
                        };
                    } else {
                        diag.span_suggestion(
                            name_span,
                            "there is a config with a similar name",
                            best_match,
                            Applicability::MaybeIncorrect,
                        );
                    }

                    if !possibilities.is_empty() && should_print_possibilities {
                        let possibilities = possibilities.join("`, `");
                        diag.help(format!(
                            "expected values for `{best_match}` are: `{possibilities}`"
                        ));
                    }
                } else {
                    diag.span_suggestion(
                        name_span,
                        "there is a config with a similar name",
                        best_match,
                        Applicability::MaybeIncorrect,
                    );
                }

                is_feature_cfg |= best_match == sym::feature;
            } else {
                if !names_possibilities.is_empty() && names_possibilities.len() <= 3 {
                    names_possibilities.sort();
                    for cfg_name in names_possibilities.iter() {
                        diag.span_suggestion(
                            name_span,
                            "found config with similar value",
                            format!("{cfg_name} = \"{name}\""),
                            Applicability::MaybeIncorrect,
                        );
                    }
                }
                if !possibilities.is_empty() {
                    diag.help_once(check_cfg_expected_note(
                        sess,
                        &possibilities,
                        "names",
                        None,
                        "",
                    ));
                }
            }

            let inst = if let Some((value, _value_span)) = value {
                let pre = if is_from_cargo { "\\" } else { "" };
                format!("cfg({name}, values({pre}\"{value}{pre}\"))")
            } else {
                format!("cfg({name})")
            };

            if is_from_cargo {
                if !is_feature_cfg {
                    diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
                }
                diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
            } else {
                diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
                diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
            }
        }
        BuiltinLintDiag::UnexpectedCfgValue((name, name_span), value) => {
            let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name)
            else {
                bug!(
                    "it shouldn't be possible to have a diagnostic on a value whose name is not in values"
                );
            };
            let mut have_none_possibility = false;
            // We later sort possibilities if it is not empty, so the
            // order here does not matter.
            #[allow(rustc::potential_query_instability)]
            let possibilities: Vec<Symbol> = values
                .iter()
                .inspect(|a| have_none_possibility |= a.is_none())
                .copied()
                .flatten()
                .collect();
            let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();

            // Show the full list if all possible values for a given name, but don't do it
            // for names as the possibilities could be very long
            if !possibilities.is_empty() {
                diag.note(check_cfg_expected_note(
                    sess,
                    &possibilities,
                    "values",
                    Some(name),
                    if have_none_possibility { "(none), " } else { "" },
                ));

                if let Some((value, value_span)) = value {
                    // Suggest the most probable if we found one
                    if let Some(best_match) = find_best_match_for_name(&possibilities, value, None)
                    {
                        diag.span_suggestion(
                            value_span,
                            "there is a expected value with a similar name",
                            format!("\"{best_match}\""),
                            Applicability::MaybeIncorrect,
                        );
                    }
                } else if let &[first_possibility] = &possibilities[..] {
                    diag.span_suggestion(
                        name_span.shrink_to_hi(),
                        "specify a config value",
                        format!(" = \"{first_possibility}\""),
                        Applicability::MaybeIncorrect,
                    );
                }
            } else if have_none_possibility {
                diag.note(format!("no expected value for `{name}`"));
                if let Some((_value, value_span)) = value {
                    diag.span_suggestion(
                        name_span.shrink_to_hi().to(value_span),
                        "remove the value",
                        "",
                        Applicability::MaybeIncorrect,
                    );
                }
            } else {
                diag.note(format!("no expected values for `{name}`"));

                let sp = if let Some((_value, value_span)) = value {
                    name_span.to(value_span)
                } else {
                    name_span
                };
                diag.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect);
            }

            // We don't want to suggest adding values to well known names
            // since those are defined by rustc it-self. Users can still
            // do it if they want, but should not encourage them.
            let is_cfg_a_well_know_name = sess.psess.check_config.well_known_names.contains(&name);

            let inst = if let Some((value, _value_span)) = value {
                let pre = if is_from_cargo { "\\" } else { "" };
                format!("cfg({name}, values({pre}\"{value}{pre}\"))")
            } else {
                format!("cfg({name})")
            };

            if is_from_cargo {
                if name == sym::feature {
                    if let Some((value, _value_span)) = value {
                        diag.help(format!(
                            "consider adding `{value}` as a feature in `Cargo.toml`"
                        ));
                    } else {
                        diag.help("consider defining some features in `Cargo.toml`");
                    }
                } else if !is_cfg_a_well_know_name {
                    diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
                }
                diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
            } else {
                if !is_cfg_a_well_know_name {
                    diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
                }
                diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
            }
        }
        BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg) => {
            let left_sp = diag.span.primary_span().unwrap();
            match sugg {
                Some((right_sp, sugg)) => diag.multipart_suggestion(
                    "move it to the end of the type declaration",
                    vec![(left_sp, String::new()), (right_sp, sugg)],
                    Applicability::MachineApplicable,
                ),
                None => diag.span_suggestion(
                    left_sp,
                    "remove this `where`",
                    "",
                    Applicability::MachineApplicable,
                ),
            };
            diag.note("see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information");
        }
        BuiltinLintDiag::SingleUseLifetime {
            param_span,
            use_span: Some((use_span, elide)),
            deletion_span,
        } => {
            debug!(?param_span, ?use_span, ?deletion_span);
            diag.span_label(param_span, "this lifetime...");
            diag.span_label(use_span, "...is used only here");
            if let Some(deletion_span) = deletion_span {
                let msg = "elide the single-use lifetime";
                let (use_span, replace_lt) = if elide {
                    let use_span = sess
                        .source_map()
                        .span_extend_while(use_span, char::is_whitespace)
                        .unwrap_or(use_span);
                    (use_span, String::new())
                } else {
                    (use_span, "'_".to_owned())
                };
                debug!(?deletion_span, ?use_span);

                // issue 107998 for the case such as a wrong function pointer type
                // `deletion_span` is empty and there is no need to report lifetime uses here
                let suggestions = if deletion_span.is_empty() {
                    vec![(use_span, replace_lt)]
                } else {
                    vec![(deletion_span, String::new()), (use_span, replace_lt)]
                };
                diag.multipart_suggestion(msg, suggestions, Applicability::MachineApplicable);
            }
        }
        BuiltinLintDiag::SingleUseLifetime { param_span: _, use_span: None, deletion_span } => {
            debug!(?deletion_span);
            if let Some(deletion_span) = deletion_span {
                diag.span_suggestion(
                    deletion_span,
                    "elide the unused lifetime",
                    "",
                    Applicability::MachineApplicable,
                );
            }
        }
        BuiltinLintDiag::NamedArgumentUsedPositionally {
            position_sp_to_replace,
            position_sp_for_msg,
            named_arg_sp,
            named_arg_name,
            is_formatting_arg,
        } => {
            diag.span_label(
                named_arg_sp,
                "this named argument is referred to by position in formatting string",
            );
            if let Some(positional_arg_for_msg) = position_sp_for_msg {
                let msg = format!(
                    "this formatting argument uses named argument `{named_arg_name}` by position"
                );
                diag.span_label(positional_arg_for_msg, msg);
            }

            if let Some(positional_arg_to_replace) = position_sp_to_replace {
                let name = if is_formatting_arg { named_arg_name + "$" } else { named_arg_name };
                let span_to_replace = if let Ok(positional_arg_content) =
                    sess.source_map().span_to_snippet(positional_arg_to_replace)
                    && positional_arg_content.starts_with(':')
                {
                    positional_arg_to_replace.shrink_to_lo()
                } else {
                    positional_arg_to_replace
                };
                diag.span_suggestion_verbose(
                    span_to_replace,
                    "use the named argument by name to avoid ambiguity",
                    name,
                    Applicability::MaybeIncorrect,
                );
            }
        }
        BuiltinLintDiag::ByteSliceInPackedStructWithDerive => {
            diag.help("consider implementing the trait by hand, or remove the `packed` attribute");
        }
        BuiltinLintDiag::UnusedExternCrate { removal_span } => {
            diag.span_suggestion(removal_span, "remove it", "", Applicability::MachineApplicable);
        }
        BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => {
            let suggestion_span = vis_span.between(ident_span);
            diag.span_suggestion_verbose(
                suggestion_span,
                "convert it to a `use`",
                if vis_span.is_empty() { "use " } else { " use " },
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::AmbiguousGlobImports { diag: ambiguity } => {
            rustc_errors::report_ambiguity_error(diag, ambiguity);
        }
        BuiltinLintDiag::AmbiguousGlobReexports {
            name,
            namespace,
            first_reexport_span,
            duplicate_reexport_span,
        } => {
            diag.span_label(
                first_reexport_span,
                format!("the name `{name}` in the {namespace} namespace is first re-exported here"),
            );
            diag.span_label(
                duplicate_reexport_span,
                format!(
                    "but the name `{name}` in the {namespace} namespace is also re-exported here"
                ),
            );
        }
        BuiltinLintDiag::HiddenGlobReexports {
            name,
            namespace,
            glob_reexport_span,
            private_item_span,
        } => {
            diag.span_note(glob_reexport_span, format!("the name `{name}` in the {namespace} namespace is supposed to be publicly re-exported here"));
            diag.span_note(private_item_span, "but the private item here shadows it".to_owned());
        }
        BuiltinLintDiag::UnusedQualifications { removal_span } => {
            diag.span_suggestion_verbose(
                removal_span,
                "remove the unnecessary path segments",
                "",
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span } => {
            diag.span_suggestion_verbose(
                if elided { span.shrink_to_hi() } else { span },
                "use the `'static` lifetime",
                if elided { "'static " } else { "'static" },
                Applicability::MachineApplicable,
            );
        }
        BuiltinLintDiag::RedundantImportVisibility { max_vis, span } => {
            diag.span_note(span, format!("the most public imported item is `{max_vis}`"));
            diag.help(
                "reduce the glob import's visibility or increase visibility of imported items",
            );
        }
    }
}