Skip to content
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

Merged
merged 6 commits into from
Mar 7, 2024
Merged

Conversation

sffc
Copy link
Member

@sffc sffc commented Mar 6, 2024

Need this to support the Store type parameter, which is ?Sized but should only implement ZeroFrom when it is sized.

@sffc sffc requested a review from Manishearth as a code owner March 6, 2024 22:05
@sffc sffc requested a review from a team as a code owner March 6, 2024 22:05
Copy link
Member

@Manishearth Manishearth left a 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.

let bound = bound_pair.into_value();
if let TypeParamBound::Trait(ref trait_bound) = bound {
let sized: Path = PathSegment {
ident: quote::format_ident!("Sized"),
Copy link
Member

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

.map(|param| {
// First one doesn't work yet https://github.com/rust-lang/rust/issues/114393
let maybe_new_param = if has_attr(&param.attrs, "may_borrow")
|| may_borrow_attrs.contains(&param.ident)
{
// Remove `?Sized`` bound because we need a param to be Sized in order to take a ZeroFrom of it
Copy link
Member

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.

Copy link
Member

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.

Manishearth
Manishearth previously approved these changes Mar 7, 2024
Copy link
Member

@Manishearth Manishearth left a 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.

Manishearth
Manishearth previously approved these changes Mar 7, 2024
}
.into();
if trait_bound.path == sized
if trait_bound.path.get_ident() == Some(&quote::format_ident!("Sized"))
Copy link
Member

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

Copy link
Member

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)

@sffc sffc merged commit dcea4e3 into unicode-org:main Mar 7, 2024
30 checks passed
@sffc sffc deleted the zerofrom-sized branch March 7, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants