Change:
Given that there should be a lint that is capable of detecting it (there was a suggestion that should also detect it, but it might make sense to be able to lint it individually too).
So maybe should be a lint group, and include this new lint? I am suggesting that because I think should suffice to trigger the new lint.
I've got the basic lint working now. do you think it's worth adding it as a separate lint, renaming to something else (which I can't think of a name for), and adding them both as lints in an group; or better to just integrate it into the current lint?
I'll defer to for that :D
I am partial towards having a hard error when encountering multiple functions with the same name in a given workspace, . Adding this to might be problematic in the wild. Let's make a PR that rolls it into and see the behavior in the wild with a crater run, but if it causes too much fallout, lets make it an independent lint.
There's other ways of using which create UB than just overriding within a workspace, e.g. the example in While adding a hard error for cases that can be detected would be nice, I don't think it's possible in general.
Removing I-prioritize since this is already tracked at
Is there a tracking issue for additional lints like this to similar "unsafe attributes"? I think that'd be great!
not that I know of but you could open one :)
Done

Discussion:
cx.struct_span_lint(UNSAFE_CODE, span, decorate); } <ins> 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(); }) } </ins> } impl EarlyLintPass for UnsafeCode {

}) } <ins> 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`", ); } } </ins> _ => {} } }

unsafe fn also_allowed() {} unsafe trait AllowedUnsafe { } unsafe impl AllowedUnsafe for super::Bar {} <ins> #[no_mangle] fn allowed2() {} #[export_name = "foo"] fn allowed3() {} </ins> } macro_rules! unsafe_in_macro { <del> () => { </del> <ins> () => {{ #[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` function #[no_mangle] static FOO: u32 = 5; //~ ERROR: declaration of a `no_mangle` static #[export_name = "bar"] fn bar() {} //~^ ERROR: declaration of a function with `export_name` #[export_name = "BAR"] static BAR: u32 = 5; //~^ ERROR: declaration of a static with `export_name` </ins> unsafe {} //~ ERROR: usage of an `unsafe` block <del> } </del> <ins> }} </ins> } <ins> #[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` function #[no_mangle] static FOO: u32 = 5; //~ ERROR: declaration of a `no_mangle` static #[export_name = "bar"] fn bar() {} //~ ERROR: declaration of a function with `export_name` #[export_name = "BAR"] static BAR: u32 = 5; //~ ERROR: declaration of a static with `export_name` </ins> unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function unsafe trait Foo {} //~ ERROR: declaration of an `unsafe` trait unsafe impl Foo for Bar {} //~ ERROR: implementation of an `unsafe` trait

<del> error: declaration of an `unsafe` function --> $DIR/lint-unsafe-code.rs:23:1 </del> <ins> error: declaration of a `no_mangle` function --> $DIR/lint-unsafe-code.rs:31:1 </ins> | <del> LL | unsafe fn baz() {} | ^^^^^^^^^^^^^^^^^^ </del> <ins> LL | #[no_mangle] fn foo() {} | ^^^^^^^^^^^^ </ins> | note: the lint level is defined here --> $DIR/lint-unsafe-code.rs:3:9 | LL | #![deny(unsafe_code)] |         ^^^^^^^^^^^ <ins> = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of a `no_mangle` static --> $DIR/lint-unsafe-code.rs:32:1 | LL | #[no_mangle] static FOO: u32 = 5; | ^^^^^^^^^^^^ | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of a function with `export_name` --> $DIR/lint-unsafe-code.rs:34:1 | LL | #[export_name = "bar"] fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of a static with `export_name` --> $DIR/lint-unsafe-code.rs:35:1 | LL | #[export_name = "BAR"] static BAR: u32 = 5; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of an `unsafe` function --> $DIR/lint-unsafe-code.rs:37:1 | LL | unsafe fn baz() {} | ^^^^^^^^^^^^^^^^^^ </ins> error: declaration of an `unsafe` trait <del> --> $DIR/lint-unsafe-code.rs:24:1 </del> <ins> --> $DIR/lint-unsafe-code.rs:38:1 </ins> | LL | unsafe trait Foo {} | ^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` trait <del> --> $DIR/lint-unsafe-code.rs:25:1 </del> <ins> --> $DIR/lint-unsafe-code.rs:39:1 </ins> | LL | unsafe impl Foo for Bar {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: declaration of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:28:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:42:5 </ins> | LL |     unsafe fn baz(&self); |     ^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:29:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:43:5 </ins> | LL |     unsafe fn provided(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:30:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:44:5 </ins> | LL |     unsafe fn provided_override(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:34:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:48:5 </ins> | LL |     unsafe fn baz(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:35:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:49:5 </ins> | LL |     unsafe fn provided_override(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:54:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:68:5 </ins> | LL |     unsafe fn provided_override(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:65:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:79:5 </ins> | LL |     unsafe fn provided(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:71:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:85:5 </ins> | LL |     unsafe fn provided(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: implementation of an `unsafe` method <del> --> $DIR/lint-unsafe-code.rs:75:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:89:5 </ins> | LL |     unsafe fn baz(&self) {} |     ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of an `unsafe` block <del> --> $DIR/lint-unsafe-code.rs:86:5 </del> <ins> --> $DIR/lint-unsafe-code.rs:100:5 </ins> | LL |     unsafe {} |     ^^^^^^^^^ <ins> error: declaration of a `no_mangle` function --> $DIR/lint-unsafe-code.rs:21:9 | LL |         #[no_mangle] fn foo() {} |         ^^^^^^^^^^^^ ... LL |     unsafe_in_macro!() |     ------------------ in this macro invocation | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: declaration of a `no_mangle` static --> $DIR/lint-unsafe-code.rs:22:9 | LL |         #[no_mangle] static FOO: u32 = 5; |         ^^^^^^^^^^^^ ... LL |     unsafe_in_macro!() |     ------------------ in this macro invocation | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: declaration of a function with `export_name` --> $DIR/lint-unsafe-code.rs:23:9 | LL |         #[export_name = "bar"] fn bar() {} |         ^^^^^^^^^^^^^^^^^^^^^^ ... LL |     unsafe_in_macro!() |     ------------------ in this macro invocation | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: declaration of a static with `export_name` --> $DIR/lint-unsafe-code.rs:25:9 | LL |         #[export_name = "BAR"] static BAR: u32 = 5; |         ^^^^^^^^^^^^^^^^^^^^^^ ... LL |     unsafe_in_macro!() |     ------------------ in this macro invocation | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) </ins> error: usage of an `unsafe` block <del> --> $DIR/lint-unsafe-code.rs:19:9 </del> <ins> --> $DIR/lint-unsafe-code.rs:27:9 </ins> | LL |         unsafe {} |         ^^^^^^^^^

| = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) <del> error: aborting due to 14 previous errors </del> <ins> error: aborting due to 22 previous errors </ins>