-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made fail_bounds_check more careful with strings. #12357
Made fail_bounds_check more careful with strings. #12357
Conversation
msg.with_c_str(|buf| fail_(buf as *u8, file, line)) | ||
|
||
#[inline] | ||
fn c_str_to_static(cs: CString) -> &'static str { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need a separate function? Can't it be
let file_str = match unsafe {CString::new(file as *c_char, false)}.as_str() {
Some(s) => ...,
None => ...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's much better! (Thanks for teaching me a new idiom.)
General question (not necessarily to @chromatic): is there a reason we can't emit the file names as |
#[inline] | ||
fn c_str_to_static(cs: CString) -> &'static str { | ||
match cs.as_str() { | ||
Some(s) => unsafe { cast::transmute::<&str, &'static str>(s) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment for why this transmute is safe? Something along the lines of how the file
is stored in rodata which is indeed static.
We could certainly do that, I thought we had an issue open on that, but I can't seem to find it... |
(I opened #12378 about avoiding |
fix: When reference searching macro inputs, don't search everything that was downmapped Fixes rust-lang/rust-analyzer#11668
Fixes #11976.