lint: add bad opt access internal lint
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. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
f5e005f0ca
commit
7bab769b58
19 changed files with 509 additions and 300 deletions
|
@ -329,6 +329,8 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
|
|||
})
|
||||
}
|
||||
|
||||
// JUSTIFICATION: before session exists, only config
|
||||
#[cfg_attr(not(bootstrap), allow(rustc::bad_opt_access))]
|
||||
pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
|
||||
tracing::trace!("run_compiler");
|
||||
util::run_in_thread_pool_with_globals(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue