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

Added Default impl to PathBuf #38764

Merged
merged 1 commit into from
Feb 8, 2017
Merged

Added Default impl to PathBuf #38764

merged 1 commit into from
Feb 8, 2017

Conversation

XAMPPRocky
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@frewsxcv frewsxcv added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 4, 2017
@GuillaumeGomez
Copy link
Member

👍

@sfackler
Copy link
Member

sfackler commented Jan 4, 2017

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Jan 4, 2017

Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams:

Concerns:

Once these reviewers reach consensus, 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.

@brson
Copy link
Contributor

brson commented Jan 6, 2017

I feel like we've discussed this before and decided not to have a default for paths because it's not clear what it means to be a 'default' path. This implementation I think creates an empty path, but semantically that does not strike me as a 'default path', it strikes me more like a null path and a source of errors.

@brson
Copy link
Contributor

brson commented Jan 6, 2017

@rfcbot concern there's no obvious default for paths per above

@aturon
Copy link
Member

aturon commented Jan 6, 2017

@brson Yes, I believe this came up for Path previously, with the conclusion you mention. But the story is different for PathBuf, as it's common to create an empty PathBuf and then push components onto it.

@sfackler
Copy link
Member

A generally good rule of thumb is that if a type has a no-arg new method, it probably makes sense to have a Default impl that does the same thing. I think clippy may even have a lint for that?

@clarfonthey
Copy link
Contributor

@sfackler
Copy link
Member

@brson ping?

@clarfonthey
Copy link
Contributor

Also note that this has precedent in Iterator::unzip which requires Default.

@brson
Copy link
Contributor

brson commented Jan 20, 2017

@brson Yes, I believe this came up for Path previously, with the conclusion you mention. But the story is different for PathBuf, as it's common to create an empty PathBuf and then push components onto it.

And you would use default for that, not new?

@brson
Copy link
Contributor

brson commented Jan 20, 2017

Also note that this has precedent in Iterator::unzip which requires Default.

I don't quite follow how that is precedent for Path::default.

@brson
Copy link
Contributor

brson commented Jan 20, 2017

I'm afraid I still don't see any obvious motivation here except for @sfackler's rule of thumb that types that implement new should implement default. I've stated my concern that empty PathBuf's, which could accidentally slip in to arbitrary deriving-default data structures, are bogus, and prone to error. I don't see a use case for defaulting empty paths.

@clarfonthey
Copy link
Contributor

@brson: the unzip iterator adapter assumes Default and Extend instead of FromIterator, basically stating that the Default implementation for a container is its empty version.

Empty strings might not be a reasonable default for a lot of containers too, but that's the way stdlib seems to point.

@BurntSushi
Copy link
Member

I've stated my concern that empty PathBuf's, which could accidentally slip in to arbitrary deriving-default data structures, are bogus, and prone to error.

I feel like this is a pretty good point. Paths have additional semantics in the environment that strings don't have.

I don't feel strongly either way on this given @brson's concerns. It does feel like a possible footgun, but I think adding a Default impl so that PathBuf works with things like unzip is pretty nice. Neither seem like a big deal though.

@aturon
Copy link
Member

aturon commented Jan 23, 2017

I agree with @brson that there's a potential footgun here, but I think it's relatively minor, and OTOH not being able to work easily with things like unzip is a pain. So on balance I'm still 👍.

@XAMPPRocky
Copy link
Member Author

I've stated my concern that empty PathBuf's, which could accidentally slip in to arbitrary deriving-default data structures, are bogus, and prone to error.

@brson I'm not really sure if I see the footgun. What errors could arise from the PathBuf that wouldn't already have to be handled by the user?

@tbu-
Copy link
Contributor

tbu- commented Jan 28, 2017

See also #32990.

The empty path makes sense for both Path and PathBuf -- when you accumulate over (concatenate) many of these, the empty path is the neutral element, much like the Default implementation for many other types.

@aturon
Copy link
Member

aturon commented Jan 31, 2017

Ping @brson, are you satisfied by the recent arguments?

@brson
Copy link
Contributor

brson commented Feb 6, 2017

@aturon No, but I clicked the box anyway.

@aturon
Copy link
Member

aturon commented Feb 6, 2017

Thanks all, and thanks @Aaronepower for sticking in there!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Feb 6, 2017

📌 Commit 108293d has been approved by aturon

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 7, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 7, 2017
bors added a commit that referenced this pull request Feb 7, 2017
Rollup of 15 pull requests

- Successful merges: #38764, #39361, #39426, #39462, #39482, #39557, #39561, #39582, #39583, #39587, #39598, #39599, #39601, #39602, #39604
- Failed merges:
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 8, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 8, 2017
bors added a commit that referenced this pull request Feb 8, 2017
Rollup of 13 pull requests

- Successful merges: #38764, #39361, #39372, #39374, #39400, #39426, #39431, #39459, #39482, #39545, #39593, #39620, #39621
- Failed merges:
@bors bors merged commit 108293d into rust-lang:master Feb 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.