Skip to content
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

Tracking issue for vNext edition prelude #65512

Closed
2 tasks
scottmcm opened this issue Oct 17, 2019 · 27 comments
Closed
2 tasks

Tracking issue for vNext edition prelude #65512

scottmcm opened this issue Oct 17, 2019 · 27 comments
Labels
A-maybe-future-edition Something we may consider for a future edition. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. E-help-wanted Call for participation: Help is requested to fix this issue. Libs-Tracked Libs issues that are tracked on the team's project board. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Oct 17, 2019

There were plans to do this for the 2018 edition, but it never happened (#51418, #51434)

Things to consider:

  • TryFrom/TryInto
  • ???

Note 2020-04-19: Please limit suggestions here to things that would be breaking changes to do in the current prelude. Some prelude additions can happen without being a breaking change, and if you'd like to do one of those them just talk with libs about it -- it doesn't need to wait.

@scottmcm scottmcm added the A-maybe-future-edition Something we may consider for a future edition. label Oct 17, 2019
@jonas-schievink jonas-schievink added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Oct 17, 2019
@scottmcm scottmcm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Oct 17, 2019
@jhpratt
Copy link
Member

jhpratt commented Dec 1, 2019

std::fmt::Display seems like a reasonable thing to include IMO.

@SimonSapin
Copy link
Contributor

@jhpratt

  • Why should it be added?

  • Why this one and not other items from std::fmt? Display is rarely called directly but more often implemented. But to implement it you also need std::fmt::Formatter and <std::fmt::Result or std::fmt::Error>. But we already have std::result::Result in the prelude, and std::io::Error and std::error::Error that are not but share the exact same name and don’t seem to me less important than std::fmt::Error.

  • If it’s added, why in an edition-specific prelude rather than for all editions? Edition-specific prelude are only discussed because adding TryFrom makes many existing calls to try_from methods of other traits ambiguous, breaking code that runs on Stable: Stabilize TryFrom / TryInto, and tweak impls for integers #49305 (comment)

@eaglgenes101
Copy link

eaglgenes101 commented Feb 2, 2020

Can I also suggest an ArrayIntoIterExt extension trait for the 2021 prelude?

AFAIK implementing IntoIterator for arrays is blocked on clashes with existing ecosystem implementations. This could be worked around starting with the 2021 edition by creating an extension trait for arrays which implements IntoIterator, and exposing it in the 2021 prelude.

A similar approach is currently to expose slice concatenation methods for technical reasons I still don't quite understand. So this approach, while unusual, is not completely unheard of.

@kornelski
Copy link
Contributor

kornelski commented Apr 15, 2020

In addition to TryInto, I find adding quite frequently:

  • Path and PathBuf
  • HashMap and HashSet
  • Arc and Mutex

I wouldn't add Display, because for implementing it, it also needs its formatter and result. It would be interesting to add std::fmt to the prelude, so that fmt::Formatter and fmt::Result work, but adding use std::fmt isn't too bad.

@SimonSapin
Copy link
Contributor

SimonSapin commented Apr 15, 2020

If it’s added, why in an edition-specific prelude rather than for all editions? Edition-specific prelude are only discussed because adding TryFrom makes many existing calls to try_from methods of other traits ambiguous, breaking code that runs on Stable: #49305 (comment)

@SimonSapin
Copy link
Contributor

@eaglgenes101 The problem with #25725 is not collision with methods of other traits from other crates, but collision of IntoInterator for [T; N] with itself for &[T; N] though auto-ref. Code that was previously valid (iterating &T by reference) changes meaning.

Having a new dedicated trait does not change the problem if the method is still named into_iter. And if it’s named something else, we’re back to the previous point that it doesn’t need to be edition-specific.

@mbrubeck
Copy link
Contributor

I have previously suggested adding FromIterator to the prelude. Rationale here.

@joshtriplett
Copy link
Member

joshtriplett commented Apr 15, 2020

I would love to see the following in an updated prelude:

  • Error
  • TryInfo and TryFrom
  • Path and PathBuf
  • Cow
  • HashMap, HashSet, BTreeMap, BTreeSet
  • File

I've based these on things I see imported heavily, and some greps for commonly imported bits of std in various projects.

I'm also tempted to request OsStr and OsString.

@SimonSapin
Copy link
Contributor

SimonSapin commented Apr 16, 2020

@mbrubeck @joshtriplett Aside for TryInto and TryFrom (where we already know this is the case), do you expect that adding those to std::prelude::v1 for all editions would cause any breakage? If not, we shouldn’t make things edition-specific gratuitously and this is not the right thread to request additions.

@mbrubeck
Copy link
Contributor

mbrubeck commented Apr 17, 2020

structopt, kuchiki, micromath, and clapme have trait methods that could conflict with FromIterator::from_iter.

Of these, clapme (which is not very widely used currently) definitely has conflicts: clapme::ClapMe is implemented for Vec and Option, which also implement FromIterator. The others could conflict in theory because of third-party impls, but I think such conflicts are unlikely in practice.

My best guess is that adding FromIterator to the prelude for all editions would break some existing code, but not a huge amount.

@jhpratt
Copy link
Member

jhpratt commented Apr 18, 2020

Here's one that may be slightly controversial — remove std::mem::drop from the prelude. I can't think of a single instance I've ever used it, and IMO having to explicitly import it would be clearer.

@programmerjake
Copy link
Member

Here's one that may be slightly controversial — remove std::mem::drop from the prelude. I can't think of a single instance I've ever used it, and IMO having to explicitly import it would be clearer.

+1

I've been writing Rust for around 2 years now, and I never realized until now that drop was in the prelude -- I've always imported std::mem and used it as mem::drop(x). I don't recall ever seeing any code that uses it from the prelude.

@kornelski
Copy link
Contributor

I'm regularly using drop from the prelude. It's very handy in async/await code where it's efficient and sometimes required to explicitly drop stuff before .await points.

@jhpratt
Copy link
Member

jhpratt commented Apr 20, 2020

@kornelski Is it something that most people use on a regular basis though? Other items in the prelude are used all the time by a lot of people.

@kornelski
Copy link
Contributor

kornelski commented Apr 20, 2020

I use drop more often than try_from, for example. Probably because one is in the prelude, and the other isn't :)

I think removal of drop is an unnecessary churn:

  • it has legitimate use-cases, like unlocking mutexes early, explicitly disconnecting mpsc senders, removing ballast from Futures.
  • it's been used in code examples and the Rust Book.
  • it's harmless, and it's not deprecated.
  • dropping it would not improve anyone's Rust experience. There's no other drop function waiting to be used instead.

@crlf0710 crlf0710 added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Jun 10, 2020
@KodrAus KodrAus added the Libs-Tracked Libs issues that are tracked on the team's project board. label Jul 29, 2020
@Lokathor
Copy link
Contributor

Error I'm sure breaks someone.

HashMap and HashSet probably break people as well.

@matklad
Copy link
Member

matklad commented Aug 5, 2020

Error I'm sure breaks someone. HashMap and HashSet probably break people as well.

As far as my understanding goes, adding types (as opposed to traits) to the prelude is not a breaking change. Prelude is shadowed by glob and explicit imports.

@scottmcm scottmcm added the E-help-wanted Call for participation: Help is requested to fix this issue. label Aug 17, 2020
@scottmcm
Copy link
Member Author

We talked about this in the lang team triage meeting today, in the context of rust-lang/lang-team#44.

The zulip thread (https://rust-lang.zulipchat.com/#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20per-edition.20preludes.20lang-team.2344/near/205701158) raised a question about how this is going to interact with name resolution in macros. We'd appreciate it if someone in the community could take a deep dive into the best way to resolve this specific question, as overall we'd probably like to do this.

@jhpratt
Copy link
Member

jhpratt commented Dec 5, 2020

Here's something that I just ran across: the only Debug imported is the derive, not the trait. I don't know if it needs to be edition-specific, butt it's something worth considering.

@matklad
Copy link
Member

matklad commented Dec 5, 2020

Adding Debug or Display to prelude will probably break some code, as they both share the fmt name, so this might add new ambiguities to method selection.

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Dec 20, 2020

Across this lengthy thread in internals we can see that there are many people, myself included, who would like for bool to feature a .not() method that would always be in scope, so as to allow whomever prefers it that way to replace the prefix sigil ! with a postfix annotation, which is a pattern seemingly considered idiomatically/ergonomically superior (c.f. .await and suggestions for .match), and that's without mentioning stuff like !matches!. Obviously one can emulate that by having Not in scope, but the ergonomic hit of having to use a trait for something as simple as condition negation is then a big source of churn.

I thus suggest that the Not trait be also added to the next edition prelude (2021), since it may be simpler than adding an inherent .not() method 🙂

@cole-miller

This comment has been minimized.

@mbrubeck

This comment has been minimized.

@cole-miller

This comment has been minimized.

@est31
Copy link
Member

est31 commented Feb 17, 2021

cc #82217

@djc
Copy link
Contributor

djc commented Feb 26, 2021

I've posted an initial take on an RFC for this: rust-lang/rfcs#3090. Please comment there.

@m-ou-se
Copy link
Member

m-ou-se commented Sep 1, 2021

This has been implemented and is shipping in Rust 1.56 as part of Rust 2021.

@m-ou-se m-ou-se closed this as completed Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-maybe-future-edition Something we may consider for a future edition. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. E-help-wanted Call for participation: Help is requested to fix this issue. Libs-Tracked Libs issues that are tracked on the team's project board. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests