Warn no_mangle on generic functions
This commit is contained in:
parent
7b77f67d19
commit
55ffc33b10
2 changed files with 25 additions and 10 deletions
|
@ -971,6 +971,12 @@ declare_lint! {
|
||||||
"const items will not have their symbols exported"
|
"const items will not have their symbols exported"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare_lint! {
|
||||||
|
NO_MANGLE_GENERIC_ITEMS,
|
||||||
|
Warn,
|
||||||
|
"generic items must be mangled"
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct InvalidNoMangleItems;
|
pub struct InvalidNoMangleItems;
|
||||||
|
|
||||||
|
@ -978,19 +984,26 @@ impl LintPass for InvalidNoMangleItems {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array!(PRIVATE_NO_MANGLE_FNS,
|
lint_array!(PRIVATE_NO_MANGLE_FNS,
|
||||||
PRIVATE_NO_MANGLE_STATICS,
|
PRIVATE_NO_MANGLE_STATICS,
|
||||||
NO_MANGLE_CONST_ITEMS)
|
NO_MANGLE_CONST_ITEMS,
|
||||||
|
NO_MANGLE_GENERIC_ITEMS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateLintPass for InvalidNoMangleItems {
|
impl LateLintPass for InvalidNoMangleItems {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
||||||
match it.node {
|
match it.node {
|
||||||
hir::ItemFn(..) => {
|
hir::ItemFn(_, _, _, _, ref generics, _) => {
|
||||||
if attr::contains_name(&it.attrs, "no_mangle") &&
|
if attr::contains_name(&it.attrs, "no_mangle") {
|
||||||
!cx.access_levels.is_reachable(it.id) {
|
if !cx.access_levels.is_reachable(it.id) {
|
||||||
let msg = format!("function {} is marked #[no_mangle], but not exported",
|
let msg = format!("function {} is marked #[no_mangle], but not exported",
|
||||||
it.name);
|
it.name);
|
||||||
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, &msg);
|
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, &msg);
|
||||||
|
}
|
||||||
|
if generics.is_parameterized() {
|
||||||
|
cx.span_lint(NO_MANGLE_GENERIC_ITEMS,
|
||||||
|
it.span,
|
||||||
|
"generic functions must be mangled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hir::ItemStatic(..) => {
|
hir::ItemStatic(..) => {
|
||||||
|
|
|
@ -8,10 +8,12 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-test this should fail to compile (#15844)
|
#![deny(no_mangle_generic_items)]
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn foo<T>() {} //~ ERROR generic functions must be mangled
|
pub fn foo<T>() {} //~ ERROR generic functions must be mangled
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
extern fn foo<T>() {} //~ ERROR generic functions must be mangled
|
pub extern fn bar<T>() {} //~ ERROR generic functions must be mangled
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue