Skip to content

Commit 3e2972a

Browse files
authored
chore: Enforce lint rule clippy::needless_pass_by_value to datafusion-catalog (apache#18638)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes apache#18609. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> The type `impl AsRef<str>` is implicitly `Sized`, meaning its size is known at compile time. `&(impl AsRef<str>)` is a reference to a concrete type that implements `AsRef<str>` and is `Sized`. However, this `Sized` bound prevents passing references to dynamically sized types such as `&str`, `String`, or `Box<dyn Trait>`. Therefore, we add `+ ?Sized` to indicate that the referenced type might not have a fixed size — that is, it allows the referenced type to be dynamically sized. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> - Enforce lint rule `clippy::needless_pass_by_value` to `datafusion-catalog`. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> Signed-off-by: Alan Tang <jmtangcs@gmail.com>
1 parent 5053c71 commit 3e2972a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

datafusion/catalog/src/information_schema.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl InformationSchemaConfig {
245245
name,
246246
"FUNCTION",
247247
Self::is_deterministic(udf.signature()),
248-
return_type,
248+
return_type.as_ref(),
249249
"SCALAR",
250250
udf.documentation().map(|d| d.description.to_string()),
251251
udf.documentation().map(|d| d.syntax_example.to_string()),
@@ -265,7 +265,7 @@ impl InformationSchemaConfig {
265265
name,
266266
"FUNCTION",
267267
Self::is_deterministic(udaf.signature()),
268-
return_type,
268+
return_type.as_ref(),
269269
"AGGREGATE",
270270
udaf.documentation().map(|d| d.description.to_string()),
271271
udaf.documentation().map(|d| d.syntax_example.to_string()),
@@ -285,7 +285,7 @@ impl InformationSchemaConfig {
285285
name,
286286
"FUNCTION",
287287
Self::is_deterministic(udwf.signature()),
288-
return_type,
288+
return_type.as_ref(),
289289
"WINDOW",
290290
udwf.documentation().map(|d| d.description.to_string()),
291291
udwf.documentation().map(|d| d.syntax_example.to_string()),
@@ -418,11 +418,11 @@ fn get_udf_args_and_return_types(
418418
// only handle the function which implemented [`ScalarUDFImpl::return_type`] method
419419
let return_type = udf
420420
.return_type(&arg_types)
421-
.map(|t| remove_native_type_prefix(NativeType::from(t)))
421+
.map(|t| remove_native_type_prefix(&NativeType::from(t)))
422422
.ok();
423423
let arg_types = arg_types
424424
.into_iter()
425-
.map(|t| remove_native_type_prefix(NativeType::from(t)))
425+
.map(|t| remove_native_type_prefix(&NativeType::from(t)))
426426
.collect::<Vec<_>>();
427427
(arg_types, return_type)
428428
})
@@ -445,10 +445,10 @@ fn get_udaf_args_and_return_types(
445445
let return_type = udaf
446446
.return_type(&arg_types)
447447
.ok()
448-
.map(|t| remove_native_type_prefix(NativeType::from(t)));
448+
.map(|t| remove_native_type_prefix(&NativeType::from(t)));
449449
let arg_types = arg_types
450450
.into_iter()
451-
.map(|t| remove_native_type_prefix(NativeType::from(t)))
451+
.map(|t| remove_native_type_prefix(&NativeType::from(t)))
452452
.collect::<Vec<_>>();
453453
(arg_types, return_type)
454454
})
@@ -470,7 +470,7 @@ fn get_udwf_args_and_return_types(
470470
// only handle the function which implemented [`ScalarUDFImpl::return_type`] method
471471
let arg_types = arg_types
472472
.into_iter()
473-
.map(|t| remove_native_type_prefix(NativeType::from(t)))
473+
.map(|t| remove_native_type_prefix(&NativeType::from(t)))
474474
.collect::<Vec<_>>();
475475
(arg_types, None)
476476
})
@@ -479,7 +479,7 @@ fn get_udwf_args_and_return_types(
479479
}
480480

481481
#[inline]
482-
fn remove_native_type_prefix(native_type: NativeType) -> String {
482+
fn remove_native_type_prefix(native_type: &NativeType) -> String {
483483
format!("{native_type}")
484484
}
485485

@@ -679,7 +679,7 @@ impl InformationSchemaViewBuilder {
679679
catalog_name: impl AsRef<str>,
680680
schema_name: impl AsRef<str>,
681681
table_name: impl AsRef<str>,
682-
definition: Option<impl AsRef<str>>,
682+
definition: Option<&(impl AsRef<str> + ?Sized)>,
683683
) {
684684
// Note: append_value is actually infallible.
685685
self.catalog_names.append_value(catalog_name.as_ref());
@@ -1164,7 +1164,7 @@ impl InformationSchemaRoutinesBuilder {
11641164
routine_name: impl AsRef<str>,
11651165
routine_type: impl AsRef<str>,
11661166
is_deterministic: bool,
1167-
data_type: Option<impl AsRef<str>>,
1167+
data_type: Option<&impl AsRef<str>>,
11681168
function_type: impl AsRef<str>,
11691169
description: Option<impl AsRef<str>>,
11701170
syntax_example: Option<impl AsRef<str>>,
@@ -1298,7 +1298,7 @@ impl InformationSchemaParametersBuilder {
12981298
specific_name: impl AsRef<str>,
12991299
ordinal_position: u64,
13001300
parameter_mode: impl AsRef<str>,
1301-
parameter_name: Option<impl AsRef<str>>,
1301+
parameter_name: Option<&(impl AsRef<str> + ?Sized)>,
13021302
data_type: impl AsRef<str>,
13031303
parameter_default: Option<impl AsRef<str>>,
13041304
is_variadic: bool,

datafusion/catalog/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
// Make sure fast / cheap clones on Arc are explicit:
2424
// https://github.com/apache/datafusion/issues/11143
2525
#![cfg_attr(not(test), deny(clippy::clone_on_ref_ptr))]
26+
#![deny(clippy::needless_pass_by_value)]
27+
#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
2628

2729
//! Interfaces and default implementations of catalogs and schemas.
2830
//!

0 commit comments

Comments
 (0)