-
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
Add derive and doc comment capabilities to newtype_index macro #45605
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
cc @spastorino |
src/librustc/hir/def_id.rs
Outdated
const LOCAL_CRATE = 0, | ||
|
||
/// Virtual crate for builtin macros | ||
// FIXME(jseyfried): this is also used for custom derives until proc-macro crates get `CrateNum`s. |
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.
Tidy errors.
[00:03:33] tidy error: /checkout/src/librustc/hir/def_id.rs:26: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:89: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:125: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:136: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:148: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:160: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:172: line longer than 100 chars
[00:03:33] tidy error: /checkout/src/librustc_data_structures/indexed_vec.rs:184: line longer than 100 chars
@Nashenas88 thanks for working on this :). Is there another way to get rid of the nopub thing?, not sure what's the issue we are having with that. Another thing that I'm thinking about is if it's better to add the derive = something or just pass some kind of flag only in the case you want to define your encodings, something like do_not_derive_encodings. |
Another two things, we should make /~https://github.com/rust-lang/rust/blob/690ff045/src/librustc/dep_graph/graph.rs#L47-L66 and /~https://github.com/rust-lang/rust/blob/690ff045/src/librustc/hir/def_id.rs#L96-L125 also go away. |
Regarding the In #45538, I changed from |
I agree with @spastorino that it would be nice if |
@nikomatsakis I'm wondering if I can somehow track the derive list so that |
Also, failing tests will be fixed when |
As you said, that seems a bit surprising to me.
Hmm, probably. I can't think when you want to do otherwise. Maybe in that case it's easier to just have a flag to disable encodable? e.g.,
Regarding |
Yes, the error is in the original comment I created the PR with, link. I was seeing that error 20 or so times. I like Regarding |
@nikomatsakis I tried matching what you wrote in #45538 re mod X {
pub struct CrateNum(u32);
impl CrateNum {
pub fn new(val: u32) -> Self {
CrateNum(val)
}
}
}
use X::CrateNum;
pub enum Enum {
CrateNumVal(CrateNum)
}
fn main() {
let val = Enum::CrateNumVal(CrateNum::new(4));
match val {
Enum::CrateNumVal(CrateNum) => {
println!("hello world");
}
}
} but this will not: mod X {
pub struct CrateNum(pub u32);
impl CrateNum {
pub fn new(val: u32) -> Self {
CrateNum(val)
}
}
}
use X::CrateNum;
pub enum Enum {
CrateNumVal(CrateNum)
}
fn main() {
let val = Enum::CrateNumVal(CrateNum::new(4));
match val {
Enum::CrateNumVal(CrateNum) => {
println!("hello world");
}
}
}
The behavior is the same when it's outside the module, regardless of visibility: pub struct CrateNum(u32);
impl CrateNum {
pub fn new(val: u32) -> Self {
CrateNum(val)
}
}
pub enum Enum {
CrateNumVal(CrateNum)
}
fn main() {
let val = Enum::CrateNumVal(CrateNum::new(4));
match val {
Enum::CrateNumVal(CrateNum) => {
println!("hello world");
}
}
} The version with the |
@Nashenas88 that is indeed odd. I am familiar with the rules giving rise to that error, but I think it's sort of a bug in the existing (dep-node) macro that we are relying on them. We could work around it by changing the various usages of The situation is that in general we resolve a naming ambiguity in binding pattern (i.e., a pattern with a plain identifier like This whole situation with the privacy of the inner field is kind of annoying. @spastorino I'm trying to remember why we made it pub in the first place... something to do with constants? |
@nikomatsakis we made it public because there were some match clauses if I recall correctly doing stuff like |
☔ The latest upstream changes (presumably #45538) made this pull request unmergeable. Please resolve the merge conflicts. |
146f6dc
to
bf1198e
Compare
@nikomatsakis @spastorino I changed it so it's not pub by default. Only |
@@ -158,8 +158,8 @@ pub struct BlockRemainder { | |||
|
|||
newtype_index!(FirstStatementIndex | |||
{ | |||
DEBUG_FORMAT = "{}", | |||
MAX = SCOPE_DATA_REMAINDER_MAX, | |||
pub idx |
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.
private by default FTW =)
@bors r+ |
📌 Commit 97692af has been approved by |
Add derive and doc comment capabilities to newtype_index macro This moves `RustcDecodable` and `RustcEncodable` out of the macro definition and into the macro uses. They were conflicting with `CrateNum`'s impls of `serialize::UseSpecializedEncodable` and `serialize::UseSpecializedDecodable`, and now it's not :). `CrateNum` is now defined with the `newtype_index` macro. I also added support for doc comments on constant definitions and allowed a type to remove the pub specification on the tuple param (otherwise a LOT of code would refuse to compile for `CrateNum`). I was getting dozens of errors like this if `CrateNum` was defined as `pub struct CrateNum(pub u32)`: ``` error[E0530]: match bindings cannot shadow tuple structs --> src/librustc/dep_graph/dep_node.rs:624:25 | 63 | use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX}; | -------- a tuple struct `CrateNum` is imported here ... 624 | [] MissingLangItems(CrateNum), | ^^^^^^^^ cannot be named the same as a tuple struct ``` I also cleaned up the formatting of the macro bodies as they were getting impossibly long. Should I go back and fix the matching rules to this style too? I also want to see what the test results look like because `CrateNum` used to just derive `Debug`, but the `newtype_index` macro has a custom implementation. This might require further pushes. Feel free to bikeshed on the macro language, I have no preference here.
☀️ Test successful - status-appveyor, status-travis |
This moves
RustcDecodable
andRustcEncodable
out of the macro definition and into the macro uses. They were conflicting withCrateNum
's impls ofserialize::UseSpecializedEncodable
andserialize::UseSpecializedDecodable
, and now it's not :).CrateNum
is now defined with thenewtype_index
macro. I also added support for doc comments on constant definitions and allowed a type to remove the pub specification on the tuple param (otherwise a LOT of code would refuse to compile forCrateNum
). I was getting dozens of errors like this ifCrateNum
was defined aspub struct CrateNum(pub u32)
:I also cleaned up the formatting of the macro bodies as they were getting impossibly long. Should I go back and fix the matching rules to this style too?
I also want to see what the test results look like because
CrateNum
used to just deriveDebug
, but thenewtype_index
macro has a custom implementation. This might require further pushes.Feel free to bikeshed on the macro language, I have no preference here.