-
Notifications
You must be signed in to change notification settings - Fork 13k
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
stabilize dyn Trait
in Rust 2015
#49218
Comments
cc @petrochenkov, who implemented, and @Manishearth, who has been working on lint etc |
@rfcbot fcp merge I propose that we stabilize the Rust 2015 behavior of |
Team member @nikomatsakis 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. |
(Here is a question to ponder, that does not I think block stabilization: for Rust 2018, is it working making |
This isn't consistent -- Though it seems like you're suggesting that we could scope the epoch breakage so that I do think that contextual keywords should eventually become true keywords and we're well poised to just make it a keyword with the epoch, so idk. |
I am proposing not making it parse differently. It currently parses as a path
As I wrote above, I am proposing that
This is an interesting policy question. Some cases, like |
I noticed something: in our error messages, we don't use |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I wonder if by stabilizing the new syntax with the exact same semantics as the old one we are not missing an opportunity to make small semantic changes without breaking existing code? I don't have any such changes in mind, it's just a thought. |
The final comment period is now complete. |
@leodasvacas I have wondered the same thing. Occasionally I dream about making |
The final comment period is up, let's do this! There are general instructions on how to stabilize a feature given here: https://forge.rust-lang.org/stabilization-guide.html In this case, the feature name in question is |
I'd like to take care of the stabilization PR :) |
@christianpoveda encountered a question (we were discussing on IRC) that I didn't know the answer to. @Manishearth maybe you can help. Right now, the rust/src/librustc/hir/lowering.rs Lines 4090 to 4100 in eec3208
However, I believe that we would prefer this lint to be gated on the edition that is in use. @Manishearth how should we tweak this line? |
What's the reasoning behind that? If dyn trait is going to exist on both epochs, no need to gate the lint, yes?. (Also, this isn't a future compat lint anymore) |
True, we could just enable the lint (but make it not future-compat). My assumption though was that we didn't want to be quite so forceful in terms of nagging people to convert their code, at least until Edition 2018 (or until they opt into the 2018 transition lints). Maybe others feel differently. |
Ah. Well, in that case I can make it such that the lint always exists but is Allow on 2015? We have EpochDeny, I can add EpochWarn. |
cc @rust-lang/lang -- I'd like to hear from others. Do we think that we ought to warn by default in Edition 2015 regarding the My inclination for now is to take it slow. We can always add in such warnings later. But maybe I'm being too cautious. Among other things, though, I am reluctant to unleash an avalanche of warnings before the |
Come to think of it, the original plan was that we enable |
@Manishearth right -- so what are the concrete steps that @christianpoveda should take? It seems like we should always emit the lint, but we should modify its definition to be "allow by default", right? (Poking at the code, I'm finding it a bit confusing actually -- I can't tell where/how the "priority" of this lint gets upgraded from Allow...) |
The lint is currently always-allow and it should stay that way for now. Christian just needs to remove the feature gate in the lint. Making it EpochWarn or EpochDeny can be done later as y'all decide what we actually want to do here. |
I had assumed that we would just always leave |
rust/src/librustc/lint/builtin.rs Line 253 in eec3208
|
…komatsakis Stabilize dyn trait This PR stabilizes RFC 2113. I followed the [stabilization guide](https://forge.rust-lang.org/stabilization-guide.html). Related issue: rust-lang#49218
Closed by #49968 |
I realise this decision was made a long time ago, but do me In the future could we please be more cautious about deprecating previously-valid code in an existing epoch? |
It's just as valid of code in 2018 as it is in 2018-- the warning and the new syntax aren't edition-related. |
The syntax is valid, but the deprecation is another matter. If |
I don't agree with this. The syntax is not a hard error in either edition. It is a warning in both editions. It is not an edition-related feature or change. |
It is edition-related since only E2018 implemented this properly (with a new keyword). Since this discussion was already happening way before E2018 was a thing, I don't understand why But my point is more that breaking changes are not expected in an existing edition, and the purpose of default lints is to point out real issues (e.g. So I ask again: is there any plan to make this a hard error within Edition 2015 (bearing in mind that any code still using E2015 is obviously not being updated for some reason)? Because if not, this deprecation warning has no raison d'être (though it would not be out of place in Clippy, phrased as a "recommended style" or some such). |
This warning seems to affect the majority of 2015 crates, e.g. when looking through crater logs the walls of |
I don't agree with the reasoning that we should never add new lints unless things are being deprecated to the point of being removed. This is a form of deprecation, just one where we don't intend to remove support for the syntax. I don't see an issue with the scale of the warnings. These are easy to fix with rustfix. If lots of people see them it's no big deal, this happens with other kinds of new warnings reasonably often as well (we had a bunch with |
This assumes one intends to modify the code in question, and do so immediately. At the end of the day we can live with this, but from my POV the nuisance out-weighs the benefit. |
No, it doesn't, it's a warning, you can also choose to not fix it. |
This is technically true but does not account for the fact that deprecation warnings carry a lot of psychological pressure to fix them (which is also why they work in the first place). |
If someone is the type of programmer who feels compelled to fix all warnings, then I believe they should also want new warnings to be enabled that would help improve their code. If they don't believe following the warning improves their code, it's easy to disable the warning. |
Indeed, and the key part is "their code". To quote @dhardy:
|
I think most of this was already settled by the Editions RFC and the dyn Trait RFCs, and we're almost reiterating discussions that have already happened, but I also think there's a valid point buried under the confusion. First, the relevant part of the Editions RFC:
The relevant part of the dyn Trait RFC:
In particular, some of the comments above seem to be simply confused about these points:
Non-obvious historical context: I wrote the dyn Trait RFC before the big discussion surrounding the Now, with all that out of the way, the semi-buried but valid novel point I see in this discussion is: When I updated the dyn Trait RFC, I did not notice that the argument for a warn-by-default lint against bare trait syntax on Rust 2015 becomes much weaker when you realize dyn Trait came out around the same time as a new Edition, and I don't think anybody else noticed this either. In all fairness, it is pretty minor compared to the "wait, can we actually get away with this?" question that correctly dominated the discussion. So even though the explicit consensus of that RFC was to warn against it on 2015, in hindsight I have no objection to softening that now. Especially since we're also considering making the 2015 edition be a warning unto itself, it does seem a bit silly to have more than one warning that effectively says "this is 2015 code" on by default. |
This is a sub-issue of #44662 proposing the Rust 2015 stabilization of
dyn Trait
.Status
The decision is made, we just need a stabilization PR!
Details
The new syntactic form
dyn <relative-path>
is added. It is an error to usedyn <relative-path>
ifpath
does not name a trait. The result is a so-called dynamic trait type.For backwards compatibility,
dyn
can still be used as an identifier -- in other words, it is a contextual keyword. Note also thatdyn :: foo
parses as a pathdyn::foo
and not a use of thedyn
keyword. You can however writedyn (::foo)
to clarify your meaning.There is a "allow by default" lint that suggests uses of
Trait
be rewritten todyn Trait
. Much code in rustc was converted usingrustfix
in conjunction with this lint. I believe the current plan is to keep this lint as "allow by default" for the time being, but make it as part of the "idiom shift" lints for Rust 2018.Tests
Here are some tests documenting the current behavior:
dyn Trait
, including a use ofdyn (::Path)
.dyn
by itself is an identifierdyn::foo
is a pathOther details
Once this is stable, we should adjust the output from
ppaux
to use it! (#49277)The text was updated successfully, but these errors were encountered: