Make '#[allow(private_bounds)]' compiler version-aware #2689
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.
The current fix for #2608 as implemented in e7ef93b addressed the problem by introducing both the new
private_bounds
lint rule and the deprecatedprivate_in_public
one. To smooth out the cross-version incompatibilities, @SergioBenitez added two more lint rules, namelyrenamed_and_removed_lints
andunknown_lints
, to suppress the warnings on both old and newrustc
s.Rocket/core/codegen/src/derive/from_form.rs
Lines 123 to 131 in b3abc76
However, we can take one step further by utilizing
version_check
dependency. This PR proposes that the said crate checks the availability ofprivate_bounds
at codegen time, allowing for fewer lint rules generated in the AST.The fix is implemented by introducing an auxiliary variable
lints
, which expands to different attributes of lint rules when compiled on different versions ofrustc
. Whenrustc
is newer than1.74.0
, it is set to the token stream of#[allow(private_bounds)]
, utilizing the new feature; otherwise it is equal to the old sequence of#[allow(...)]
rules. The need for#[allow(unknown_lints)]
is eliminated.Pros. Less lint rules generated while retaining the effect of the fix in e7ef93b.
Cons. None known to the author.
Feel free to make comments and suggest edits to this PR! 👋