-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lint: add bad opt access internal lint #99710
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
Maybe also enable this lint for cli_forced_codegen_units, verify_llvm_ir, lto, thinlto and plt? Or even for all fields which have a wrapper, no matter how small? |
This comment was marked as resolved.
This comment was marked as resolved.
a9976d2
to
3002aa4
Compare
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment was marked as resolved.
This comment was marked as resolved.
3002aa4
to
f65e87e
Compare
An even simpler alternative would be to make these fields inaccessible using standard Rust visibility restrictions? |
Sometimes they need to be accessed without an available |
That's the second alternative I listed, it would absolutely work, and we could add our wrapper functions to |
This comment was marked as resolved.
This comment was marked as resolved.
c0263b5
to
56f778d
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few nits, then r=me
haven't really checked the fields which have this lint, but even if one of the fields is incorrectly linted, that shouldn't hurt too much
This comment was marked as resolved.
This comment was marked as resolved.
Add a brief comment explaining why the diagnostic migration lints aren't included in the `rustc::internal` diagnostic group. Signed-off-by: David Wood <[email protected]>
If an internal lint uses `typeck_results` or similar queries then that can result in rustdoc checking code that it shouldn't (e.g. from other platforms) and emit compilation errors. Signed-off-by: David Wood <[email protected]>
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 <[email protected]>
56f778d
to
7bab769
Compare
@bors r=lcnr |
…laumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#94247 (Fix slice::ChunksMut aliasing) - rust-lang#99358 (Allow `ValTree::try_to_raw_bytes` on `u8` array) - rust-lang#99651 (Deeply deny fn and raw ptrs in const generics) - rust-lang#99710 (lint: add bad opt access internal lint) - rust-lang#99717 (Add some comments to the docs issue template to clarify) - rust-lang#99728 (Clean up HIR-based lifetime resolution) - rust-lang#99812 (Fix headings colors) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Can we instead move those fields to be defined in the same crate as Session? This seems like an improvement over the status quo, but at the cost of increased complexity ... |
They already are, we could use |
|
It also doesn't prevent other accessors not using the accessor for this field - I think to do that we'd need wrapper structs in private modules or something, which feels ungreat. I think the lint is a pretty OK method of achieving our goals here. |
Prompted by Zulip discussion.
Some command-line options accessible through
sess.opts
are best accessed through wrapper functions onSession
,TyCtxt
or 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_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
orTyCtxt
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.