Open
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