Skip to content

lint: add bad opt access internal lint#99710

Merged
bors merged 3 commits intorust-lang:masterfrom
davidtwco:internal-lint-opts
Jul 27, 2022
Merged

lint: add bad opt access internal lint#99710
bors merged 3 commits intorust-lang:masterfrom
davidtwco:internal-lint-opts

Conversation

@davidtwco
Copy link
Member

@davidtwco davidtwco commented Jul 25, 2022

Prompted by Zulip discussion.

Some command-line options accessible through sess.opts are best accessed through wrapper functions on Session, TyCtxt or otherwise, rather than through field access on the option struct in the Session.

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_access which 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 Session or TyCtxt which 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.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants