Closed
Description
I was putting &
's here and there to make my program compile as beginners supposed to do and finally ended with:
= note: Undefined symbols for architecture arm64:
"core::ptr::drop_in_place$LT$fn$LP$$RF$$u5b$i64$u5d$$RP$$u20$.$GT$$u20$i64$GT$::h8f1379e9ceec7fb5", referenced from:
l___unnamed_1 in wyas-3cfa3c0d2101b65b.6xaszv4ay9i42ky.rcgu.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
To assure myself that this is unrelated to native/rosetta mess I've ran this in docker and in rust playground with the same outcome.
= note: /usr/bin/ld: /playground/target/release/deps/playground-7e94a1292993c003.playground.0627c30c-cgu.0.rcgu.o:(.data.rel.ro..L__unnamed_3+0x0): undefined reference to `core::ptr::drop_in_place<fn(&[i64]) -> i64>'
/usr/bin/ld: /playground/target/release/deps/playground-7e94a1292993c003: hidden symbol `_ZN4core3ptr66drop_in_place$LT$fn$LP$$RF$$u5b$i64$u5d$$RP$$u20$.$GT$$u20$i64$GT$17h8581d5a4605118bdE' isn't defined
/usr/bin/ld: final link failed: bad value
This particular code breaks the linker
struct Wrapper(fn(val: &[i64]) -> i64);
impl Debug for Wrapper {
fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Wrapper").field(&self.0 as &fn(&'a [i64]) -> i64).finish()
}
}
fn main() {
println!("{:?}", Wrapper(useful));
}
I've come up with that since deriving Debug
or implementing it manually like that
impl Debug for Wrapper {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Wrapper").field(&self.0).finish()
}
}
leads to following type/borrow check error:
implementation of
Debug
is not general enough
Expected behavior: program prints
Wrapper(address)
Actual behavior: see above
rustc --version --verbose
:
rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: aarch64-apple-darwin
release: 1.66.1
LLVM version: 15.0.2
I've tried both beta 1.67.0-beta.9
and nightly 1.68.0-nighlty
at rust playground and both are failing during linking.
Edit
I've bruteforced working program 😂 :
impl Debug for Wrapper {
fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Wrapper").field(&(self.0 as fn(&'a [i64]) -> i64)).finish()
}
}
Metadata
Metadata
Assignees
Labels
Area: Code generationCategory: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.