Rollup merge of #125132 - mejrs:diag, r=compiler-errors · rust-lang/rust@f7c2934 (original) (raw)

`@@ -29,6 +29,7 @@ use rustc_session::lint::builtin::{LEGACY_DERIVE_HELPERS, SOFT_UNSTABLE};

`

29

29

`use rustc_session::lint::builtin::{UNUSED_MACROS, UNUSED_MACRO_RULES};

`

30

30

`use rustc_session::lint::BuiltinLintDiag;

`

31

31

`use rustc_session::parse::feature_err;

`

``

32

`+

use rustc_span::edit_distance::edit_distance;

`

32

33

`use rustc_span::edition::Edition;

`

33

34

`use rustc_span:🪥:{self, ExpnData, ExpnKind, LocalExpnId};

`

34

35

`use rustc_span:🪥:{AstPass, MacroKind};

`

`@@ -568,15 +569,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

`

568

569

`}

`

569

570

``

570

571

`if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)

`

571

``

`-

&& path.segments.len() >= 2

`

572

``

`-

&& path.segments[0].ident.name == sym::diagnostic

`

573

``

`-

&& path.segments[1].ident.name != sym::on_unimplemented

`

``

572

`+

&& let [namespace, attribute, ..] = &*path.segments

`

``

573

`+

&& namespace.ident.name == sym::diagnostic

`

``

574

`+

&& attribute.ident.name != sym::on_unimplemented

`

574

575

`{

`

575

``

`-

self.tcx.sess.psess.buffer_lint(

`

``

576

`+

let distance =

`

``

577

`+

edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);

`

``

578

+

``

579

`+

let help = if distance.is_some() {

`

``

580

`+

BuiltinLintDiag::MaybeTypo { span: attribute.span(), name: sym::on_unimplemented }

`

``

581

`+

} else {

`

``

582

`+

BuiltinLintDiag::Normal

`

``

583

`+

};

`

``

584

`+

self.tcx.sess.psess.buffer_lint_with_diagnostic(

`

576

585

`UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,

`

577

``

`-

path.segments[1].span(),

`

``

586

`+

attribute.span(),

`

578

587

` node_id,

`

579

588

`"unknown diagnostic attribute",

`

``

589

`+

help,

`

580

590

`);

`

581

591

`}

`

582

592

``