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 CString, OsString, PathBuf extra methods #40380

Closed
clarfonthey opened this issue Mar 9, 2017 · 17 comments
Closed

Tracking issue for CString, OsString, PathBuf extra methods #40380

clarfonthey opened this issue Mar 9, 2017 · 17 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Mar 9, 2017

This includes the methods:

  • CString::into_boxed_c_str
  • OsString::into_boxed_os_str
  • PathBuf::into_boxed_path
  • <Box<CStr>>::into_c_string
  • <Box<OsStr>>::into_os_string
  • <Box<Path>>::into_path_buf
  • CString::as_c_str

The into_boxed_* methods coming from #39594, the other into_* methods from #40009, and the as_c_str method from #41095.

The features for the methods are into_boxed_c_str, into_boxed_os_str, into_boxed_path, and as_c_str.

@clarfonthey
Copy link
Contributor Author

ping @brson / @alexcrichton to tag this, also ping @jonhoo because you were specifically interested in stabilising these for something for serde.

@alexcrichton
Copy link
Member

Oh it looks like in #39594 we forgot to update the tracking issue. @clarcharr could you update those tracking issues to point here?

@alexcrichton alexcrichton added B-unstable Blocker: Implemented in the nightly compiler and unstable. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 9, 2017
@clarfonthey
Copy link
Contributor Author

clarfonthey commented Mar 9, 2017

I included that as part of the second PR, so, already covered. If for some reason that PR isn't accepted, I'll make a separate PR for just updating the tracking issues.

@clarfonthey clarfonthey changed the title Tracking issue for CString, OsString, PathBuf to Box methods Tracking issue for CString, OsString, PathBuf extra methods Apr 5, 2017
bors added a commit that referenced this issue Apr 11, 2017
Reduce str transmutes, add mut versions of methods.

When I was working on the various parts involved in #40380 one of the comments I got was the excess of transmutes necessary to make the changes work. This is part of a set of multiple changes I'd like to offer to fix this problem.

I think that having these methods is reasonable because they're already possible via transmutes, and it makes the code that uses them safer. I can also add `pub(crate)` to these methods for now if the libs team would rather not expose them to the public without an RFC.
@nagisa
Copy link
Member

nagisa commented May 7, 2017

The into_boxed_* methods do not have associated tracking issue set.

Also, I really dislike the _ between c/os and str in the method name. I mistyped the method about three times in a row.

@clarfonthey
Copy link
Contributor Author

Currently this is to be consistent with methods that already exist, like as_os_str. We could rename them and deprecate the methods with the old naming scheme, though.

@clarfonthey
Copy link
Contributor Author

Also I'm confused on what you mean about them lacking a tracking issue; all of them link to here.

@nagisa
Copy link
Member

nagisa commented May 7, 2017

Also I'm confused on what you mean about them lacking a tracking issue; all of them link to here.

There’s no tracking issue linked in the stable docs, which is why I was confused.

@clarfonthey
Copy link
Contributor Author

I initially forgot to add a tracking issue before the cut, so, they're probably on the beta docs but not stable. I thought that I had gotten it in before the changes were merged but I guess not.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented May 11, 2017

Is there a way we could get this on track for stabilisation? This is necessary to make some serde impls safe on stable.

(I am not sure how to tag the libs team in general)

@alexcrichton
Copy link
Member

Sure yeah, let's see what others think:

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented May 11, 2017

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

No concerns currently listed.

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.

@dtolnay
Copy link
Member

dtolnay commented May 11, 2017

So far I have only looked at CString::as_c_str, will look at the other ones next.

It looks like the implementation could be simpler:

pub fn as_c_str(&self) -> &CStr {
    self
}

This is what String::as_str does.

Also I noticed there is String::as_mut_str but not CString::as_mut_c_str. Any reason or are we just punting that to a future change?

What are the reasons that people use String::as_str in practice? Do we expect all of those to apply to CString::as_c_str? Are there any additional reasons someone might need as_c_str?

@clarfonthey
Copy link
Contributor Author

I personally use it a lot via map, e.g. iterator.map(String::as_str). It also helps with type inference because as_ref is ambiguous and as_str is not.

There's no as_mut_c_str currently because there are no methods for &mut CStr and currently no way to construct one outside transmuting one out of thin air. I think that this should be saved for the future when we actually have a need for such a thing, if ever.

@dtolnay
Copy link
Member

dtolnay commented May 12, 2017

This was in the insta-stable part of #40009 but this impl has a stray lifetime that should be removed. EDIT: also this impl.

The attribute on that impl says since = "1.17.0" but from what I can tell it was not in 1.17.0. Where in the process do those get updated to the right version? Is that something we need to track in this issue?

I'm sure this has been discussed but there is no way to do any of the Into impls in #40009 as From impls instead, right? It would be great to get a comment on each Into impl with a brief explanation or a link to an explanation or thread. That way future maintainers aren't confused. I'm sure there is a reason but it isn't obvious.

Changing them to From impls in the future if it becomes possible is backward compatible right?

These are the very first Into impls we have added to std (other than the blanket impl involving From). In the past, somebody could look at the list of implementations and understand: oh, I'm probably not supposed to implement this. Now we have a nice long list of implementations and one less way to convince people "do as we say, not as we do." Are there any ways that we could cancel out this effect or is it not worth worrying about? In particular, I would prefer to explain this in the API guidelines before the Into impls become stable. rust-lang/api-guidelines#30

selection_044

@clarfonthey
Copy link
Contributor Author

clarfonthey commented May 12, 2017

@dtolnay First, thank you for looking into this so much!

So, sort-of in order:

  1. I filed Warn on unused lifetime parameters #41960 because we should be warning on unused lifetimes. I made a PR to remove them: Remove unused lifetimes. #42127.
  2. I'm not actually sure. Usually there's a tag added to PRs to indicate that they need to be added to release notes, but no one actually modified this tag. I can modify it to say 1.18.0 and then request a beta backport.
  3. I made a PR (Nightly regression on x86_64_unknown_linux_gnu #43126) that modifies the docs for Into to reflect this. There are issues floating around about softening the rules so that we can turn these into Froms, but I can't seem to find them.
  4. They're not actually the first Into impls; there used to be three others until actually I actually mentioned in Into implementations should be changed to From #37561 that they should be changed, and then they were removed. :)

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue May 31, 2017
Clarify docs on implementing Into.

This was suggested by @dtolnay in rust-lang#40380.

This explicitly clarifies in what circumstances you should implement `Into` instead of `From`.
@rfcbot
Copy link

rfcbot commented Jun 6, 2017

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jun 6, 2017
@rfcbot
Copy link

rfcbot commented Jun 16, 2017

The final comment period is now complete.

@Mark-Simulacrum Mark-Simulacrum added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Jul 22, 2017
@bors bors closed this as completed in cbfce40 Jul 27, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 12, 2017
Stabilizes:

* `CString::as_c_str`
* `CString::into_boxed_c_str`
* `CStr::into_c_string`
* `OsString::into_boxed_os_str`
* `OsStr::into_os_string`
* `PathBuf::into_boxed_path`
* `PathBuf::into_path_buf`

Closes rust-lang#40380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. 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

6 participants