-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[WIP] str
is dead, long live str([u8])
!
#19612
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 notifications@github.com 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) |
This PR removes the built-in/primitive
str
type from the compiler, and replaces it with a library type:str([u8])
. This new type is defined in thecore::str
module, and re-exported in thecollections::str
andstd::str
modules.[breaking-change]s
For most of people:
str
is now a struct imported as part of thestd
prelude, this means that importing thestd::str
module or usingstr
as a variable name now is a name clash, and will result in a compile error.StrPrelude
trait has been removed, and all the methods defined in it are now inherent methods of the newstr
type. This will break code that was explicitly using theStrPrelude
trait.For
#![non_std]
users:core
crate then you need to define thestr
type and mark it with the"str"
lang item:format_args!
andpanic!
macros now usestd::str::str
instead of juststr
in their expansion, to use these macros you'll need to use the "std
module trick":Closes #19036
This passes
make check
as it is, but I broke therun-pass/unsized3
test (it triggers an LLVM assertion) and I'm currently investigating how to fix it.@nikomatsakis re: compiler. I removed the
sty::ty_str
variant and replaced it with the following check:ty_struct(def_id, _) if ty::is_str(cx, def_id)
in mostmatch
expressions. 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
str
type/struct now collides with thestd::str
module (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_utf8
would work without needing to importstd::str
, and no collision would occur. Thoughts?