Rollup merge of #72209 - Nemo157:lint-no-mangle-in-unsafe-code, r=nikomatsakis
Add checking for no_mangle to unsafe_code lint fixes #72188 r? `@estebank`
This commit is contained in:
commit
f8b330d9fb
3 changed files with 159 additions and 20 deletions
|
@ -328,6 +328,18 @@ impl UnsafeCode {
|
|||
|
||||
cx.struct_span_lint(UNSAFE_CODE, span, decorate);
|
||||
}
|
||||
|
||||
fn report_overriden_symbol_name(&self, cx: &EarlyContext<'_>, span: Span, msg: &str) {
|
||||
self.report_unsafe(cx, span, |lint| {
|
||||
lint.build(msg)
|
||||
.note(
|
||||
"the linker's behavior with multiple libraries exporting duplicate symbol \
|
||||
names is undefined and Rust cannot provide guarantees when you manually \
|
||||
override them",
|
||||
)
|
||||
.emit();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyLintPass for UnsafeCode {
|
||||
|
@ -367,6 +379,40 @@ impl EarlyLintPass for UnsafeCode {
|
|||
lint.build("implementation of an `unsafe` trait").emit()
|
||||
}),
|
||||
|
||||
ast::ItemKind::Fn(..) => {
|
||||
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::no_mangle) {
|
||||
self.report_overriden_symbol_name(
|
||||
cx,
|
||||
attr.span,
|
||||
"declaration of a `no_mangle` function",
|
||||
);
|
||||
}
|
||||
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
|
||||
self.report_overriden_symbol_name(
|
||||
cx,
|
||||
attr.span,
|
||||
"declaration of a function with `export_name`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Static(..) => {
|
||||
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::no_mangle) {
|
||||
self.report_overriden_symbol_name(
|
||||
cx,
|
||||
attr.span,
|
||||
"declaration of a `no_mangle` static",
|
||||
);
|
||||
}
|
||||
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
|
||||
self.report_overriden_symbol_name(
|
||||
cx,
|
||||
attr.span,
|
||||
"declaration of a static with `export_name`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue