-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
str::lines and BufRead::lines: document trailing bare cr behaviour #91051
Conversation
Apropos discussion here rust-lang#91047 (comment) Sadly, str::lines gets this wrong. I think it is probably too late to fix this, so document it instead.
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
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.
Can we keep it neutral and not have it sound so negative? I don't think giving the "we messed up" vibe in the official docs adds a lot of value.
And instead of referring to the two ways as "correct" and "incorrect" you could be more explicit.
I think we should just fix this and make |
I think this would need an FCP, but it is indeed our other option. I will work up an MR to do this, so we can see what it looks like (and what kind of justification I find I am able to write). I think we should choose between fixing it, and acknowledging that it is, at the very least, anomalous. I don't think we should pretend (even implicitly) in the docs that we think the current behaviour of |
I don't think many libs rely on this behaviour so fixing would be a wise decision rather than mitigating it by adding docs. Not many of us are going to read the documentation and this is not expected too. So it would be better if we fix it. Maybe next time when we do a crater run we can investigate how much churn it would cause in the ecosystem. |
E.g., split "bare\r" into the single line "bare\r", not "bare". The documentation for this function says that only LF or CR-LF count as newlines. So a bare CR is not a line ending, and must not be stripped. This fix is a behavioural change, even though it brings the behaviour into line with the documentation, and into line with that of `std::io::BufRead:;lines()`. It seems unlikely that anyone is relying on this bug, but I'm not sure how to rule it out. Perhaps this should have an FCP or a crater run or something. It should definitely be in the release notes. This is an alternative to rust-lang#91051, which proposes to document rather than fix the behaviour. As for the implementation: the current version doesn't give the map closure the right information, so we need to use split_inclusive. After that, we can reuse the logic in the new `str::trim_newline`. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Co-authored-by: r00ster <r00ster91@protonmail.com>
The job Click to see the possible cause of the failure (guessed by this bot)
|
@ijackson if you can |
Given these comments, ping @rust-lang/libs-api |
I do think we could try a crater run fixing the two to be consistent. |
I agree, these two being inconsistent seems like a mistake we should fix. |
Triage: |
Previously "bare\r" was split into ["bare"] even though the documentation said that only LF and CRLF count as newlines. This fix is a behavioural change, even though it brings the behaviour into line with the documentation, and into line with that of `std::io::BufRead::lines()`. This is an alternative to rust-lang#91051, which proposes to document rather than fix the behaviour. Fixes rust-lang#94435. Co-authored-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Previously "bare\r" was split into ["bare"] even though the documentation said that only LF and CRLF count as newlines. This fix is a behavioural change, even though it brings the behaviour into line with the documentation, and into line with that of `std::io::BufRead::lines()`. This is an alternative to rust-lang#91051, which proposes to document rather than fix the behaviour. Fixes rust-lang#94435. Co-authored-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Apropos discussion here #91047 (comment)
Sadly, str::lines gets this wrong. I think it is probably too late to
fix this, so document it instead.