Detect std by checking if the crate defines #[lang = "start"] rather than string comparison#1823
Conversation
| fn in_std(&self) -> bool { | ||
| let this = self.eval_context_ref(); | ||
| this.tcx.def_path(this.frame().instance.def_id()).krate | ||
| == this.tcx.def_path(this.tcx.lang_items().start_fn().unwrap()).krate |
There was a problem hiding this comment.
There may not be a #[lang = "start"] when using #![no_std] in combination with #[start], so please don't unwrap.
There was a problem hiding this comment.
There is already an unwrap() in create_ecx() 🤔
Line 113 in ef99830
There was a problem hiding this comment.
using #![no_std] in combination with #[start]
That sounds like a test case we should have, then. ;)
There was a problem hiding this comment.
using
#![no_std]in combination with#[start]
Note that it's currently broken even before the unwrap():
error: internal compiler error: src/tools/miri/src/eval.rs:110:9: main function must not take any arguments
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:1007:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.54.0-nightly (c79419af0 2021-06-04) running on x86_64-unknown-linux-gnu
Line 110 in ef99830
There was a problem hiding this comment.
Hm, the start item in Rust has no arguments so I am not sure if it makes sense to support other start items that do.
But this sounds like a separate discussion then, could you open an issue?
|
Note that the check does not have to be extremely robust. If someone wants to go out of their way to use these incomplete Miri shims, I'm fine with that, but they don't get to complain about any bugs they encounter. ;) So I'm in favor of your code changes, but I am worried about the test size blowup.^^ |
This comment has been minimized.
This comment has been minimized.
(I have removed it now, but) I added it to test that |
|
Thanks @hyd-dev :) |
|
📌 Commit 0ece55d has been approved by |
Fair -- however, it is implicitly tested in every single test, which IMO is good enough. |
|
☀️ Test successful - checks-actions |
I also considered to compare the crate name with
sym::std, but it's easy to name any cratestdby using--crate-name std, so I don't think that is robust enough.Note that this only checks the crate, it does not check whether the call is in
sys::unixorsys::windows, unlike the previous implementation, but I think it's already robust enough.Fixes #1821.