lint: port deprecated attr diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
18a48c1d6c
commit
e151d66343
@ -334,3 +334,7 @@ lint-builtin-missing-debug-impl =
|
|||||||
|
|
||||||
lint-builtin-anonymous-params = anonymous parameters are deprecated and will be removed in the next edition
|
lint-builtin-anonymous-params = anonymous parameters are deprecated and will be removed in the next edition
|
||||||
.suggestion = try naming the parameter or explicitly ignoring it
|
.suggestion = try naming the parameter or explicitly ignoring it
|
||||||
|
|
||||||
|
lint-builtin-deprecated-attr-link = use of deprecated attribute `{$name}`: {$reason}. See {$link}
|
||||||
|
lint-builtin-deprecated-attr-used = use of deprecated attribute `{$name}`: no longer used.
|
||||||
|
lint-builtin-deprecated-attr-default-suggestion = remove this attribute
|
||||||
|
@ -969,24 +969,6 @@ pub fn new() -> DeprecatedAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lint_deprecated_attr(
|
|
||||||
cx: &EarlyContext<'_>,
|
|
||||||
attr: &ast::Attribute,
|
|
||||||
msg: &str,
|
|
||||||
suggestion: Option<&str>,
|
|
||||||
) {
|
|
||||||
cx.struct_span_lint(DEPRECATED, attr.span, |lint| {
|
|
||||||
lint.build(msg)
|
|
||||||
.span_suggestion_short(
|
|
||||||
attr.span,
|
|
||||||
suggestion.unwrap_or("remove this attribute"),
|
|
||||||
"",
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EarlyLintPass for DeprecatedAttr {
|
impl EarlyLintPass for DeprecatedAttr {
|
||||||
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
|
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
|
||||||
for BuiltinAttribute { name, gate, .. } in &self.depr_attrs {
|
for BuiltinAttribute { name, gate, .. } in &self.depr_attrs {
|
||||||
@ -998,17 +980,38 @@ fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
|
|||||||
_,
|
_,
|
||||||
) = gate
|
) = gate
|
||||||
{
|
{
|
||||||
let msg =
|
cx.struct_span_lint(DEPRECATED, attr.span, |lint| {
|
||||||
format!("use of deprecated attribute `{}`: {}. See {}", name, reason, link);
|
// FIXME(davidtwco) translatable deprecated attr
|
||||||
lint_deprecated_attr(cx, attr, &msg, suggestion);
|
lint.build(fluent::lint::builtin_deprecated_attr_link)
|
||||||
|
.set_arg("name", name)
|
||||||
|
.set_arg("reason", reason)
|
||||||
|
.set_arg("link", link)
|
||||||
|
.span_suggestion_short(
|
||||||
|
attr.span,
|
||||||
|
suggestion.map(|s| s.into()).unwrap_or(
|
||||||
|
fluent::lint::builtin_deprecated_attr_default_suggestion,
|
||||||
|
),
|
||||||
|
"",
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if attr.has_name(sym::no_start) || attr.has_name(sym::crate_id) {
|
if attr.has_name(sym::no_start) || attr.has_name(sym::crate_id) {
|
||||||
let path_str = pprust::path_to_string(&attr.get_normal_item().path);
|
cx.struct_span_lint(DEPRECATED, attr.span, |lint| {
|
||||||
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
|
lint.build(fluent::lint::builtin_deprecated_attr_used)
|
||||||
lint_deprecated_attr(cx, attr, &msg, None);
|
.set_arg("name", pprust::path_to_string(&attr.get_normal_item().path))
|
||||||
|
.span_suggestion_short(
|
||||||
|
attr.span,
|
||||||
|
fluent::lint::builtin_deprecated_attr_default_suggestion,
|
||||||
|
"",
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user