-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[WIP] str is dead, long live str([u8])!
#19612
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
Conversation
|
Please, don't forget about RFC 339. It should be possible to add fixed strings to the language without breaking changes. |
|
wow, you are on a serious roll! The library situation is ... unfortunate. Of course, we usually avoid this by convention -- a convention the I really wish that we had complete enough associated items (and HKT) that "single type" modules could essentially just be types, with all of their contents associated items. That said, we don't have HKT, and things like iterators have to live somewhere. I don't know; maybe this unfortunate situation is enough to revisit the Worse case, we could rename the module |
I had thought |
|
So. I've been talking a bunch with the core team about this PR. Unfortunately, it's a bit unclear whether we want to move in this direction -- whether the benefits outweigh the drawbacks. Benefits:
Drawbacks:
At the moment, this change does not seem worth it, because it makes @japaric, I'd like to hear your thoughts on the above, and whether you see additional benefits or drawbacks we should consider, or alternative routes. |
|
(I was going to say that it's necessary to convert With that out of the way, of the two benefits you have mentioned, the first one will go mostly unnoticed by the community. And the second one is not really relevant anymore, because we are getting "facade" extension traits. That means that this PR will effectively break downstream code for no gain at all. And that's a good reason to not land this when we are so close to 1.0. Feel free to close this, unless someone can think of a good reason to actually do this. |
|
FWIW, if the My 2¢ regarding the whole situation: is it too late for an RFC renaming (BTW, fixed-size string literals would certainly be useful without CTFE or integral generic parameters. For example, |
|
It's not necessarily too late for an RFC (though I would suggest String FWIW, I don't think keeping On Tue, Dec 16, 2014 at 12:44 AM, P1start [email protected] wrote:
|
|
@aturon I believe the drawbacks you presented can easily be resolved by making str a real struct, not a tuple struct. Later, making str generic over its content type would make fixed-size string slices possible. With a default type parameter The magic about this type in the compiler would be reduced to the handling of string literals. |
|
@tbu-, I believe only one of the drawbacks is solved by using a normal struct (as @P1start describes). |
|
You're right, sorry. |
|
Closing for now to help clear out the queue and because of #19612 (comment) |
fix: Fix a bug with predicate lowering of associated items
This PR removes the built-in/primitive
strtype from the compiler, and replaces it with a library type:str([u8]). This new type is defined in thecore::strmodule, and re-exported in thecollections::strandstd::strmodules.[breaking-change]s
For most of people:
stris now a struct imported as part of thestdprelude, this means that importing thestd::strmodule or usingstras a variable name now is a name clash, and will result in a compile error.StrPreludetrait has been removed, and all the methods defined in it are now inherent methods of the newstrtype. This will break code that was explicitly using theStrPreludetrait.For
#![non_std]users:corecrate then you need to define thestrtype and mark it with the"str"lang item:format_args!andpanic!macros now usestd::str::strinstead of juststrin their expansion, to use these macros you'll need to use the "stdmodule trick":Closes #19036
This passes
make checkas it is, but I broke therun-pass/unsized3test (it triggers an LLVM assertion) and I'm currently investigating how to fix it.@nikomatsakis re: compiler. I removed the
sty::ty_strvariant and replaced it with the following check:ty_struct(def_id, _) if ty::is_str(cx, def_id)in mostmatchexpressions. But, I'm sure that I can simplify the logic (i.e. remove that match arm) in several parts of the compiler, which I'd like to do before landing this.@aturon re: library. One annoying thing after this change is that the
strtype/struct now collides with thestd::strmodule (when imported). As a "fix", instead of directly importing the module, I now import it under thestr_name (use std::str as str_). From what I've seen that the main reason for importing that module is to use its free functions (e.g.str::from_utf8), so I'm wondering if we should convert all those free functions into inherent methods ofstr, that waystr::from_utf8would work without needing to importstd::str, and no collision would occur. Thoughts?