lint: add bad opt access internal lint#99710
Merged
bors merged 3 commits intorust-lang:masterfrom Jul 27, 2022
Merged
Conversation
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.
Prompted by Zulip discussion.
Some command-line options accessible through
sess.optsare best accessed through wrapper functions onSession,TyCtxtor otherwise, rather than through field access on the option struct in theSession.Adds a new lint which triggers on those options that should be accessed through a wrapper function so that this is prohibited. Options are annotated with a new attribute
rustc_lint_opt_deny_field_accesswhich can specify the error message (i.e. "use this other function instead") to be emitted.A simpler alternative would be to simply rename the options in the option type so that it is clear they should not be used, however this doesn't prevent uses, just discourages them. Another alternative would be to make the option fields private, and adding accessor functions on the option types, however the wrapper functions sometimes rely on additional state from
SessionorTyCtxtwhich wouldn't be available in an function on the option type, so the accessor would simply make the field available and its use would be discouraged too.Leave a comment if there's an option I should add this to.