Skip to content

Commit e151d66

Browse files
committed
lint: port deprecated attr diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 18a48c1 commit e151d66

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,7 @@ lint-builtin-missing-debug-impl =
334334
335335
lint-builtin-anonymous-params = anonymous parameters are deprecated and will be removed in the next edition
336336
.suggestion = try naming the parameter or explicitly ignoring it
337+
338+
lint-builtin-deprecated-attr-link = use of deprecated attribute `{$name}`: {$reason}. See {$link}
339+
lint-builtin-deprecated-attr-used = use of deprecated attribute `{$name}`: no longer used.
340+
lint-builtin-deprecated-attr-default-suggestion = remove this attribute

compiler/rustc_lint/src/builtin.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -969,24 +969,6 @@ impl DeprecatedAttr {
969969
}
970970
}
971971

972-
fn lint_deprecated_attr(
973-
cx: &EarlyContext<'_>,
974-
attr: &ast::Attribute,
975-
msg: &str,
976-
suggestion: Option<&str>,
977-
) {
978-
cx.struct_span_lint(DEPRECATED, attr.span, |lint| {
979-
lint.build(msg)
980-
.span_suggestion_short(
981-
attr.span,
982-
suggestion.unwrap_or("remove this attribute"),
983-
"",
984-
Applicability::MachineApplicable,
985-
)
986-
.emit();
987-
})
988-
}
989-
990972
impl EarlyLintPass for DeprecatedAttr {
991973
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
992974
for BuiltinAttribute { name, gate, .. } in &self.depr_attrs {
@@ -998,17 +980,38 @@ impl EarlyLintPass for DeprecatedAttr {
998980
_,
999981
) = gate
1000982
{
1001-
let msg =
1002-
format!("use of deprecated attribute `{}`: {}. See {}", name, reason, link);
1003-
lint_deprecated_attr(cx, attr, &msg, suggestion);
983+
cx.struct_span_lint(DEPRECATED, attr.span, |lint| {
984+
// FIXME(davidtwco) translatable deprecated attr
985+
lint.build(fluent::lint::builtin_deprecated_attr_link)
986+
.set_arg("name", name)
987+
.set_arg("reason", reason)
988+
.set_arg("link", link)
989+
.span_suggestion_short(
990+
attr.span,
991+
suggestion.map(|s| s.into()).unwrap_or(
992+
fluent::lint::builtin_deprecated_attr_default_suggestion,
993+
),
994+
"",
995+
Applicability::MachineApplicable,
996+
)
997+
.emit();
998+
});
1004999
}
10051000
return;
10061001
}
10071002
}
10081003
if attr.has_name(sym::no_start) || attr.has_name(sym::crate_id) {
1009-
let path_str = pprust::path_to_string(&attr.get_normal_item().path);
1010-
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
1011-
lint_deprecated_attr(cx, attr, &msg, None);
1004+
cx.struct_span_lint(DEPRECATED, attr.span, |lint| {
1005+
lint.build(fluent::lint::builtin_deprecated_attr_used)
1006+
.set_arg("name", pprust::path_to_string(&attr.get_normal_item().path))
1007+
.span_suggestion_short(
1008+
attr.span,
1009+
fluent::lint::builtin_deprecated_attr_default_suggestion,
1010+
"",
1011+
Applicability::MachineApplicable,
1012+
)
1013+
.emit();
1014+
});
10121015
}
10131016
}
10141017
}

0 commit comments

Comments
 (0)