You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rustc can't check constness of foreign globals #9866
task '<unnamed>' failed at 'const not bound to an item', /Users/leo/Downloads/rust/src/librustc/middle/check_const.rs:269
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues
task '<unnamed>' failed at 'explicit failure', /Users/leo/Downloads/rust/src/librustc/rustc.rs:391
Shouldn't Rustc be able to compile this code ? Since the foreign global is static, it should be possible to use it in constant expressions, juste like any static declared in Rust code.
We should fail in a more graceful way, but I suspect we should still
fail. Rust statics can be evaluated at compilation time, but C statics
generally cannot, they are just memory locations basically. I guess
it's plausible that if the C library were available we could inspect
it's read-only segment in some cases, but that sounds very
complicated.
Yeah you're right.
And no, I don't think extract the value from the C library is a viable thing, the extern address could as well not be available until link-time (if it is declared in a linker script, or whatever).
I'm realizing this issue was stupid, foreign globals cannot be reliably evaluated at compile-time.
But still, the compiler should report a proper error message like "Impossible to use foreign global in a constant expression context" rather than failing.
Activity
nikomatsakis commentedon Oct 15, 2013
We should fail in a more graceful way, but I suspect we should still
fail. Rust statics can be evaluated at compilation time, but C statics
generally cannot, they are just memory locations basically. I guess
it's plausible that if the C library were available we could inspect
it's read-only segment in some cases, but that sounds very
complicated.
LeoTestard commentedon Oct 15, 2013
Yeah you're right.
And no, I don't think extract the value from the C library is a viable thing, the extern address could as well not be available until link-time (if it is declared in a linker script, or whatever).
I'm realizing this issue was stupid, foreign globals cannot be reliably evaluated at compile-time.
But still, the compiler should report a proper error message like "Impossible to use foreign global in a constant expression context" rather than failing.
huonw commentedon May 15, 2014
Closing as a dupe of the more modern #14227 (since the compiler behaviour has changed).
Auto merge of rust-lang#10001 - Jarcho:issue_9866, r=llogiq
Merge rust-lang#10126