Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for type_id stabilization #27745
Comments
aturon
added
T-libs
B-unstable
labels
Aug 12, 2015
Ms2ger
referenced this issue
Aug 16, 2015
Open
Tracking: Unstable Rust feature gates used by Servo #5286
This comment has been minimized.
This comment has been minimized.
|
It was pointed out it's one of the very few methods to be named with |
This comment has been minimized.
This comment has been minimized.
|
I suspect this is just some very old convention that wasn't updated during stabilization (since we didn't stabilize this API). |
This comment has been minimized.
This comment has been minimized.
flosse
commented
Jul 25, 2016
|
Any progress here? |
This comment has been minimized.
This comment has been minimized.
Zaerei
commented
Aug 11, 2016
|
I tried to tackle it, but it looks like the main problem is that (Though making an extern function const is probably dicey from a compiler perspective anyway, I'm not an expert on that). |
aturon
added
the
I-nominated
label
Aug 29, 2016
This comment has been minimized.
This comment has been minimized.
|
Removing nomination as this was an accidental mistake about what this issue was about. |
alexcrichton
removed
the
I-nominated
label
Sep 12, 2016
This comment has been minimized.
This comment has been minimized.
|
Any update on this? Is is discouraged to use it in current code? |
This comment has been minimized.
This comment has been minimized.
jweinst1
commented
Apr 9, 2017
|
Is there any other way to do reflection or dynamic typing that will work? |
This comment has been minimized.
This comment has been minimized.
|
@jweinst1 the rest of the fn is<T>(&self) -> bool where T: Any;
fn downcast_ref<T>(&self) -> Option<&T> where T: Any;
fn downcast_mut<T>(&mut self) -> Option<&mut T> where T: Any;
fn downcast<T>(Box<self>) -> Result<Box<T>, Box<Any>> where T: Any ;In each of these the call site is specifying a specific |
This comment has been minimized.
This comment has been minimized.
|
I’ve just realized that |
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I propose we make Once that's done, we can add a constant to @SimonSapin I don't think it's that easy since there exist methods in the wild that pass around trait objects ( |
This comment has been minimized.
This comment has been minimized.
|
It might be better off as an associated constant if possible. |
This comment has been minimized.
This comment has been minimized.
|
I might not be understanding, but I think that's what I suggested? That we have something like |
This comment has been minimized.
This comment has been minimized.
|
Oh right derp, there isn't anywhere to put the constant on TypeId itself since it isn't parameterized. |
This comment has been minimized.
This comment has been minimized.
|
Alright, I'm working on this and I think I managed to turn Edit: I solved the mistery, the const needs to be inserted in the |
This comment has been minimized.
This comment has been minimized.
|
I wonder if #10389 is relevant here |
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Feb 4, 2018
This comment has been minimized.
This comment has been minimized.
|
It turns out that associated constants cannot be used in trait objects, because the constants aren't stored in the vtable. So this won't work: trait Any {
const TYPE_ID: TypeId = TypeId::of::<Self>();
}And this also won't work, because it just stores the trait Any {}
impl Any {
const TYPE_ID: TypeId = TypeId::of::<Self>();
}So assuming we still want to make TYPE_ID an associated constant, we need to add support for associated constants in trait objects, or make this a special case and add a dedicated field to the vtable which stores the |
This comment has been minimized.
This comment has been minimized.
I think this wouldn’t work? This code: fn foo(object: &Any) {
let type_id = object.get_type_id();
}… can call a trait method from a trait object. Accessing an associated constant would be Other code that does have a concrete So I propose keeping this method as a method, renaming to |
This comment has been minimized.
This comment has been minimized.
|
That seems reasonable. |
This comment has been minimized.
This comment has been minimized.
@rfcbot fcp merge |
rfcbot
added
the
proposed-final-comment-period
label
Mar 17, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 17, 2018
•
|
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
Seems like we might as well make it a const method while we're stabilizing it. It should be pretty trivial since |
This comment has been minimized.
This comment has been minimized.
It’s fine that those implementation details exist, but we should be clear about what items are in that category as opposed to features that are not stable yet but have some path to stabilization. Perma-unstable implementation details have The existence of this open tracking issue indicates that there is something to be tracked. Closing it and deciding that |
This comment has been minimized.
This comment has been minimized.
|
Hm? Did rfcbot not register the concern here? I thought it normally edits those into its post. |
This comment has been minimized.
This comment has been minimized.
Unfortunate timing, considering a new syntax will be introduced for them. This would otherwise be a good opportunity to introduce small breaking changes to behavior. But I guess that's off topic here. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 28, 2018
|
The final comment period is now complete. |
tmccombs
added a commit
to tmccombs/rust
that referenced
this issue
Apr 3, 2018
This comment has been minimized.
This comment has been minimized.
Are there any plans to implement this, or RFCs that specify that? |
This comment has been minimized.
This comment has been minimized.
That's the exact motivation for stabilising this: as a trait method it is directly callable on trait objects extending This issue is even directly linked from comments in the We should stabilize this as-is - I don't see how performance is a concern since we already have |
leodasvacas
added a commit
to leodasvacas/rust
that referenced
this issue
May 22, 2018
Centril
added
disposition-merge
finished-final-comment-period
and removed
final-comment-period
labels
May 24, 2018
This comment has been minimized.
This comment has been minimized.
From #49613 (comment) @Centril should this have the See also, #27745 (comment) |
This comment has been minimized.
This comment has been minimized.
|
@tmccombs unclear; I defer to @rust-lang/libs |
0xazure
referenced this issue
Nov 20, 2018
Open
Lint `set_*` and `get_*` methods that do nothing but access the field #1673
This comment has been minimized.
This comment has been minimized.
|
How likely is this to be stabilized? Will the |
SimonSapin
added a commit
to SimonSapin/rust
that referenced
this issue
Jan 22, 2019
SimonSapin
referenced this issue
Jan 22, 2019
Merged
Stabilize Any::get_type_id and rename to type_id #57834
This comment has been minimized.
This comment has been minimized.
|
Very, since FCP to stabilize is done. Yes, since that’s was part of the FCP proposal. Stabilization PR: #57834 |
Centril
added a commit
to Centril/rust
that referenced
this issue
Jan 23, 2019
bors
closed this
in
5749bac
Jan 24, 2019
This comment has been minimized.
This comment has been minimized.
|
Thank you @SimonSapin. I wasn't sure since the FCP was months ago. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, sometimes we just forget to follow up. Pinging open issues like you did can help, thanks! |
aturon commentedAug 12, 2015
The method
get_type_idinAnyis intended to support reflection. It's currently unstable in favor of using an associated constant instead.