Re:Memory Safe Languages in Android 13
by optymizer on Thursday December 01, 2022 @03:41PM
(#33822410)
what if there's no static function with that name?
[ Parent
| on HN ]
Re:Memory Safe Languages in Android 13
by masklinn on Thursday December 01, 2022 @04:18PM
(#33822907)
There is since that's what you declared.
impl Foo {
// static
fn foo() {}
}
impl Foo {
// instance, owned
fn foo(self) {}
}
impl Foo {
// instance, borrowed
fn foo(&self) {}
}
impl Foo {
// instance, boxed
fn foo(self: Box<Self>) {}
}
impl Foo {
// instance, refcounted <strike>(currently nightly, arbitrary_self_types)</strike>
// actually stable, alonside Arc, and Pin, it's other things which
// Deref<Target=Self> which require arbitrary self types
fn foo(self: Rc<Self>) {}
}
Re:Memory Safe Languages in Android 13
by phaylon on Thursday December 01, 2022 @04:27PM
(#33823040)
Small nitpick: Fortunately, `Rc` and `Arc` actually don't require the nightly feature.
Re:Memory Safe Languages in Android 13
by masklinn on Thursday December 01, 2022 @04:31PM
(#33823100)
Oh yeah you're right that's been stabilised, now that I'm thinking about it, it was probably something like `self: std::sync::MutexGuard<'_, Self>` which told me to enable the feature
Re:Memory Safe Languages in Android 13
by optymizer on Sunday December 04, 2022 @05:02PM
(#33858435)
Again, what if there is no static declaration?
impl Foo {
// static
fn foo() {}
}
Why would I need to use self to tell the compiler about an instance method? Surely the Rust compiler is smart enough to detect this case and complain if the call site is ambiguous.
Re:Memory Safe Languages in Android 13
by masklinn on Wednesday December 07, 2022 @02:13AM
(#33891566)
> Again, what if there is no static declaration?
So your suggestion is to remove static methods from the language?
> Why would I need to use self to tell the compiler about an instance method? Surely the Rust compiler is smart enough to detect this case and complain if the call site is ambiguous.
Detect what case? There is a dozen and eventually an infinite number of potential instance call ABIs.
And the Rust compiler is generally very much on the “refuse to guess” side of the fence (hence no global type inference), so you have to tell it what it should expect, `self`, `&mut self`, and `&self` have rather different requirements, impacts, and capabilities to say nothing of the rest.