-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: DynSized without ?DynSized — Lint against use of extern type
in size_of_val
, and more
#2310
Conversation
Tell me if I'm going crazy here, but given that...
and
the RFC's final alternative of a "post-monomorphization error" actually seems like a strong contender to me (I mean in addition to the proposed trait and/or lints, not instead of), since it seems to be the only way to make foreign types actually typesafe. Or is the proposed lint expected to be exhaustive/"actually typesafe", and the distinction between a lint and a post-monomorphization error merely academic here? |
text/0000-dyn-sized.md
Outdated
compile-time error and only affects the rare cases where foreign type is actually misused. | ||
|
||
Rust currently has no post-monomorphization lints or type errors (except [E0511] or recursion | ||
overflow). Introducing such errors marks a serious departure of this policy. |
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.
Please don't refer to errors by error codes, or the error message, but rather for the semantic reason for the error.
Also note that other than resource limits, all the post-monomorphization errors come from unstable features (mostly inline assembly and platform intrinsics, both of which shouldn't have stabilized forms that don't move the errors to earlier checks).
@kennytm, I have to say this RFC is really well written and researched. This kind of writing is painful for me, and when I write my first RFC, it's definitely going to be a lot shorter. I haven't fully read everything yet, so I'll probably add more comments later. It looks like your proposal is, basically, to still add the It seems rather complicated, but then again, most of the potential solutions, except maybe C++-style post-monomorphization errors, are fairly complicated. In RFC 1861 (extern types), @canndrew writes in the Drawbacks section:
Perhaps we should ask him what sort of implementation he had in mind 😄 |
@mikeyhew Thanks :) This proposal will add This RFC is complicated since we want to avoid default bound, i.e. This proposal does not make failing to fulfill The problem is that, as Thus we cheat by introducing Due to how epoch works, we could turn the lint into an error in the next epoch (2018). But the current epoch (2015) must still be supported, thus the |
I'm not a big fan of the need to keep that hack around forever, but the rest of the system seems good to me. I didn't like the need for the My understanding is that we are not adding post-monomorphization errors, correct? Rather we're emitting a warning for almost all callers of |
@mystor Yeah, |
Let's avoid making this decision here.
However, this also means that other libraries have no choice but do an API-breaking update by the time the lint becomes a hard error as they cannot benefit from this libstd-only hack, right? |
@RalfJung Yes, but it requires a new epoch. You could still stay in the 2015 epoch if a hard error is not wanted, but that's basically lying to yourself that "my code still works". From what I checked there isn't really a lot of public interfaces expecting DynSized, so hopefully not too many packages need to update the major version. |
Now that I've actually read this RFC properly... I don't think It falls out of specialization that we can write: trait HopefullyDynSized {}
impl<T: ?Sized> HopefullyDynSized for T {}
impl<T: ?Sized + DynSized> HopefullyDynSized for T {} Now, what if we mark the first impl as deprecated? #[deprecated(note = "how about adding a DynSized bound, dummy")]
impl<T: ?Sized> HopefullyDynSized for T {} Currently… it compiles but has no effect: the compiler doesn't seem to produce a lint in any scenario, even if the impl is used with fully concrete Relevant bug report: #39935: But ideally, rustc could lint whenever trait resolution chooses that impl during the type checking stage (as opposed to trans/monomorphization). This wouldn't require any special extra queries, 'just' linting based on something it already knows. That said, the implementation might be nontrivial: AFAICT, trait resolution currently has no lints at all, and I'm not sure whether it keeps track of which span(s) are responsible for a trait obligation, which it'd need in order to know where to attach the lint… But that's clearly a solvable problem. Then, instead of |
@comex Interesting. As you mentioned, this relies on rust-lang/rust#39935, which is also what forces us to insta-stable all new |
One thing this RFC does is double down on the idea that anything with a known size can be moved, since as long as something is |
@rfcbot fcp postpone I am going to move to postpone this RFC. At present, there is only one kind of type for which this is relevant (extern types) and even more specifically one set of functions ( This doesn't however foreclose adding a |
Team member @nikomatsakis has proposed to postpone 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 is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to postpone, as per the review above, is now complete. By the power vested in me by Rust, I hereby postpone this RFC. |
Rendered
cc #2255
cc @mikeyhew, @mystor (#1993), @withoutboats