diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index af590d98c301c..0a5052c4b36db 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -53,11 +53,11 @@ use crate::lints::{ BuiltinExplicitOutlives, BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures, BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents, BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc, - BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns, - BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasBounds, - BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit, BuiltinUnpermittedTypeInitSub, - BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment, - BuiltinUnusedDocCommentSub, BuiltinWhileTrue, EqInternalMethodImplemented, InvalidAsmLabel, + BuiltinMutablesTransmutes, BuiltinNonShorthandFieldPatterns, BuiltinSpecialModuleNameUsed, + BuiltinTrivialBounds, BuiltinTypeAliasBounds, BuiltinUngatedAsyncFnTrackCaller, + BuiltinUnpermittedTypeInit, BuiltinUnpermittedTypeInitSub, BuiltinUnreachablePub, + BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub, + BuiltinWhileTrue, EqInternalMethodImplemented, InvalidAsmLabel, }; use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext}; declare_lint! { @@ -924,36 +924,7 @@ declare_lint! { "const items will not have their symbols exported" } -declare_lint! { - /// The `no_mangle_generic_items` lint detects generic items that must be - /// mangled. - /// - /// ### Example - /// - /// ```rust - /// #[unsafe(no_mangle)] - /// fn foo(t: T) {} - /// - /// #[unsafe(export_name = "bar")] - /// fn bar(t: T) {} - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// A function with generics must have its symbol mangled to accommodate - /// the generic parameter. The [`no_mangle`] and [`export_name`] attributes - /// have no effect in this situation, and should be removed. - /// - /// [`no_mangle`]: https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute - /// [`export_name`]: https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute - NO_MANGLE_GENERIC_ITEMS, - Warn, - "generic items must be mangled" -} - -declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GENERIC_ITEMS]); +declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS]); impl InvalidNoMangleItems { fn check_no_mangle_on_generic_fn( @@ -964,11 +935,10 @@ impl InvalidNoMangleItems { ) { let generics = cx.tcx.generics_of(def_id); if generics.requires_monomorphization(cx.tcx) { - cx.emit_span_lint( - NO_MANGLE_GENERIC_ITEMS, - cx.tcx.def_span(def_id), - BuiltinNoMangleGeneric { suggestion: attr_span }, - ); + cx.tcx.dcx().emit_err(crate::errors::BuiltinNoMangleGeneric { + span: cx.tcx.def_span(def_id), + suggestion: attr_span, + }); } } } @@ -1607,7 +1577,6 @@ declare_lint_pass!( ANONYMOUS_PARAMETERS, UNUSED_DOC_COMMENTS, NO_MANGLE_CONST_ITEMS, - NO_MANGLE_GENERIC_ITEMS, MUTABLE_TRANSMUTES, UNSTABLE_FEATURES, UNREACHABLE_PUB, diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 8fec30816bd13..37aa7bccc6745 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -74,6 +74,22 @@ pub(crate) struct UnknownToolInScopedLint { pub is_nightly_build: bool, } +#[derive(Diagnostic)] +#[diag("functions generic over types or consts must be mangled")] +pub(crate) struct BuiltinNoMangleGeneric { + #[primary_span] + pub span: Span, + // Use of `#[no_mangle]` suggests FFI intent; correct + // fix may be to monomorphize source by hand + #[suggestion( + "remove this attribute", + style = "short", + code = "", + applicability = "maybe-incorrect" + )] + pub suggestion: Span, +} + #[derive(Diagnostic)] #[diag("`...` range patterns are deprecated", code = E0783)] pub(crate) struct BuiltinEllipsisInclusiveRangePatterns { diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 2f773b9e166c7..c26bc609b5b6e 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -643,6 +643,11 @@ fn register_builtins(store: &mut LintStore) { ); store.register_removed("wasm_c_abi", "the wasm C ABI has been fixed"); store.register_removed("soft_unstable", "the general soft-unstable mechanism has been removed"); + store.register_removed( + "no_mangle_generic_items", + "converted into hard error, \ + generic items must always be mangled", + ); } fn register_internals(store: &mut LintStore) { diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index f111f8134499e..a29d60e0ccbe8 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -264,20 +264,6 @@ pub(crate) enum BuiltinUnusedDocCommentSub { BlockHelp, } -#[derive(Diagnostic)] -#[diag("functions generic over types or consts must be mangled")] -pub(crate) struct BuiltinNoMangleGeneric { - // Use of `#[no_mangle]` suggests FFI intent; correct - // fix may be to monomorphize source by hand - #[suggestion( - "remove this attribute", - style = "short", - code = "", - applicability = "maybe-incorrect" - )] - pub suggestion: Span, -} - #[derive(Diagnostic)] #[diag("const items should never be `#[no_mangle]`")] pub(crate) struct BuiltinConstNoMangle { diff --git a/src/tools/miri/test-cargo-miri/issue-rust-86261/src/lib.rs b/src/tools/miri/test-cargo-miri/issue-rust-86261/src/lib.rs index 1947c38b77455..4997891adcbcf 100644 --- a/src/tools/miri/test-cargo-miri/issue-rust-86261/src/lib.rs +++ b/src/tools/miri/test-cargo-miri/issue-rust-86261/src/lib.rs @@ -1,4 +1,4 @@ -#![allow(unused_imports, unused_attributes, no_mangle_generic_items)] +#![allow(unused_imports, unused_attributes)] // Regression test for https://github.com/rust-lang/rust/issues/86261: // `#[no_mangle]` on a `use` item. diff --git a/tests/codegen-llvm/avr/avr-func-addrspace.rs b/tests/codegen-llvm/avr/avr-func-addrspace.rs index 2a40f0f247542..8812992050325 100644 --- a/tests/codegen-llvm/avr/avr-func-addrspace.rs +++ b/tests/codegen-llvm/avr/avr-func-addrspace.rs @@ -30,7 +30,6 @@ fn arbitrary_black_box(ptr: &usize, _: &mut u32) -> Result<(), ()> { } #[inline(never)] -#[no_mangle] fn call_through_fn_trait(a: &mut impl Fn<(), Output = ()>) { (*a)() } @@ -49,7 +48,7 @@ pub extern "C" fn test() { // A call through the Fn trait must use address space 1. // - // CHECK: call{{.+}}addrspace(1) void @call_through_fn_trait({{.*}}) + // CHECK: call{{.+}}addrspace(1) void @{{.*call_through_fn_trait.*}}({{.*}}) call_through_fn_trait(&mut update_bar_value); // A call through a global variable must use address space 1. diff --git a/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs b/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs index 65da2c3f5c761..044a9c4d13e76 100644 --- a/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs +++ b/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs @@ -1,16 +1,13 @@ //@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only -#[no_mangle] pub fn baz(mut cb: F, data: u32) where F: FnMut(u32) { cb(data); } -#[no_mangle] pub fn bar(cb: F, data: u32) where F: FnMut(u32) { baz(cb, data); } -#[no_mangle] pub fn foo(cb: F, data: u32) where F: FnMut(u32) { bar(cb, data); } diff --git a/tests/ui/backtrace/line-tables-only.rs b/tests/ui/backtrace/line-tables-only.rs index b3ae8a1971b98..e9ee4c4264b3e 100644 --- a/tests/ui/backtrace/line-tables-only.rs +++ b/tests/ui/backtrace/line-tables-only.rs @@ -46,8 +46,8 @@ fn main() { // line tables? #[cfg(not(all(target_pointer_width = "32", target_env = "msvc")))] { - assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 5); + assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 6); } - assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 10); - assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 5); + assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 11); + assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 6); } diff --git a/tests/ui/generics/export-name-on-generics.fixed b/tests/ui/generics/export-name-on-generics.fixed deleted file mode 100644 index c8a3fd5798f86..0000000000000 --- a/tests/ui/generics/export-name-on-generics.fixed +++ /dev/null @@ -1,157 +0,0 @@ -//@ run-rustfix -#![allow(dead_code, mismatched_lifetime_syntaxes)] -#![deny(no_mangle_generic_items)] - -pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled - -pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - -#[export_name = "baz"] -pub fn baz(x: &i32) -> &i32 { x } - -#[export_name = "qux"] -pub fn qux<'a>(x: &'a i32) -> &i32 { x } - -pub struct Foo; - -impl Foo { - - pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - #[export_name = "baz"] - pub fn baz(x: &i32) -> &i32 { x } - - #[export_name = "qux"] - pub fn qux<'a>(x: &'a i32) -> &i32 { x } -} - -trait Trait1 { - fn foo(); - extern "C" fn bar(); - fn baz(x: &i32) -> &i32; - fn qux<'a>(x: &'a i32) -> &i32; -} - -impl Trait1 for Foo { - - fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - #[export_name = "baz"] - fn baz(x: &i32) -> &i32 { x } - - #[export_name = "qux"] - fn qux<'a>(x: &'a i32) -> &i32 { x } -} - -trait Trait2 { - fn foo(); - fn foo2(); - extern "C" fn bar(); - fn baz(x: &i32) -> &i32; - fn qux<'a>(x: &'a i32) -> &i32; -} - -impl Trait2 for Foo { - - fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - fn foo2() {} //~ ERROR functions generic over types or consts must be mangled - - - extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - - fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled - - - fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled -} - -pub struct Bar(#[allow(dead_code)] T); - -impl Bar { - - pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - - pub fn baz() {} //~ ERROR functions generic over types or consts must be mangled -} - -impl Bar { - #[export_name = "qux"] - pub fn qux() {} -} - -trait Trait3 { - fn foo(); - extern "C" fn bar(); - fn baz(); -} - -impl Trait3 for Bar { - - fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - - fn baz() {} //~ ERROR functions generic over types or consts must be mangled -} - -pub struct Baz<'a>(#[allow(dead_code)] &'a i32); - -impl<'a> Baz<'a> { - #[export_name = "foo"] - pub fn foo() {} - - #[export_name = "bar"] - pub fn bar<'b>(x: &'b i32) -> &i32 { x } -} - -trait Trait4 { - fn foo(); - fn bar<'a>(x: &'a i32) -> &i32; -} - -impl Trait4 for Bar { - #[export_name = "foo"] - fn foo() {} - - #[export_name = "bar"] - fn bar<'b>(x: &'b i32) -> &i32 { x } -} - -impl<'a> Trait4 for Baz<'a> { - #[export_name = "foo"] - fn foo() {} - - #[export_name = "bar"] - fn bar<'b>(x: &'b i32) -> &i32 { x } -} - -trait Trait5 { - fn foo(); -} - -impl Trait5 for Foo { - #[export_name = "foo"] - fn foo() {} -} - -impl Trait5 for Bar { - #[export_name = "foo"] - fn foo() {} -} - -fn main() {} diff --git a/tests/ui/generics/export-name-on-generics.rs b/tests/ui/generics/export-name-on-generics.rs index 8b38037fe12fb..8178fee78a30c 100644 --- a/tests/ui/generics/export-name-on-generics.rs +++ b/tests/ui/generics/export-name-on-generics.rs @@ -1,6 +1,4 @@ -//@ run-rustfix #![allow(dead_code, mismatched_lifetime_syntaxes)] -#![deny(no_mangle_generic_items)] #[export_name = "foo"] pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled diff --git a/tests/ui/generics/export-name-on-generics.stderr b/tests/ui/generics/export-name-on-generics.stderr index e08b2b1c8f319..d680430ca867d 100644 --- a/tests/ui/generics/export-name-on-generics.stderr +++ b/tests/ui/generics/export-name-on-generics.stderr @@ -1,19 +1,13 @@ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:6:1 + --> $DIR/export-name-on-generics.rs:4:1 | LL | #[export_name = "foo"] | ---------------------- help: remove this attribute LL | pub fn foo() {} | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/export-name-on-generics.rs:3:9 - | -LL | #![deny(no_mangle_generic_items)] - | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:9:1 + --> $DIR/export-name-on-generics.rs:7:1 | LL | #[export_name = "bar"] | ---------------------- help: remove this attribute @@ -21,7 +15,7 @@ LL | pub extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:21:5 + --> $DIR/export-name-on-generics.rs:19:5 | LL | #[export_name = "foo"] | ---------------------- help: remove this attribute @@ -29,7 +23,7 @@ LL | pub fn foo() {} | ^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:24:5 + --> $DIR/export-name-on-generics.rs:22:5 | LL | #[export_name = "bar"] | ---------------------- help: remove this attribute @@ -37,7 +31,7 @@ LL | pub extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:42:5 + --> $DIR/export-name-on-generics.rs:40:5 | LL | #[export_name = "foo"] | ---------------------- help: remove this attribute @@ -45,7 +39,7 @@ LL | fn foo() {} | ^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:45:5 + --> $DIR/export-name-on-generics.rs:43:5 | LL | #[export_name = "bar"] | ---------------------- help: remove this attribute @@ -53,7 +47,7 @@ LL | extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:64:5 + --> $DIR/export-name-on-generics.rs:62:5 | LL | #[export_name = "foo"] | ---------------------- help: remove this attribute @@ -61,7 +55,7 @@ LL | fn foo() {} | ^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:67:5 + --> $DIR/export-name-on-generics.rs:65:5 | LL | #[export_name = "foo2"] | ----------------------- help: remove this attribute @@ -69,7 +63,7 @@ LL | fn foo2() {} | ^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:70:5 + --> $DIR/export-name-on-generics.rs:68:5 | LL | #[export_name = "baz"] | ---------------------- help: remove this attribute @@ -77,7 +71,7 @@ LL | extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:73:5 + --> $DIR/export-name-on-generics.rs:71:5 | LL | #[export_name = "baz"] | ---------------------- help: remove this attribute @@ -85,7 +79,7 @@ LL | fn baz(x: &i32) -> &i32 { x } | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:76:5 + --> $DIR/export-name-on-generics.rs:74:5 | LL | #[export_name = "qux"] | ---------------------- help: remove this attribute @@ -93,7 +87,7 @@ LL | fn qux<'a>(x: &'a i32) -> &i32 { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:83:5 + --> $DIR/export-name-on-generics.rs:81:5 | LL | #[export_name = "foo"] | ---------------------- help: remove this attribute @@ -101,7 +95,7 @@ LL | pub fn foo() {} | ^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:86:5 + --> $DIR/export-name-on-generics.rs:84:5 | LL | #[export_name = "bar"] | ---------------------- help: remove this attribute @@ -109,7 +103,7 @@ LL | pub extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:89:5 + --> $DIR/export-name-on-generics.rs:87:5 | LL | #[export_name = "baz"] | ---------------------- help: remove this attribute @@ -117,7 +111,7 @@ LL | pub fn baz() {} | ^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:105:5 + --> $DIR/export-name-on-generics.rs:103:5 | LL | #[export_name = "foo"] | ---------------------- help: remove this attribute @@ -125,7 +119,7 @@ LL | fn foo() {} | ^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:108:5 + --> $DIR/export-name-on-generics.rs:106:5 | LL | #[export_name = "bar"] | ---------------------- help: remove this attribute @@ -133,7 +127,7 @@ LL | extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/export-name-on-generics.rs:111:5 + --> $DIR/export-name-on-generics.rs:109:5 | LL | #[export_name = "baz"] | ---------------------- help: remove this attribute diff --git a/tests/ui/generics/generic-no-mangle.fixed b/tests/ui/generics/generic-no-mangle.fixed deleted file mode 100644 index e3e41eb9d0db1..0000000000000 --- a/tests/ui/generics/generic-no-mangle.fixed +++ /dev/null @@ -1,157 +0,0 @@ -//@ run-rustfix -#![allow(dead_code, mismatched_lifetime_syntaxes)] -#![deny(no_mangle_generic_items)] - -pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled - -pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - -#[no_mangle] -pub fn baz(x: &i32) -> &i32 { x } - -#[no_mangle] -pub fn qux<'a>(x: &'a i32) -> &i32 { x } - -pub struct Foo; - -impl Foo { - - pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - #[no_mangle] - pub fn baz(x: &i32) -> &i32 { x } - - #[no_mangle] - pub fn qux<'a>(x: &'a i32) -> &i32 { x } -} - -trait Trait1 { - fn foo(); - extern "C" fn bar(); - fn baz(x: &i32) -> &i32; - fn qux<'a>(x: &'a i32) -> &i32; -} - -impl Trait1 for Foo { - - fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - #[no_mangle] - fn baz(x: &i32) -> &i32 { x } - - #[no_mangle] - fn qux<'a>(x: &'a i32) -> &i32 { x } -} - -trait Trait2 { - fn foo(); - fn foo2(); - extern "C" fn bar(); - fn baz(x: &i32) -> &i32; - fn qux<'a>(x: &'a i32) -> &i32; -} - -impl Trait2 for Foo { - - fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - fn foo2() {} //~ ERROR functions generic over types or consts must be mangled - - - extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - - fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled - - - fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled -} - -pub struct Bar(#[allow(dead_code)] T); - -impl Bar { - - pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - - pub fn baz() {} //~ ERROR functions generic over types or consts must be mangled -} - -impl Bar { - #[no_mangle] - pub fn qux() {} -} - -trait Trait3 { - fn foo(); - extern "C" fn bar(); - fn baz(); -} - -impl Trait3 for Bar { - - fn foo() {} //~ ERROR functions generic over types or consts must be mangled - - - extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled - - - fn baz() {} //~ ERROR functions generic over types or consts must be mangled -} - -pub struct Baz<'a>(#[allow(dead_code)] &'a i32); - -impl<'a> Baz<'a> { - #[no_mangle] - pub fn foo() {} - - #[no_mangle] - pub fn bar<'b>(x: &'b i32) -> &i32 { x } -} - -trait Trait4 { - fn foo(); - fn bar<'a>(x: &'a i32) -> &i32; -} - -impl Trait4 for Bar { - #[no_mangle] - fn foo() {} - - #[no_mangle] - fn bar<'b>(x: &'b i32) -> &i32 { x } -} - -impl<'a> Trait4 for Baz<'a> { - #[no_mangle] - fn foo() {} - - #[no_mangle] - fn bar<'b>(x: &'b i32) -> &i32 { x } -} - -trait Trait5 { - fn foo(); -} - -impl Trait5 for Foo { - #[no_mangle] - fn foo() {} -} - -impl Trait5 for Bar { - #[no_mangle] - fn foo() {} -} - -fn main() {} diff --git a/tests/ui/generics/generic-no-mangle.rs b/tests/ui/generics/generic-no-mangle.rs index 085f8610a548e..34f1d3b7d415a 100644 --- a/tests/ui/generics/generic-no-mangle.rs +++ b/tests/ui/generics/generic-no-mangle.rs @@ -1,6 +1,4 @@ -//@ run-rustfix #![allow(dead_code, mismatched_lifetime_syntaxes)] -#![deny(no_mangle_generic_items)] #[no_mangle] pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled diff --git a/tests/ui/generics/generic-no-mangle.stderr b/tests/ui/generics/generic-no-mangle.stderr index 39fbe4dd76da1..1a4e8641133f9 100644 --- a/tests/ui/generics/generic-no-mangle.stderr +++ b/tests/ui/generics/generic-no-mangle.stderr @@ -1,19 +1,13 @@ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:6:1 + --> $DIR/generic-no-mangle.rs:4:1 | LL | #[no_mangle] | ------------ help: remove this attribute LL | pub fn foo() {} | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/generic-no-mangle.rs:3:9 - | -LL | #![deny(no_mangle_generic_items)] - | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:9:1 + --> $DIR/generic-no-mangle.rs:7:1 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -21,7 +15,7 @@ LL | pub extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:21:5 + --> $DIR/generic-no-mangle.rs:19:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -29,7 +23,7 @@ LL | pub fn foo() {} | ^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:24:5 + --> $DIR/generic-no-mangle.rs:22:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -37,7 +31,7 @@ LL | pub extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:42:5 + --> $DIR/generic-no-mangle.rs:40:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -45,7 +39,7 @@ LL | fn foo() {} | ^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:45:5 + --> $DIR/generic-no-mangle.rs:43:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -53,7 +47,7 @@ LL | extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:64:5 + --> $DIR/generic-no-mangle.rs:62:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -61,7 +55,7 @@ LL | fn foo() {} | ^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:67:5 + --> $DIR/generic-no-mangle.rs:65:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -69,7 +63,7 @@ LL | fn foo2() {} | ^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:70:5 + --> $DIR/generic-no-mangle.rs:68:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -77,7 +71,7 @@ LL | extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:73:5 + --> $DIR/generic-no-mangle.rs:71:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -85,7 +79,7 @@ LL | fn baz(x: &i32) -> &i32 { x } | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:76:5 + --> $DIR/generic-no-mangle.rs:74:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -93,7 +87,7 @@ LL | fn qux<'a>(x: &'a i32) -> &i32 { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:83:5 + --> $DIR/generic-no-mangle.rs:81:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -101,7 +95,7 @@ LL | pub fn foo() {} | ^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:86:5 + --> $DIR/generic-no-mangle.rs:84:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -109,7 +103,7 @@ LL | pub extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:89:5 + --> $DIR/generic-no-mangle.rs:87:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -117,7 +111,7 @@ LL | pub fn baz() {} | ^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:105:5 + --> $DIR/generic-no-mangle.rs:103:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -125,7 +119,7 @@ LL | fn foo() {} | ^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:108:5 + --> $DIR/generic-no-mangle.rs:106:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -133,7 +127,7 @@ LL | extern "C" fn bar() {} | ^^^^^^^^^^^^^^^^^^^ error: functions generic over types or consts must be mangled - --> $DIR/generic-no-mangle.rs:111:5 + --> $DIR/generic-no-mangle.rs:109:5 | LL | #[no_mangle] | ------------ help: remove this attribute diff --git a/tests/ui/lint/suggestions.fixed b/tests/ui/lint/suggestions.fixed index 66d097b121fbf..3dcdd865183f8 100644 --- a/tests/ui/lint/suggestions.fixed +++ b/tests/ui/lint/suggestions.fixed @@ -9,7 +9,7 @@ //~^ HELP remove this attribute pub fn defiant(_t: T) {} -//~^ WARN functions generic over types or consts must be mangled +//~^ ERROR functions generic over types or consts must be mangled #[no_mangle] fn rio_grande() {} @@ -23,7 +23,7 @@ mod badlands { //~| HELP try a static value #[allow(dead_code)] // for rustfix pub fn val_jean() {} - //~^ WARN functions generic over types or consts must be mangled + //~^ ERROR functions generic over types or consts must be mangled //~| HELP remove this attribute // ... but we can suggest just-`pub` instead of restricted @@ -32,7 +32,7 @@ mod badlands { //~| HELP try a static value #[allow(dead_code)] // for rustfix pub(crate) fn crossfield() {} - //~^ WARN functions generic over types or consts must be mangled + //~^ ERROR functions generic over types or consts must be mangled //~| HELP remove this attribute } diff --git a/tests/ui/lint/suggestions.rs b/tests/ui/lint/suggestions.rs index 2419686a8793b..5e811e23f950b 100644 --- a/tests/ui/lint/suggestions.rs +++ b/tests/ui/lint/suggestions.rs @@ -10,7 +10,7 @@ #[no_mangle] //~^ HELP remove this attribute pub fn defiant(_t: T) {} -//~^ WARN functions generic over types or consts must be mangled +//~^ ERROR functions generic over types or consts must be mangled #[no_mangle] fn rio_grande() {} @@ -24,7 +24,7 @@ mod badlands { //~| HELP try a static value #[allow(dead_code)] // for rustfix #[no_mangle] pub fn val_jean() {} - //~^ WARN functions generic over types or consts must be mangled + //~^ ERROR functions generic over types or consts must be mangled //~| HELP remove this attribute // ... but we can suggest just-`pub` instead of restricted @@ -33,7 +33,7 @@ mod badlands { //~| HELP try a static value #[allow(dead_code)] // for rustfix #[no_mangle] pub(crate) fn crossfield() {} - //~^ WARN functions generic over types or consts must be mangled + //~^ ERROR functions generic over types or consts must be mangled //~| HELP remove this attribute } diff --git a/tests/ui/lint/suggestions.stderr b/tests/ui/lint/suggestions.stderr index c6a7de51da2e6..68bf80e89e1bd 100644 --- a/tests/ui/lint/suggestions.stderr +++ b/tests/ui/lint/suggestions.stderr @@ -58,7 +58,7 @@ LL | #[no_mangle] const DISCOVERY: usize = 1; | = note: `#[deny(no_mangle_const_items)]` on by default -warning: functions generic over types or consts must be mangled +error: functions generic over types or consts must be mangled --> $DIR/suggestions.rs:12:1 | LL | #[no_mangle] @@ -66,8 +66,6 @@ LL | #[no_mangle] LL | LL | pub fn defiant(_t: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(no_mangle_generic_items)]` on by default warning: the `warp_factor:` in this pattern is redundant --> $DIR/suggestions.rs:61:23 @@ -85,7 +83,7 @@ LL | #[no_mangle] pub const DAUNTLESS: bool = true; | | | help: try a static value: `pub static` -warning: functions generic over types or consts must be mangled +error: functions generic over types or consts must be mangled --> $DIR/suggestions.rs:26:18 | LL | #[no_mangle] pub fn val_jean() {} @@ -101,7 +99,7 @@ LL | #[no_mangle] pub(crate) const VETAR: bool = true; | | | help: try a static value: `pub static` -warning: functions generic over types or consts must be mangled +error: functions generic over types or consts must be mangled --> $DIR/suggestions.rs:35:18 | LL | #[no_mangle] pub(crate) fn crossfield() {} @@ -109,5 +107,5 @@ LL | #[no_mangle] pub(crate) fn crossfield() {} | | | help: remove this attribute -error: aborting due to 3 previous errors; 8 warnings emitted +error: aborting due to 6 previous errors; 5 warnings emitted