lint: port no-mangle diagnostics

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-06-28 13:40:59 +01:00
parent a13b70ea83
commit dbdbdb6874
2 changed files with 10 additions and 5 deletions

View file

@ -343,3 +343,9 @@ lint-builtin-unused-doc-comment = unused doc comment
.label = rustdoc does not generate documentation for {$kind} .label = rustdoc does not generate documentation for {$kind}
.plain-help = use `//` for a plain comment .plain-help = use `//` for a plain comment
.block-help = use `/* */` for a plain comment .block-help = use `/* */` for a plain comment
lint-builtin-no-mangle-generic = functions generic over types or consts must be mangled
.suggestion = remove this attribute
lint-builtin-const-no-mangle = const items should never be `#[no_mangle]`
.suggestion = try a static value

View file

@ -1166,10 +1166,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
GenericParamKind::Lifetime { .. } => {} GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, span, |lint| { cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, span, |lint| {
lint.build("functions generic over types or consts must be mangled") lint.build(fluent::lint::builtin_no_mangle_generic)
.span_suggestion_short( .span_suggestion_short(
no_mangle_attr.span, no_mangle_attr.span,
"remove this attribute", fluent::lint::suggestion,
"", "",
// Use of `#[no_mangle]` suggests FFI intent; correct // Use of `#[no_mangle]` suggests FFI intent; correct
// fix may be to monomorphize source by hand // fix may be to monomorphize source by hand
@ -1193,8 +1193,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
// Const items do not refer to a particular location in memory, and therefore // Const items do not refer to a particular location in memory, and therefore
// don't have anything to attach a symbol to // don't have anything to attach a symbol to
cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, |lint| { cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, |lint| {
let msg = "const items should never be `#[no_mangle]`"; let mut err = lint.build(fluent::lint::builtin_const_no_mangle);
let mut err = lint.build(msg);
// account for "pub const" (#45562) // account for "pub const" (#45562)
let start = cx let start = cx
@ -1208,7 +1207,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5)); let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
err.span_suggestion( err.span_suggestion(
const_span, const_span,
"try a static value", fluent::lint::suggestion,
"pub static", "pub static",
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );