Skip to content

treat no_mangle_generic_items as hard error instead of lint warning#154585

Open
HerrCai0907 wants to merge 2 commits into
rust-lang:mainfrom
HerrCai0907:fix/no_mangle_generic_items
Open

treat no_mangle_generic_items as hard error instead of lint warning#154585
HerrCai0907 wants to merge 2 commits into
rust-lang:mainfrom
HerrCai0907:fix/no_mangle_generic_items

Conversation

@HerrCai0907

@HerrCai0907 HerrCai0907 commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

View all comments

In rust-lang/miri#4929 (comment), rustc should reject the no_mangled generic function.
This PR treat is as a hard error

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2026
@rustbot

This comment was marked as outdated.

@HerrCai0907

Copy link
Copy Markdown
Contributor Author

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned fmease Mar 30, 2026
@rustbot

rustbot commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@fmease fmease added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Mar 30, 2026
@oli-obk

oli-obk commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Please make it a hard error and not a lint at all if crater doesn't show any significant regressions.

For crater purposes this works.

@rust-bors

This comment was marked as off-topic.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2026
@oli-obk

This comment was marked as off-topic.

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 30, 2026
@oli-obk

oli-obk commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 30, 2026
set no_mangle_generic_items deny by default
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ac4c361 (ac4c3613be2acd5395b65d85e5657b81e3c982f0, parent: 4cf5f9580233c36f6bc8db76e282ba8a1c1ea491)

@oli-obk

oli-obk commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-154585 created and queued.
🤖 Automatically detected try build ac4c361
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 30, 2026
@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-154585 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-154585 is completed!
📊 5 regressed and 2 fixed (871888 total)
📊 5110 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-154585/retry-regressed-list.txt

@craterbot craterbot removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Apr 6, 2026
@craterbot craterbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2026
@oli-obk

oli-obk commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

