-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-linkage#![feature(linkage)]`#![feature(linkage)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I'm trying to define a "weak" const in a library, which allows users to redefine their const. On stable Rust, there's no way to do it. On nightly, linkage
feature seems the solution, but I found that it doesn't work as well. The following is the repro code:
// In library code:
#![feature(linkage)]
#[linkage = "weak"]
#[no_mangle]
const fn get_foo() -> i32 {
0
}
pub const FOO: i32 = get_foo();
pub fn hello() {
println!("hello: {}, {}", FOO, get_foo());
}
// In application code:
use linkage_weak_bug::hello;
#[no_mangle]
const fn get_foo() -> i32 {
1
}
fn main() {
// Output: hello: 0, 1
// Expected: hello: 1, 1
hello();
}
I uploaded a repo that could repro it: https://github.com/HaoboGu/linkage_weak_bug
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-linkage#![feature(linkage)]`#![feature(linkage)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.