-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Improve the experience of using syntax extensions with #![no_std] #17100
Conversation
@@ -764,6 +765,8 @@ mod test_map { | |||
|
|||
#[test] | |||
fn test_show() { | |||
use std::to_string::ToString; |
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.
Import the trait but still remove the to_string
?
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.
It's needed for this call below:
let map_str = map.to_string();
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.
Hm; why is there the to_string
-> String::from_str
change?
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.
When libcollections is built with cfg(test)
it links the real libstd. This means that to_string
returns an std::string::String
, re-exported from a previous build of libcollections, rather than the string::String
defined in the crate under test. We can still compare them with .as_slice()
, but for most purposes it's better to use string::String
.
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.
Oh, right. Different types with the same name!
I pushed commits addressing the comments. I can squash these after review. |
I'd like someone else to glance over this (maybe @alexcrichton and @sfackler); r=me if they're ok with it. (This is actually patch is along the lines of how I was thinking of solving this problem, but I never got around to it because I'm not totally in love with this solution; but it's mostly just a general unease about increasing the number of syntax extension name resolution hacks that we have, rather than something concrete.) |
Needed to make #[deriving(Hash)] work within libstd itself.
Fixes rust-lang#16806. The duplication of code with libstd is unfortunate, but there's already a lot of that exported from core::macros.
569e24c
to
e4dcfdb
Compare
Rebased. Yeah, I don't love this solution either. But I want to solve these issues ASAP, so we can deliver on the promise of writing C libraries in Rust. And this seems like a fine stopgap fix until we have a way to reliably capture references to crates. One thing I'm wondering is to what extent the "facade" pattern of libstd re-exports will appear in other Rust projects besides the standard libraries. If those projects also define syntax extensions, they'll need similar hacks. |
I'm okay with this for now, I guess. We should really figure out how we want to fix this in the long run, and how much of that we can get done before 1.0. (also, e17977f now refers to a nonexistent commit in the message since you rebased) |
This is expanding some core apis that I'd like to consider a bit before landing. It would be great if we could avoid expanding them for now. Notably:
Also, as others have noted, this is just a band-aid, it's not really fixing the underlying issue. The bugs being "fixed" here aren't really bugs per se but rather all victims of lack of macro import/export, macro hygiene at the item level, etc. Code will still not work if you have I think we can land this for now (hopefully with no API extensions), but I'm very wary of continuing down this path which was not meant to be taken of shoehorning hygiene under the facade where it doesn't exist. |
I'm working on a different band-aid (see #17103) that makes some of this obsolete and should merge first. |
Nope, it's still there. This was a fix to std's |
@kmcallister do you think we can move forward with this without modifying public APIs? I would be ok with this otherwise I think. |
Slice syntax has a similar problem. |
Closing due to inactivity, and it looks like this getting re-scrutinized in rust-lang/rfcs#453 as well. |
This isn't as exciting as crate capture for macros, but it removes a number of immediate pain points.