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

Fix receiver lifetimes in AttributeTypeAndValue. #141

Closed
wants to merge 1 commit into from

Conversation

SergioBenitez
Copy link
Contributor

This builds off rusticata/asn1-rs#22.

@SergioBenitez
Copy link
Contributor Author

Note that this PR depends on rusticata/asn1-rs#22, so we expect tests to fail until that PR is merged and dependencies are updated as needed.

@SergioBenitez
Copy link
Contributor Author

SergioBenitez commented Jun 7, 2023

Checking on this. Can we get this merged? We still need a release of asn1 for this PR to work.

@SergioBenitez
Copy link
Contributor Author

Checking in again.

@@ -115,7 +115,7 @@ impl<'a> AttributeTypeAndValue<'a> {

/// Get the content as a slice.
#[inline]
pub fn as_slice(&'a self) -> &'a [u8] {
pub fn as_slice(&self) -> &'a [u8] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look correct. By forcing only the return to satisfy 'a, the compiler assigns an unnamed lifetime to self, and they do not match. Removing the return lifetime fixes that.
I'll add some commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the way lifetimes work, and your reversal of this change partially obviates the intended consequences of this PR. Please see my comment in rusticata/asn1-rs#22 (comment) where I address your misconceptions about lifetimes.

By forcing only the return to satisfy 'a, the compiler assigns an unnamed lifetime to self, and they do not match.

You seem think that "they do not match" is a problematic statement, but in fact, that's quite literally the point here: we want the receiver's lifetime (&self) to differ from the returned lifetime (&[u8]). Otherwise, we ask for unification, which means that the receiver must live as long as the return value and vice-versa, even when no such relationship is needed.

Your commit has obviated the meaningful change here and resulted in a strictly worse situation wherein the content of the struct is typed to a particular reference (the receiver, created exactly when the method is called - it doesn't exist otherwise) to the struct. This only makes sense when the struct owns the data, which is not the case here.

@chifflier
Copy link
Member

Manually merged in 109e0aa and 853d7ee
Thanks!

@chifflier chifflier closed this Jul 5, 2023
@SergioBenitez
Copy link
Contributor Author

Please revert 853d7ee and any other such changes and publish a new breaking release.

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.

None yet

2 participants