Change derive macro for Eq to not impl Eq trait fn#153125
Change derive macro for Eq to not impl Eq trait fn#153125KiChjang wants to merge 8 commits intorust-lang:mainfrom
Conversation
|
Changes to the code generated for builtin derived traits. cc @nnethercote |
This comment has been minimized.
This comment has been minimized.
|
A test case that seems like might break with this: trait Trait<T> {}
#[derive(PartialEq, Eq)]
struct Thing<T: Trait<Self>>(T); |
|
A less exotic test case: #[derive(PartialEq, Eq)]
struct Thing(Option<Box<Self>>); |
|
Nick, I would reassign to you (feel free to reroll) since @cyrgani is a triage member and can't approve compiler changes r? nnethercote |
Gah, because we're now generating a const item instead of a trait impl block, we'd need to rewrite the A better solution now would be to emit the following: impl<...> Type<...> {
const fn assert_fields_are_eq() {
let _: ::core::cmp::AssertParamIsEq<Option<Box<Self>>>;
}
}This would side-step the issue of rewriting |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| //~^ ERROR: struct takes 0 generic arguments | ||
| //~| ERROR: struct takes 0 generic arguments | ||
| //~| ERROR: struct takes 0 generic arguments | ||
| //~| ERROR: struct takes 0 generic arguments |
There was a problem hiding this comment.
This is expected since the Eq derive macro now respans generics in the where clause, which causes the same E0107 error to be reported in 2 different contexts instead of simply the original one (i.e. in the derived trait impl for Eq)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Looks like CI is passing now, r? @nnethercote |
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
|
You should be able to delete the |
|
Could you also add a test that something like fn main() {
X::assert_fields_are_eq();
}
#[derive(PartialEq, Eq)]
struct X(u8);will not compile? |
| id: ast::DUMMY_NODE_ID, | ||
| attrs: thin_vec![ | ||
| cx.attr_nested_word(sym::doc, sym::hidden, span), | ||
| cx.attr_nested_word(sym::coverage, sym::off, span), |
There was a problem hiding this comment.
I guess this will also need #[inline] like #153157?
Fixes #152504.
r? @cyrgani