-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
*const T has quite a few methods that seem like they don't need to require T: Sized #42847
Comments
Adding to this, std::ptr::null & std::ptr::null_mut. Technically not methods on *const T but has these bounds too. |
All inherent methods and trait impls for Following the paper trail, it appears that there may be good reason that |
Should I open a new issue to argue about extern {
type foo_t;
}
fn fake_foo_new() -> *const foo_t {
std::ptr::null()
}
|
Do mind that the conclusion drawn in the last thread I linked seemed to be that null vtable pointers (even on raw pointers) are currently considered to be UB in rust. (I'm not saying that you necessarily shouldn't; just pointing out. Maybe new facts and use cases may bring a new perspective) Edit: wow, it just occurred to me what you're showing in that example. I never realized that rust had any unsized types that use thin pointers! |
I'll be that person and ping in @dtolnay, @eddyb, and @mikeyhew for some more discussion around my last comment |
Unless there's a trait to distinguish between thin+unsized and fat+unsized pointers, we cannot relax the When the custom DST traits are included we could define fn null<T: ?Sized>() -> *const T
where
T::Meta: Default,
{
/* assemble a custom DST from { ptr = 0, meta = T::Meta::default() } */
} |
I can certainly see that a null vtable would be a bad thing, but I also feel that the complete inability to create a #![feature(extern_types)]
extern {
type foo_t;
fn foo_init(f: *mut foo_t);
}
fn main() {
let mut a = std::mem::uninitialized();
unsafe { foo_init(&mut a) };
}
Edit — that was a dumb example because of course #![feature(extern_types)]
extern "C" {
type foo_t;
fn foo_init(f: *mut *mut foo_t);
}
fn main() {
unsafe {
let mut a = std::mem::uninitialized();
foo_init(&mut a);
}
} The corresponding equivalent with #![feature(extern_types)]
extern "C" {
type foo_t;
fn foo_init(f: *mut *mut foo_t);
}
fn main() {
unsafe {
let mut a = std::ptr::null_mut();
foo_init(&mut a);
}
}
|
As a workaround for now you can get a null pointer to extern type through #![feature(extern_types)]
extern "C" {
type foo_t;
fn foo_take_null(f: *mut foo_t);
}
fn main() {
let a = 0 as *mut foo_t;
unsafe {
foo_take_null(a);
}
} |
We should add a private/unstable marker trait and use it to add a bound that's weaker than It should be directly equivalent to cc @retep998 |
Is RFC 2580 (implementation PR: #81172) add public APIs for pointer metadata and a Building on top of that, I hoped that fixing this issue would be as simple as -pub const fn null<T>() -> *const T {
+pub const fn null<T: ?Sized + Thin>() -> *const T {
-pub const fn null_mut<T>() -> *mut T {
+pub const fn null_mut<T: ?Sized + Thin>() -> *mut T { However this gives two kinds of errors when compiling libcore:
|
I hope we can do |
|
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
Related: |
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
To see what changes we'd have to make in the library to use `extern type` (RFC-1861) (when it's is stabilized). Unfortunately had to change some usage of `ptr::null[_mut]` to `0 as *const/mut X`, see rust-lang/rust#42847.
Not sure which exactly, but we should evaluate and relax bounds where possible.
See also #24794, #36952.
The text was updated successfully, but these errors were encountered: