Open
Description
Based on discussion on #43467 and in @rust-lang/lang meetings, an opaque extern type
type cannot support size_of_val
or align_of_val
. We believe that we should panic or abort in this case. We also believe that we should have a compile-time lint that detects this whenever possible, since at some level the compiler should know at compile time if code invokes size_of_val
or align_of_val
on an extern type
.
I've opened this separate issue to document that decision, and will propose FCP on it to give time for final comments.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
joshtriplett commentedon Apr 5, 2018
@rfcbot fcp merge
rfcbot commentedon Apr 5, 2018
Team member @joshtriplett 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.
kennytm commentedon Apr 5, 2018
will the lint be emitted before or after monomorphization?
P.S. cc rust-lang/rfcs#2310
eddyb commentedon Apr 5, 2018
I'm specifically in favor of "before", only emitting anything after monomorphization under some general umbrella of "this code will always panic at runtime" warnings.
joshtriplett commentedon Apr 5, 2018
It would be nice to handle generic functions that get monomorphized with an
extern type
, though. That will come up.hanna-kruppe commentedon Apr 5, 2018
The RFC text (and the discussion even more so, IIRC) mention the possibility of adding a new trait for encoding this constraint. I assume this has been dropped because that trait would have to be included in bounds by default like
Sized
?Ericson2314 commentedon Apr 6, 2018
@rkruppe yes sadly.... rust-lang/rfcs#2310 was opened as backup plan. See the end of #43467.
comex commentedon Apr 6, 2018
I'm a bit confused why this is in rust-lang/rust instead of rust-lang/rfcs. (I have rust-lang/rfcs set as watched, so I get email copies of all issues and PRs there, but not here.)
joshtriplett commentedon Apr 6, 2018
Because it's a bug about
extern type
behavior.nikomatsakis commentedon Apr 10, 2018
@comex
Because this is not a new RFC, it's nailing down a specific unresolved question around extern types (though we should have linked from the tracking issue to here -- fixed). This is pretty standard practice.
jethrogb commentedon Apr 10, 2018
Why lint when you can have type safety? Two convincing comments from the other discussion thread:
@mikeyhew #43467 (comment)
@Ericson2314 #43467 (comment)
And my own perspective: there are various places where I'd like to be generic over things that the language doesn't allow. That goes hand in hand with the type system. For example, you can't be generic over lengths when using arrays or calling conventions when using function pointers. Let's not add more features in that could reasonably be described correctly in the type system but aren't.
joshtriplett commentedon Apr 10, 2018
@jethrogb
If the lint is deny-by-default (which I think it should be), it'd effectively act the same as a type error. The second comment you quote seems based on the idea that it'd be a warning and not an error.
So the only difference is whether to provide a more general trait-based mechanism or to handle the specific case at hand. I haven't seen any fundamental opposition to the idea of introducing those traits in the future if we have a more general case that needs them, but if we want those traits for some future features that we haven't yet introduced to the language, let's design those traits alongside those future language features.
68 remaining items