-
Notifications
You must be signed in to change notification settings - Fork 185
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
Handle ?Sized better in ZeroFrom derive #4657
Conversation
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.
Not convinced that either this or the Yokeable changes are necessary. Would like to see the actual errors.
utils/zerofrom/derive/src/lib.rs
Outdated
let bound = bound_pair.into_value(); | ||
if let TypeParamBound::Trait(ref trait_bound) = bound { | ||
let sized: Path = PathSegment { | ||
ident: quote::format_ident!("Sized"), |
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.
nit: I would just directly check equality on the ident here instead of constructing a new one
utils/zerofrom/derive/src/lib.rs
Outdated
.map(|param| { | ||
// First one doesn't work yet https://github.com/rust-lang/rust/issues/114393 | ||
let maybe_new_param = if has_attr(¶m.attrs, "may_borrow") | ||
|| may_borrow_attrs.contains(¶m.ident) | ||
{ | ||
// Remove `?Sized`` bound because we need a param to be Sized in order to take a ZeroFrom of it |
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.
issue: same comment as on Yokeable, I don't agree with this.
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.
Ah, this is only on may_borrow
. This is fine, but please update the docs to say "we need a may_borrow
param to be Sized
in order to take a ZeroFrom attribute of it.
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.
This is fine, please fix the nit on equality.
utils/zerofrom/derive/src/lib.rs
Outdated
} | ||
.into(); | ||
if trait_bound.path == sized | ||
if trait_bound.path.get_ident() == Some("e::format_ident!("Sized")) |
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.
you should just be able to == str
here
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.
.get_ident().map(|x| x == "Sized").unwrap_or(false)
Need this to support the
Store
type parameter, which is?Sized
but should only implementZeroFrom
when it is sized.