Skip to content

Conversation

@chenyan2002
Copy link
Contributor

@chenyan2002 chenyan2002 commented Oct 30, 2025

The original get function elides the lifetime, so we have fn get(&'b self) -> &'b T. But since Borrow<'a> is valid for the whole 'a duration, we should be able to borrow &'a T instead. The new signature is also semantically more accurate.

@alexcrichton
Copy link
Member

Thanks! For this I'd prefer to have one of (a) leave them private and users use the &-returning methods, or (b) make them public but document them and explain why they might be used. I don't mind either one, but I'd prefer to not be in the current state where they're public-but-hidden as that feels a bit too brittle to me (e.g. easy to forget why they were public in the first place)

@chenyan2002 chenyan2002 changed the title make resource::as_ptr public extend the lifetime of borrowed resource get Nov 8, 2025
@chenyan2002
Copy link
Contributor Author

I have a better fix now. The original get function elides the lifetime, so we have fn get(&'b self) -> &'b T. But since Borrow<'a> is valid for the whole 'a duration, we should be able to borrow &'a T instead. The new signature is also semantically more accurate.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks good to me! I had to re-convince myself this is safe as well but I believe it is.

Mind adding a test for this too?

@alexcrichton alexcrichton added this pull request to the merge queue Nov 10, 2025
Merged via the queue into bytecodealliance:main with commit 04f6257 Nov 10, 2025
22 checks passed
@chenyan2002 chenyan2002 deleted the as_ptr branch November 10, 2025 22:14
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