Repository navigation
New lint clippy::allow_attributes #18881
Description
Is your feature request related to a problem or challenge?
Lint reference: https://rust-lang.github.io/rust-clippy/master/index.html?search=allow_att#allow_attributes
Checks for usage of the
#[allow]attribute and suggests replacing it with the#[expect]attribute (See RFC 2383)
#[expect]attributes suppress the lint emission, but emit a warning, if the expectation is unfulfilled. This can be useful to be notified when the lint is no longer triggered.
We have a quite a few occurrences of #[allow] in our codebase, but should prefer #[expect] instead for the reasons above.
Describe the solution you'd like
Similar to #18503 we should roll this lint our gradually through crates before finally enabling at the workspace level so we don't have one big PR.
Describe alternatives you've considered
Don't enable this lint if we don't see value or if the false positive rate is too high (see below).
Additional context
I tested it for some of our current #[allow]s and it has some false positives, especially for dead_code and deprecated.
Example 1
datafusion/datafusion/core/benches/data_utils/mod.rs
Lines 37 to 40 in c8d26ba
| /// create an in-memory table given the partition len, array len, and batch size, | |
| /// and the result table will be of array_len in total, and then partitioned, and batched. | |
| #[allow(dead_code)] | |
| pub fn create_table_provider( |
- If I switch this to
#[expect(dead_code)]then clippy will flag it asthis lint expectation is unfulfilled. But if I remove the lint then the dead code warning pops up anyway 🤔
Example 2
datafusion/datafusion/execution/src/disk_manager.rs
Lines 117 to 136 in c8d26ba
| /// Configuration for temporary disk access | |
| #[allow(deprecated)] | |
| #[deprecated(since = "48.0.0", note = "Use DiskManagerBuilder instead")] | |
| #[derive(Debug, Clone, Default)] | |
| pub enum DiskManagerConfig { | |
| /// Use the provided [DiskManager] instance | |
| Existing(Arc<DiskManager>), | |
| /// Create a new [DiskManager] that creates temporary files within | |
| /// a temporary directory chosen by the OS | |
| #[default] | |
| NewOs, | |
| /// Create a new [DiskManager] that creates temporary files within | |
| /// the specified directories | |
| NewSpecified(Vec<PathBuf>), | |
| /// Disable disk manager, attempts to create temporary files will error | |
| Disabled, | |
| } |
- Switching this to
#[expect(deprecated)]causes similar to above, but also flagsNewOSvariant as using deprecated variant. Something to do with howDefaultis derived?
(I say false positive but it seems more like a bug in clippy 🤔)
Maybe there are solutions for the above, I haven't looked into it much yet.
Another thing to keep in mind is how features interact, for example here:
datafusion/datafusion/datasource-parquet/src/reader.rs
Lines 290 to 304 in c8d26ba
| fn get_metadata<'a>( | |
| &'a mut self, | |
| #[allow(unused_variables)] options: Option<&'a ArrowReaderOptions>, | |
| ) -> BoxFuture<'a, parquet::errors::Result<Arc<ParquetMetaData>>> { | |
| let object_meta = self.partitioned_file.object_meta.clone(); | |
| let metadata_cache = Arc::clone(&self.metadata_cache); | |
| async move { | |
| #[cfg(feature = "parquet_encryption")] | |
| let file_decryption_properties = options | |
| .and_then(|o| o.file_decryption_properties()) | |
| .map(Arc::clone); | |
| #[cfg(not(feature = "parquet_encryption"))] | |
| let file_decryption_properties = None; |
- This
#[allow]is for whenparquet_encryptionfeature is not enabled, but if we change it to#[expect]blindly then I believe it'll cause issues whenparquet_encryptionis enabled, so we need to be careful
Tasks
- datafusion chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-catalog Enable clippy::allow_attributes lint for datafusion-catalog #18973
- datafusion-catalog-listing chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-common chore: enforce clippy::allow_attributes for common crates #18988
- datafusion-common-runtime chore: enforce clippy::allow_attributes for common crates #18988
- datafusion-datasource chore: enforce clippy::allow_attributes for datasource crates #19068
- datafusion-datasource-arrow chore: enforce clippy::allow_attributes for datasource crates #19068
- datafusion-datasource-avro chore: enforce clippy::allow_attributes for datasource crates #19068
- datafusion-datasource-csv chore: enforce clippy::allow_attributes for datasource crates #19068
- datafusion-datasource-json chore: enforce clippy::allow_attributes for datasource crates #19068
- datafusion-datasource-parquet chore: enforce clippy::allow_attributes for datasource crates #19068
- datafusion-doc chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-execution chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-expr chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-expr-common chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-ffi chore: enforce clippy::allow_attributes for datafusion-ffi crate #19480
- datafusion-functions chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-functions-aggregate chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-functions-aggregate-common chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-functions-nested chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-functions-table chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-functions-window chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-functions-window-common chore: enforce clippy::allow_attributes for functions-* crates #18986
- datafusion-macros chore: enforce
clippy::allow_attributesfor optimizer and macros #19310 - datafusion-optimizer chore: enforce
clippy::allow_attributesfor optimizer and macros #19310 - datafusion-physical-expr deny on allow_attributes lint in physical-plan #18983
- datafusion-physical-expr-adapter chore: enforce clippy::allow_attributes for physical crates #19185
- datafusion-physical-expr-common chore: enforce clippy::allow_attributes for physical crates #19185
- datafusion-physical-optimizer chore: enforce clippy::allow_attributes for physical crates #19185
- datafusion-physical-plan deny on allow_attributes lint in physical-plan #18983
- datafusion-proto chore: enforce clippy::allow_attributes for proto, pruning, session #19350
- datafusion-proto-common chore: enforce clippy::allow_attributes for 7 crates #19133
- datafusion-pruning chore: enforce clippy::allow_attributes for proto, pruning, session #19350
- datafusion-session chore: enforce clippy::allow_attributes for proto, pruning, session #19350
- datafusion-spark chore: enforce clippy::allow_attributes for spark,sql,sustrait #19309
- datafusion-sql chore: enforce clippy::allow_attributes for spark,sql,sustrait #19309
- datafusion-substrait chore: enforce clippy::allow_attributes for spark,sql,sustrait #19309
- Enable it globally after all the above tasks are finished Enforce
clippy::allow_attributesglobally across workspace #19576
Note: we would welcome PRs that can do multiple crates in a single PR (so long as the diff isn't too large). Felt a bit overwhelmed by the volume and speed of PRs that came in for #18503 😅
Activity
Jefffrey commentedon Nov 22, 2025
Thoughts @2010YOUY01 ?
2010YOUY01 commentedon Nov 23, 2025
If there is a good way to deal with the mentioned feature flag issue, I think we should add this lint rule.
Jefffrey commentedon Nov 23, 2025
It would look something like this:
Doable, but a little verbose.
2010YOUY01 commentedon Nov 24, 2025
I think this marker describes the arg quite precisely: 'this arg is only used in
parquet_encryption' feature.So I'm +1 for this lint. Maybe we should add comment like the above explanation, to deal with the verbosity.
Jefffrey commentedon Nov 24, 2025
I've marked it as good first issue, but note to anyone interested, please do not assign this issue to yourself as it is meant to be a tracking issue. Just pick a crate (or crates) that is not yet done/in-progress and leave a comment with your intention to work on those crates (to avoid overlap).
YuraLitvinov commentedon Nov 24, 2025
Hello, if it's okay I am taking the physical-plan.
carlosahs commentedon Nov 27, 2025
Hi! If no one else is working on datafusion-functions-nested, I can take that.
chakkk309 commentedon Nov 27, 2025
Hi all, I would like to take the following crates:
datafusion-catalogdatafusion-listingdatafusion-commondatafusion-common-runtimedatafusion-datasourcedatafusion-datasource-arrowdatafusion-datasource-avrodatafusion-datasource-csvdatafusion-datasource-jsondatafusion-datasource-parquetdatafusion-docdatafusion-executiondatafusion-exprdatafusion-expr-commondatafusion-fficarlosahs commentedon Nov 27, 2025
@Jefffrey, for
datafusion-functions-nestedit suffices to add#![deny(clippy::allow_attributes)]as there is no usage of#[allow]. The same applies todatafusion-functions-table. If it's ok, I'll create a PR to enforceclippy::allow_attributesfor alldatafusion-functions-*crates as it looks like usage of#[allow]is low and to avoid raising multiple 1-liner PRs.Jefffrey commentedon Nov 28, 2025
That sounds good, thanks
Enable clippy::allow_attributes lint for datafusion-catalog (#18973)
14 remaining items
kumarUjjawal commentedon Dec 13, 2025
I'm tackling:
datafusion-spark
datafusion-sql
datafusion-substrait
kumarUjjawal commentedon Dec 13, 2025
@Jefffrey I opened a PR with changes to three of the crates, do take a look when you get the time.
kumarUjjawal commentedon Dec 13, 2025
@Jefffrey Opened PR for few other crates:
kumarUjjawal commentedon Dec 13, 2025
@Jefffrey I looked into the reamining three and I think they don't require the changes.
datafusion-proto: We should keep the parquetmax_statistics_sizelint as#[allow(deprecated)]because the deprecation isn’t emitted in all builds, and using expect causes unfulfilled-lint failures; thre are no other changes needed.datafusion-pruning: The two#[allow(dead_code)]in pruning predicates because they cover parquet-only code paths and would risk unfulfilled expectations when the feature is disabled.datafusion-session: no allow/expect present.Jefffrey commentedon Dec 14, 2025
We should still apply the deny at their lib.rs level, and any exceptions we handle on a case by case basis, so I still expect PRs for these crates.
But it sounds like these can be fixed if we ensure the lint is expected only when certain features are enabled, see: #18881 (comment)
carlosahs commentedon Dec 14, 2025
@kumarUjjawal, let's remember that the purpose of
expectis to be identical toallow, but will cause a lint to be emitted when the code it decorates does not raise a lint warning. With this in mind I want to highlight the following:datafusion-proto: We should remove the#[allow(deprecated)]lints asmax_statistics_sizeno longer exists (ref).expectis essentially helping us to identify that we don't need to add thedeprecatedattribute because there are no more deprecated fields forParquetOptions:datafusion/datafusion/common/src/config.rs
Lines 656 to 840 in fedddbc
max_statistics_size:datafusion-pruning: For this one I think we need to first figure out ifthis is only used byparquetfeature right nowclaims are still valid.pruning_predicate.rswas created from logic initially living inlib.rsas part of this refactor: refactor: move PruningPredicate into its own module #16587. And that PR was from Jun 27. It's likely claim is no longer valid sinceexpectis failing with unfulfilled lint expectation errors, in which case I think we should remove the#![allow(dead_code)]datafusion-session: I think it's best to enable#![deny(clippy::allow_attributes)]for future use cases. Case fromdatafusion-protosuggests ifexpectwas used instead ofallow, thendeprecatedattributes would've been removed too whenmax_statistics_sizewas removed.My suggestion when facing
-D unfulfilled-lint-expectationserrors is to first identify possible root causes, then track down the root cause, and finally document why anallowneeds to be removed based on such findings.chore: enforce clippy::allow_attributes for spark,sql,sustrait (#19309)
kumarUjjawal commentedon Dec 16, 2025
Opened a PR for:
chore: enforce `clippy::allow_attributes` for optimizer and macros (#…
chore: enforce clippy::allow_attributes for proto, pruning, session (#…
chore: enforce clippy::allow_attributes for datafusion-ffi crate (#19480
Enforce `clippy::allow_attributes` globally across workspace (#19576)
Enforce `clippy::allow_attributes` globally across workspace (apache#…