Enable to write thrust_macros::{ensures,requires} inside impl#77
Merged
Enable to write thrust_macros::{ensures,requires} inside impl#77
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables thrust_macros::requires / thrust_macros::ensures to be used on methods inside impl blocks by propagating impl generics/context into each method and adjusting expansion details (notably self handling and Self:: path qualification) so the generated helper functions and extern-spec wrappers are well-formed in an impl context.
Changes:
- Added
#[thrust_macros::context]to annotateimplblocks and inject a#[thrust::_impl_context(...)]marker onto contained methods for downstream macro expansion. - Updated requires/ensures expansion to (a) consume
implgenerics for bounds generation, (b) renameself→self_inside formula expressions when a receiver exists, and (c) qualify calls/paths withSelf::when expanding within animpl. - Extended analyzer handling so
#[thrust::extern_spec_fn]can be processed when attached to impl items (and trait items), plus improved annotated-path resolution via type checking.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| thrust-macros/src/lib.rs | Adds context macro, extracts impl context, rewrites self in formulas, and adjusts generated paths/where-clauses for impl-method expansions. |
| thrust-macros/Cargo.toml | Updates syn features for the new visitor-based implementation. |
| tests/ui/pass/annot_struct_impl.rs | Adds a passing UI test demonstrating requires/ensures on methods inside a generic impl wrapped with #[thrust_macros::context]. |
| tests/ui/fail/annot_struct_impl.rs | Adds a failing UI test to ensure incorrect method postconditions are rejected in the new impl-annotation scenario. |
| src/analyze/local_def.rs | Allows extern_spec_fn target extraction for impl items (and trait items), not just top-level function items. |
| src/analyze.rs | Resolves annotated paths using typeck (qpath_res) instead of relying on syntactic QPath::Resolved. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let syn::ImplItem::Fn(item) = item else { | ||
| continue; | ||
| }; | ||
| // TODO: why ::thrust_macros doesn't work here? |
Owner
Author
There was a problem hiding this comment.
I am leaving unclear question to proceed for now
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This example:
expands like the following:
thrust_macros::contextwhich copies impl information to each inner items so that the inner proc macros can make use of it (viathrust::_impl_contextattribute which is not used by backend)selfis now<&Self as Model>::Ty, not&Self. thrust_macros now renames the parameters andselfin the formula expression accordingly to handle this