Rollup merge of #138868 - mejrs:d_not_recommend_typo, r=davidtwco
Add do_not_recommend typo help
This commit is contained in:
commit
a678d2068d
3 changed files with 25 additions and 8 deletions
|
@ -28,7 +28,7 @@ use rustc_session::lint::builtin::{
|
||||||
UNUSED_MACRO_RULES, UNUSED_MACROS,
|
UNUSED_MACRO_RULES, UNUSED_MACROS,
|
||||||
};
|
};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::edit_distance::edit_distance;
|
use rustc_span::edit_distance::find_best_match_for_name;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::hygiene::{self, AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
|
use rustc_span::hygiene::{self, AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
|
||||||
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
|
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
|
||||||
|
@ -652,13 +652,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
|
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
|
||||||
&& let [namespace, attribute, ..] = &*path.segments
|
&& let [namespace, attribute, ..] = &*path.segments
|
||||||
&& namespace.ident.name == sym::diagnostic
|
&& namespace.ident.name == sym::diagnostic
|
||||||
&& !(attribute.ident.name == sym::on_unimplemented
|
&& ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name)
|
||||||
|| attribute.ident.name == sym::do_not_recommend)
|
|
||||||
{
|
{
|
||||||
let distance =
|
let typo_name = find_best_match_for_name(
|
||||||
edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);
|
&[sym::on_unimplemented, sym::do_not_recommend],
|
||||||
|
attribute.ident.name,
|
||||||
let typo_name = distance.map(|_| sym::on_unimplemented);
|
Some(5),
|
||||||
|
);
|
||||||
|
|
||||||
self.tcx.sess.psess.buffer_lint(
|
self.tcx.sess.psess.buffer_lint(
|
||||||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
|
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
|
||||||
|
|
|
@ -16,4 +16,9 @@ trait Y{}
|
||||||
//~^^HELP an attribute with a similar name exists
|
//~^^HELP an attribute with a similar name exists
|
||||||
trait Z{}
|
trait Z{}
|
||||||
|
|
||||||
|
#[diagnostic::dont_recommend]
|
||||||
|
//~^ERROR unknown diagnostic attribute
|
||||||
|
//~^^HELP an attribute with a similar name exists
|
||||||
|
impl X for u8 {}
|
||||||
|
|
||||||
fn main(){}
|
fn main(){}
|
||||||
|
|
|
@ -37,5 +37,17 @@ help: an attribute with a similar name exists
|
||||||
LL | #[diagnostic::on_unimplemented]
|
LL | #[diagnostic::on_unimplemented]
|
||||||
| ++
|
| ++
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: unknown diagnostic attribute
|
||||||
|
--> $DIR/suggest_typos.rs:19:15
|
||||||
|
|
|
||||||
|
LL | #[diagnostic::dont_recommend]
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
help: an attribute with a similar name exists
|
||||||
|
|
|
||||||
|
LL - #[diagnostic::dont_recommend]
|
||||||
|
LL + #[diagnostic::do_not_recommend]
|
||||||
|
|
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue