rust/compiler/rustc_passes/src
David Wood 7bab769b58 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>
2022-07-27 11:24:27 +01:00
..
liveness Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
check_attr.rs lint: add bad opt access internal lint 2022-07-27 11:24:27 +01:00
check_const.rs Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
dead.rs Rewrite dead-code pass to avoid fetching HIR. 2022-06-22 20:48:18 +02:00
debugger_visualizer.rs Respond to PR comments. 2022-05-25 10:44:56 -07:00
diagnostic_items.rs remove DiagnosticItemCollector 2022-05-13 11:46:05 -04:00
entry.rs avoid Symbol to &str conversions 2022-07-18 14:25:34 +09:00
errors.rs lint: add bad opt access internal lint 2022-07-27 11:24:27 +01:00
hir_id_validator.rs Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
hir_stats.rs move else block into the Local struct 2022-07-11 23:20:37 +02:00
lang_items.rs use def_span and def_kind queries instead of calling tcx.hir() methods 2022-05-06 12:11:05 -04:00
layout_test.rs remove LayoutTest 2022-05-13 11:46:05 -04:00
lib.rs Stabilize let_chains 2022-07-16 20:17:58 -03:00
lib_features.rs passes: check implied feature exists 2022-07-20 15:50:59 +01:00
liveness.rs move else block into the Local struct 2022-07-11 23:20:37 +02:00
loops.rs Add an indirection for closures in hir::ExprKind 2022-07-12 21:00:13 +04:00
naked_functions.rs Reword comments and rename HIR visiting methods. 2022-07-07 16:01:43 +02:00
reachable.rs Add an indirection for closures in hir::ExprKind 2022-07-12 21:00:13 +04:00
stability.rs avoid embedding StabilityLevel::Unstable reason string into metadata multiple times 2022-07-21 22:53:02 +03:00
upvars.rs Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
weak_lang_items.rs Use FxIndexMap instead of otherwise unused StableMap for WEAK_ITEMS_REFS. 2022-07-20 12:40:51 +02:00