Skip to content

Commit d4ffaf6

Browse files
committed
Auto merge of #30269 - sanxiyn:no-mangle-generic, r=Aatch
Fix #15844. Should the default be Deny instead?
2 parents 785a8a6 + 55ffc33 commit d4ffaf6

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/librustc_lint/builtin.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -966,26 +966,39 @@ declare_lint! {
966966
"const items will not have their symbols exported"
967967
}
968968

969+
declare_lint! {
970+
NO_MANGLE_GENERIC_ITEMS,
971+
Warn,
972+
"generic items must be mangled"
973+
}
974+
969975
#[derive(Copy, Clone)]
970976
pub struct InvalidNoMangleItems;
971977

972978
impl LintPass for InvalidNoMangleItems {
973979
fn get_lints(&self) -> LintArray {
974980
lint_array!(PRIVATE_NO_MANGLE_FNS,
975981
PRIVATE_NO_MANGLE_STATICS,
976-
NO_MANGLE_CONST_ITEMS)
982+
NO_MANGLE_CONST_ITEMS,
983+
NO_MANGLE_GENERIC_ITEMS)
977984
}
978985
}
979986

980987
impl LateLintPass for InvalidNoMangleItems {
981988
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
982989
match it.node {
983-
hir::ItemFn(..) => {
984-
if attr::contains_name(&it.attrs, "no_mangle") &&
985-
!cx.access_levels.is_reachable(it.id) {
986-
let msg = format!("function {} is marked #[no_mangle], but not exported",
987-
it.name);
988-
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, &msg);
990+
hir::ItemFn(_, _, _, _, ref generics, _) => {
991+
if attr::contains_name(&it.attrs, "no_mangle") {
992+
if !cx.access_levels.is_reachable(it.id) {
993+
let msg = format!("function {} is marked #[no_mangle], but not exported",
994+
it.name);
995+
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, &msg);
996+
}
997+
if generics.is_parameterized() {
998+
cx.span_lint(NO_MANGLE_GENERIC_ITEMS,
999+
it.span,
1000+
"generic functions must be mangled");
1001+
}
9891002
}
9901003
},
9911004
hir::ItemStatic(..) => {

src/test/compile-fail/generic-no-mangle.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-test this should fail to compile (#15844)
11+
#![deny(no_mangle_generic_items)]
1212

1313
#[no_mangle]
14-
fn foo<T>() {} //~ ERROR generic functions must be mangled
14+
pub fn foo<T>() {} //~ ERROR generic functions must be mangled
1515

1616
#[no_mangle]
17-
extern fn foo<T>() {} //~ ERROR generic functions must be mangled
17+
pub extern fn bar<T>() {} //~ ERROR generic functions must be mangled
18+
19+
fn main() {}

0 commit comments

Comments
 (0)