Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Sep 3, 2024
1 parent 55404f9 commit 320c0b9
Show file tree
Hide file tree
Showing 7 changed files with 1,250 additions and 147 deletions.
1,355 changes: 1,229 additions & 126 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::functions::MUST_USE_CANDIDATE_INFO,
crate::functions::MUST_USE_UNIT_INFO,
crate::functions::NOT_UNSAFE_PTR_ARG_DEREF_INFO,
crate::functions::REF_OPTION_SIG_INFO,
crate::functions::REF_OPTION_INFO,
crate::functions::RENAMED_FUNCTION_PARAMS_INFO,
crate::functions::RESULT_LARGE_ERR_INFO,
crate::functions::RESULT_UNIT_ERR_INFO,
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod impl_trait_in_params;
mod misnamed_getters;
mod must_use;
mod not_unsafe_ptr_arg_deref;
mod ref_option_sig;
mod ref_option;
mod renamed_function_params;
mod result;
mod too_many_arguments;
Expand Down Expand Up @@ -415,7 +415,7 @@ declare_clippy_lint! {
/// fn foo(a: Option<&String>) {}
/// ```
#[clippy::version = "1.82.0"]
pub REF_OPTION_SIG,
pub REF_OPTION,
nursery,
"function signature uses `&Option<T>` instead of `Option<&T>`"
}
Expand Down Expand Up @@ -458,7 +458,7 @@ impl_lint_pass!(Functions => [
MISNAMED_GETTERS,
IMPL_TRAIT_IN_PARAMS,
RENAMED_FUNCTION_PARAMS,
REF_OPTION_SIG,
REF_OPTION,
]);

impl<'tcx> LateLintPass<'tcx> for Functions {
Expand All @@ -482,15 +482,15 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
must_use::check_item(cx, item);
result::check_item(cx, item, self.large_error_threshold);
ref_option_sig::check_item(cx, item);
ref_option::check_item(cx, item);
}

fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
must_use::check_impl_item(cx, item);
result::check_impl_item(cx, item, self.large_error_threshold);
impl_trait_in_params::check_impl_item(cx, item);
renamed_function_params::check_impl_item(cx, item, &self.trait_ids);
ref_option_sig::check_impl_item(cx, item);
ref_option::check_impl_item(cx, item);
}

fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
Expand All @@ -499,6 +499,6 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
must_use::check_trait_item(cx, item);
result::check_trait_item(cx, item, self.large_error_threshold);
impl_trait_in_params::check_trait_item(cx, item, self.avoid_breaking_exported_api);
ref_option_sig::check_trait_item(cx, item);
ref_option::check_trait_item(cx, item);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::functions::hir::GenericArg;
use crate::functions::REF_OPTION_SIG;
use crate::functions::REF_OPTION;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet;
use rustc_errors::Applicability;
Expand Down Expand Up @@ -31,7 +31,7 @@ fn check_fn_sig(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, sig_span: Span) {
if !fixes.is_empty() {
span_lint_and_then(
cx,
REF_OPTION_SIG,
REF_OPTION,
sig_span,
"it is more idiomatic to use `Option<&T>` instead of `&Option<T>`",
|diag| {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused, clippy::all)]
#![warn(clippy::ref_option_sig)]
#![warn(clippy::ref_option)]

fn main() {}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/ref_option_sig.rs → tests/ui/ref_option.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused, clippy::all)]
#![warn(clippy::ref_option_sig)]
#![warn(clippy::ref_option)]

fn main() {}

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/ref_option_sig.stderr → tests/ui/ref_option.stderr
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:6:1
--> tests/ui/ref_option.rs:6:1
|
LL | fn opt_u8(a: &Option<u8>) {}
| ^^^^^^^^^^^^^-----------^
| |
| help: change this to: `Option<&u8>`
|
= note: `-D clippy::ref-option-sig` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ref_option_sig)]`
= note: `-D clippy::ref-option` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:7:1
--> tests/ui/ref_option.rs:7:1
|
LL | fn opt_gen<T>(a: &Option<T>) {}
| ^^^^^^^^^^^^^^^^^----------^
| |
| help: change this to: `Option<&T>`

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:8:1
--> tests/ui/ref_option.rs:8:1
|
LL | fn opt_string(a: &Option<String>) {}
| ^^^^^^^^^^^^^^^^^---------------^
| |
| help: change this to: `Option<&String>`

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:9:1
--> tests/ui/ref_option.rs:9:1
|
LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -37,31 +37,31 @@ LL | fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
| ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:11:1
--> tests/ui/ref_option.rs:11:1
|
LL | pub fn pub_opt_string(a: &Option<String>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| help: change this to: `Option<&String>`

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:14:5
--> tests/ui/ref_option.rs:14:5
|
LL | fn trait_opt(&self, a: &Option<Vec<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^----------------^^
| |
| help: change this to: `Option<&Vec<u8>>`

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:18:5
--> tests/ui/ref_option.rs:18:5
|
LL | fn private_trait_opt(&self, a: &Option<Option<String>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^
| |
| help: change this to: `Option<&Option<String>>`

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option_sig.rs:24:5
--> tests/ui/ref_option.rs:24:5
|
LL | pub fn opt_params(&self, a: &Option<()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^
Expand Down

0 comments on commit 320c0b9

Please sign in to comment.