Skip to content

Commit 8bed93c

Browse files
Rollup merge of #154585 - HerrCai0907:fix/no_mangle_generic_items, r=oli-obk
treat no_mangle_generic_items as hard error instead of lint warning Reference PR: - rust-lang/reference#1904 In rust-lang#4929 (comment), rustc should reject the no_mangled generic function. This PR treat is as a hard error
2 parents 6345b18 + 33b5f0c commit 8bed93c

5 files changed

Lines changed: 7 additions & 44 deletions

File tree

src/helpers.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,7 @@ pub fn iter_exported_symbols<'tcx>(
132132
if !(used || codegen_attrs.contains_extern_indicator()) {
133133
continue;
134134
}
135-
// FIXME: `#[no_mangle]` makes no sense on a generic item, but still causes it to be
136-
// considered "extern". Remove this once `no_mangle_generic_items` is a hard error.
137-
let mono = {
138-
let generics = tcx.generics_of(def_id);
139-
!generics.requires_monomorphization(tcx)
140-
};
141-
if mono {
142-
f(LOCAL_CRATE, def_id.into(), used)?;
143-
}
135+
f(LOCAL_CRATE, def_id.into(), used)?;
144136
}
145137

146138
// Next, all our dependencies.
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(unused_imports, unused_attributes, no_mangle_generic_items)]
1+
#![allow(unused_imports, unused_attributes)]
22

33
// Regression test for https://github.com/rust-lang/rust/issues/86261:
44
// `#[no_mangle]` on a `use` item.
@@ -14,10 +14,6 @@ pub struct NoMangleStruct;
1414
#[export_name = "NoMangleStruct"]
1515
fn no_mangle_struct() {}
1616

17-
// `#[no_mangle]` on a generic function can also cause ICEs.
18-
#[no_mangle]
19-
fn no_mangle_generic<T>() {}
20-
21-
// Same as `no_mangle_struct()` but for the `no_mangle_generic()` generic function.
22-
#[export_name = "no_mangle_generic"]
23-
fn no_mangle_generic2() {}
17+
// Same as `no_mangle_struct()` but for the `no_mangle_struct()` function.
18+
#[export_name = "no_mangle_struct"]
19+
fn no_mangle_alias() {}

test-cargo-miri/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ mod test {
8787
fn assoc_fn_as_exported_symbol() -> i32;
8888
fn make_true() -> bool;
8989
fn NoMangleStruct();
90-
fn no_mangle_generic();
90+
fn no_mangle_struct();
9191
}
9292
assert_eq!(unsafe { exported_symbol() }, 123456);
9393
assert_eq!(unsafe { assoc_fn_as_exported_symbol() }, -123456);
9494
assert!(unsafe { make_true() });
9595
unsafe { NoMangleStruct() }
96-
unsafe { no_mangle_generic() }
96+
unsafe { no_mangle_struct() }
9797
}
9898
}
9999

tests/pass/issues/issue-154385-no-mangle-generic.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/pass/issues/issue-154385-no-mangle-generic.stdout

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)