diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index dd56b13cb2f5e..464c3366a4302 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -54,11 +54,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, LintContext}; @@ -870,36 +870,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( @@ -910,11 +881,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::diagnostics::BuiltinNoMangleGeneric { + span: cx.tcx.def_span(def_id), + suggestion: attr_span, + }); } } } @@ -1553,7 +1523,6 @@ pub mod soft { 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/diagnostics.rs b/compiler/rustc_lint/src/diagnostics.rs index 8fec30816bd13..37aa7bccc6745 100644 --- a/compiler/rustc_lint/src/diagnostics.rs +++ b/compiler/rustc_lint/src/diagnostics.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 244db06a11d60..b10269d2315c6 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -695,6 +695,11 @@ fn register_builtins(store: &mut LintStore) { "converted into hard error, \ see for more information", ); + 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 d7852fc0e4f69..d57363bac7c9e 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -225,20 +225,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/src/helpers.rs b/src/tools/miri/src/helpers.rs index 8dc6b5f07b92e..6953a27a39df8 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -132,15 +132,7 @@ pub fn iter_exported_symbols<'tcx>( if !(used || codegen_attrs.contains_extern_indicator()) { continue; } - // FIXME: `#[no_mangle]` makes no sense on a generic item, but still causes it to be - // considered "extern". Remove this once `no_mangle_generic_items` is a hard error. - let mono = { - let generics = tcx.generics_of(def_id); - !generics.requires_monomorphization(tcx) - }; - if mono { - f(LOCAL_CRATE, def_id.into(), used)?; - } + f(LOCAL_CRATE, def_id.into(), used)?; } // Next, all our dependencies. 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..ab0fa8f013968 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. @@ -14,10 +14,6 @@ pub struct NoMangleStruct; #[export_name = "NoMangleStruct"] fn no_mangle_struct() {} -// `#[no_mangle]` on a generic function can also cause ICEs. -#[no_mangle] -fn no_mangle_generic() {} - -// Same as `no_mangle_struct()` but for the `no_mangle_generic()` generic function. -#[export_name = "no_mangle_generic"] -fn no_mangle_generic2() {} +// Same as `no_mangle_struct()` but for the `no_mangle_struct()` function. +#[export_name = "no_mangle_struct"] +fn no_mangle_alias() {} diff --git a/src/tools/miri/test-cargo-miri/src/main.rs b/src/tools/miri/test-cargo-miri/src/main.rs index 1568da43afe30..ed16a14e3d60f 100644 --- a/src/tools/miri/test-cargo-miri/src/main.rs +++ b/src/tools/miri/test-cargo-miri/src/main.rs @@ -87,13 +87,13 @@ mod test { fn assoc_fn_as_exported_symbol() -> i32; fn make_true() -> bool; fn NoMangleStruct(); - fn no_mangle_generic(); + fn no_mangle_struct(); } assert_eq!(unsafe { exported_symbol() }, 123456); assert_eq!(unsafe { assoc_fn_as_exported_symbol() }, -123456); assert!(unsafe { make_true() }); unsafe { NoMangleStruct() } - unsafe { no_mangle_generic() } + unsafe { no_mangle_struct() } } } diff --git a/src/tools/miri/tests/pass/issues/issue-154385-no-mangle-generic.rs b/src/tools/miri/tests/pass/issues/issue-154385-no-mangle-generic.rs deleted file mode 100644 index 90fa021863990..0000000000000 --- a/src/tools/miri/tests/pass/issues/issue-154385-no-mangle-generic.rs +++ /dev/null @@ -1,22 +0,0 @@ -fn main() { - generic_type(123); - generic_const::<456>(); - generic_lifetime(&789); -} - -#[allow(no_mangle_generic_items)] -#[unsafe(no_mangle)] -fn generic_type(value: T) { - println!("{value:?}"); -} - -#[expect(no_mangle_generic_items)] -#[unsafe(no_mangle)] -fn generic_const() { - println!("{N}"); -} - -#[unsafe(no_mangle)] -fn generic_lifetime<'a>(x: &'a i32) { - println!("{x}"); -} diff --git a/src/tools/miri/tests/pass/issues/issue-154385-no-mangle-generic.stdout b/src/tools/miri/tests/pass/issues/issue-154385-no-mangle-generic.stdout deleted file mode 100644 index af7864ba2f038..0000000000000 --- a/src/tools/miri/tests/pass/issues/issue-154385-no-mangle-generic.stdout +++ /dev/null @@ -1,3 +0,0 @@ -123 -456 -789 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 a9d555feb86b3..993632ea1a112 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 backtrace_with_baz_in_it(mut cb: F, data: u32) where F: FnMut(u32) { cb(data); } -#[no_mangle] pub fn backtrace_with_bar_in_it(cb: F, data: u32) where F: FnMut(u32) { backtrace_with_baz_in_it(cb, data); } -#[no_mangle] pub fn backtrace_with_foo_in_it(cb: F, data: u32) where F: FnMut(u32) { backtrace_with_bar_in_it(cb, data); } diff --git a/tests/ui/backtrace/line-tables-only.rs b/tests/ui/backtrace/line-tables-only.rs index 320ad93393c71..33d5774079d94 100644 --- a/tests/ui/backtrace/line-tables-only.rs +++ b/tests/ui/backtrace/line-tables-only.rs @@ -32,9 +32,7 @@ fn assert_contains( expected_line: u32, ) { // The formatted frames look like this: - // `{ fn: "backtrace_with_baz_in_it", file: ".../tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 5 }` - // or this: - // `{ fn: "line_tables_only_helper::backtrace_with_baz_in_it", file: "...\tests\ui\backtrace\auxiliary\line-tables-only-helper.rs", line: 5 },` + // `{ fn: "line_tables_only_helper::backtrace_with_baz_in_it::", file: ".../tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 4 }, // Make sure we match the right part when searching for the function name and line number. let expected_line_str = format!("line: {expected_line} "); eprintln!("{:#?}", backtrace); @@ -63,8 +61,8 @@ fn main() { // And with #143208 we also lost `bar` in the line tables. #[cfg(not(all(target_pointer_width = "32", target_env = "msvc")))] { - assert_contains(&backtrace, "backtrace_with_foo_in_it", "line-tables-only-helper.rs", 15); - assert_contains(&backtrace, "backtrace_with_bar_in_it", "line-tables-only-helper.rs", 10); + assert_contains(&backtrace, "backtrace_with_foo_in_it", "line-tables-only-helper.rs", 12); + assert_contains(&backtrace, "backtrace_with_bar_in_it", "line-tables-only-helper.rs", 8); } - assert_contains(&backtrace, "backtrace_with_baz_in_it", "line-tables-only-helper.rs", 5); + assert_contains(&backtrace, "backtrace_with_baz_in_it", "line-tables-only-helper.rs", 4); } 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..b3313538a9905 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 @@ -14,6 +12,9 @@ pub fn baz(x: &i32) -> &i32 { x } #[no_mangle] pub fn qux<'a>(x: &'a i32) -> &i32 { x } +#[no_mangle] +pub fn generic_const() {} //~ ERROR functions generic over types or consts must be mangled + pub struct Foo; impl Foo { diff --git a/tests/ui/generics/generic-no-mangle.stderr b/tests/ui/generics/generic-no-mangle.stderr index 39fbe4dd76da1..4b267d0dcc55f 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,15 @@ 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:16:1 + | +LL | #[no_mangle] + | ------------ help: remove this attribute +LL | pub fn generic_const() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: functions generic over types or consts must be mangled + --> $DIR/generic-no-mangle.rs:22:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -29,7 +31,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:25:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -37,7 +39,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:43:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -45,7 +47,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:46:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -53,7 +55,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:65:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -61,7 +63,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:68:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -69,7 +71,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:71:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -77,7 +79,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:74:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -85,7 +87,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:77:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -93,7 +95,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:84:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -101,7 +103,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:87:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -109,7 +111,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:90:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -117,7 +119,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:106:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -125,7 +127,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:109:5 | LL | #[no_mangle] | ------------ help: remove this attribute @@ -133,12 +135,12 @@ 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:112:5 | LL | #[no_mangle] | ------------ help: remove this attribute LL | fn baz() {} | ^^^^^^^^^^^ -error: aborting due to 17 previous errors +error: aborting due to 18 previous errors diff --git a/tests/ui/lint/suggestions.fixed b/tests/ui/lint/suggestions.fixed index 698cc3f34499f..6fd991e60d4c4 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 6e4c389a9c8c2..c2d422828649a 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