I reached out to the jni-mangle author, who used a generic function with no_mangle in a test file, but never actually called it (it wouldn't mangle anyway).

The rxdp failure is because (while there are no generics involved in the function signature) the body uses the generic parameter T from the impl block. (well the failure happens regardless of use in the body, but that's why the functions can't be free functions). I opened a PR to fix it, but the crate also has no dependents, no release in 5 years and the last change to the repo was 3 years ago.

So, let's turn this lint into a hard error. Then we need to write an explainer for T-lang and then we can nominate it.

@oli-obk oli-obk added T-lang Relevant to the language team S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 8, 2026
@rustbot

rustbot commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[endgroup]
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
PR_CI_JOB set; skipping tidy
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
---
failures:

---- [ui] tests/ui/backtrace/line-tables-only.rs stdout ----

error: test did not exit with success! code=Some(101) so test would pass with `run-fail`
status: exit status: 101
command: cd "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/backtrace/line-tables-only" && RUSTC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" RUST_TEST_THREADS="4" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/backtrace/line-tables-only/a"
stdout: none
--- stderr -------------------------------
Backtrace [
    { fn: "<std::backtrace::Backtrace>::create" },
    { fn: "line_tables_only_helper::capture_backtrace::{closure#0}", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 17 },
    { fn: "line_tables_only_helper::baz::<line_tables_only_helper::capture_backtrace::{closure#0}>", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 4 },
    { fn: "line_tables_only_helper::bar::<line_tables_only_helper::capture_backtrace::{closure#0}>", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 8 },
    { fn: "line_tables_only_helper::foo::<line_tables_only_helper::capture_backtrace::{closure#0}>", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 12 },
    { fn: "capture_backtrace", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 17 },
    { fn: "main", file: "/checkout/tests/ui/backtrace/line-tables-only.rs", line: 43 },
    { fn: "call_once<fn(), ()>", file: "/rustc/FAKE_PREFIX/library/core/src/ops/function.rs", line: 250 },
    { fn: "__rust_begin_short_backtrace<fn(), ()>", file: "/rustc/FAKE_PREFIX/library/std/src/sys/backtrace.rs", line: 166 },
    { fn: "std::rt::lang_start::<()>::{closure#0}", file: "/rustc/FAKE_PREFIX/library/std/src/rt.rs", line: 206 },
    { fn: "std::rt::lang_start_internal" },
    { fn: "main" },
    { fn: "__libc_start_main" },
    { fn: "_start" },
]
Backtrace [
    { fn: "<std::backtrace::Backtrace>::create" },
    { fn: "line_tables_only_helper::capture_backtrace::{closure#0}", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 17 },
    { fn: "line_tables_only_helper::baz::<line_tables_only_helper::capture_backtrace::{closure#0}>", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 4 },
    { fn: "line_tables_only_helper::bar::<line_tables_only_helper::capture_backtrace::{closure#0}>", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 8 },
    { fn: "line_tables_only_helper::foo::<line_tables_only_helper::capture_backtrace::{closure#0}>", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 12 },
    { fn: "capture_backtrace", file: "/checkout/tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 17 },
    { fn: "main", file: "/checkout/tests/ui/backtrace/line-tables-only.rs", line: 43 },
    { fn: "call_once<fn(), ()>", file: "/rustc/FAKE_PREFIX/library/core/src/ops/function.rs", line: 250 },
    { fn: "__rust_begin_short_backtrace<fn(), ()>", file: "/rustc/FAKE_PREFIX/library/std/src/sys/backtrace.rs", line: 166 },
    { fn: "std::rt::lang_start::<()>::{closure#0}", file: "/rustc/FAKE_PREFIX/library/std/src/rt.rs", line: 206 },
    { fn: "std::rt::lang_start_internal" },
    { fn: "main" },
    { fn: "__libc_start_main" },
    { fn: "_start" },
]

thread 'main' (36099) panicked at /checkout/tests/ui/backtrace/line-tables-only.rs:38:5:
backtrace does not contain expected line 11
stack backtrace:

Comment thread src/tools/miri/test-cargo-miri/issue-rust-86261/src/lib.rs
@HerrCai0907 HerrCai0907 changed the title set no_mangle_generic_items deny by default treat no_mangle_generic_items as hard error instead of lint warning Apr 25, 2026
@rust-bors

rust-bors Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #156794) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung

Copy link
Copy Markdown
Member

Nominating for @rust-lang/lang:

The no_mangle_generic_items lint was added 10 years ago (#30269) to lint against no_mangle attributes on generic items, which fundamentally make no sense. I am not sure why it was not made an FCW; I suspect the FCW machinery did not even exist yet back then. Anyway it is high time that we move towards erroring on such nonsensical code:

#[no_mangle]
fn no_mangle_generic<T>() {}

A crater run showed only 3 true regressions, 2 of them on crates.io:

  • rxdp has been fixed. No new release has been made but the crate is also basically unused.
  • jni-mangle has been fixed, and then the repo has been archived. Also basically an unused crate.

So we suggest that we skip the FCW stage and immediately move to a hard error here.

@RalfJung RalfJung added I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-t-lang Status: Awaiting decision from T-lang labels Jun 24, 2026
Comment on lines +49 to +52
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);

@RalfJung RalfJung Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 12);
}
assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 8);
assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 4);

That's based on the CI messages, I'd suggest running the tests locally though.

View changes since the review

@traviscross traviscross added I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Jun 25, 2026
@traviscross

Copy link
Copy Markdown
Contributor

Makes sense to me. Thanks @HerrCai0907, @oli-obk, and @RalfJung. I propose we make this a hard error and accept this (minimal) observed breakage.

@rfcbot fcp merge lang

@rust-rfcbot

rust-rfcbot commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. and removed needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Jun 25, 2026
@ehuss

ehuss commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

There is a waiting docs PR at rust-lang/reference#1904. Am I correct that the new rule should state the following?

r[abi.no_mangle.generic]
It is an error to use `no_mangle` on an item with generic type or constant parameters.

@RalfJung

Copy link
Copy Markdown
Member

Yes that sounds right. (Though IMO the reference should list where the attribute is allowed, not where it is forbidden.)

@traviscross traviscross added the needs-reference-pr This language change needs an approved Reference PR to proceed. label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-reference-pr This language change needs an approved Reference PR to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-t-lang Status: Awaiting decision from T-lang T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants