Skip to content

Commit

Permalink
Rename lint into into_instead_of_from.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongmao86 committed Jan 31, 2021
1 parent 4016bc0 commit aae5951
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ Released 2018-09-13
[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one
[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
[`into_and_try_into_instead_of_from_and_try_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_and_try_into_instead_of_from_and_try_from
[`into_instead_of_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_instead_of_from
[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_lint::{LateLintPass, LateContext};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_hir::*;
// use rustc_span::Span;
use rustc_span::Symbol;
use rustc_span::symbol::sym;
use if_chain::if_chain;

declare_clippy_lint! {
Expand All @@ -23,32 +23,29 @@ declare_clippy_lint! {
/// ```rust
/// // example code which does not raise clippy warning
/// ```
pub INTO_AND_TRY_INTO_INSTEAD_OF_FROM_AND_TRY_FROM,
pub INTO_INSTEAD_OF_FROM,
style,
"default lint description"
}

declare_lint_pass!(IntoAndTryIntoInsteadOfFromAndTryFrom => [INTO_AND_TRY_INTO_INSTEAD_OF_FROM_AND_TRY_FROM]);
declare_lint_pass!(IntoInsteadOfFrom => [INTO_INSTEAD_OF_FROM]);

impl LateLintPass<'tcx> for IntoAndTryIntoInsteadOfFromAndTryFrom {
impl LateLintPass<'tcx> for IntoInsteadOfFrom {
fn check_where_predicate(&mut self, cx: &LateContext<'tcx>, wp: &'tcx WherePredicate<'tcx>) {
match wp {
WherePredicate::BoundPredicate(wbp) => {
if_chain! {
if wbp.bounds.len() == 1;
if let Some(tr_ref) = wbp.bounds[0].trait_ref();
if let Some(def_id) = tr_ref.trait_def_id();
then {
["From", "TryFrom"].map(|e| {
if cx.tcx.is_diagnostic_item(Symbol::intern(e), def_id) {
span_lint(
cx,
INTO_AND_TRY_INTO_INSTEAD_OF_FROM_AND_TRY_FROM,
wp.span(),
"What is WHERE PREDICATE"
);
}
});
if cx.tcx.is_diagnostic_item(sym::from_trait, def_id) {
span_lint(
cx,
INTO_INSTEAD_OF_FROM,
wp.span(),
"What is WHERE PREDICATE"
);
}
}
}
},
Expand Down
9 changes: 5 additions & 4 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ mod inherent_to_string;
mod inline_fn_without_body;
mod int_plus_one;
mod integer_division;
mod into_and_try_into_instead_of_from_and_try_from;
mod into_instead_of_from;
mod items_after_statements;
mod large_const_arrays;
mod large_enum_variant;
Expand Down Expand Up @@ -662,7 +662,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
&int_plus_one::INT_PLUS_ONE,
&integer_division::INTEGER_DIVISION,
&into_and_try_into_instead_of_from_and_try_from::INTO_AND_TRY_INTO_INSTEAD_OF_FROM_AND_TRY_FROM,
&into_instead_of_from::INTO_INSTEAD_OF_FROM,
&items_after_statements::ITEMS_AFTER_STATEMENTS,
&large_const_arrays::LARGE_CONST_ARRAYS,
&large_enum_variant::LARGE_ENUM_VARIANT,
Expand Down Expand Up @@ -1252,6 +1252,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box case_sensitive_file_extension_comparisons::CaseSensitiveFileExtensionComparisons);
store.register_late_pass(|| box redundant_slicing::RedundantSlicing);
store.register_late_pass(|| box into_and_try_into_instead_of_from_and_try_from::IntoAndTryIntoInsteadOfFromAndTryFrom);
store.register_late_pass(|| box into_instead_of_from::IntoInsteadOfFrom);

store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
Expand Down Expand Up @@ -1477,7 +1478,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY),
LintId::of(&inline_fn_without_body::INLINE_FN_WITHOUT_BODY),
LintId::of(&int_plus_one::INT_PLUS_ONE),
LintId::of(&into_and_try_into_instead_of_from_and_try_from::INTO_AND_TRY_INTO_INSTEAD_OF_FROM_AND_TRY_FROM),
LintId::of(&into_instead_of_from::INTO_INSTEAD_OF_FROM),
LintId::of(&large_const_arrays::LARGE_CONST_ARRAYS),
LintId::of(&large_enum_variant::LARGE_ENUM_VARIANT),
LintId::of(&len_zero::COMPARISON_TO_EMPTY),
Expand Down Expand Up @@ -1722,7 +1723,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&functions::RESULT_UNIT_ERR),
LintId::of(&if_let_some_result::IF_LET_SOME_RESULT),
LintId::of(&inherent_to_string::INHERENT_TO_STRING),
LintId::of(&into_and_try_into_instead_of_from_and_try_from::INTO_AND_TRY_INTO_INSTEAD_OF_FROM_AND_TRY_FROM),
LintId::of(&into_instead_of_from::INTO_INSTEAD_OF_FROM),
LintId::of(&len_zero::COMPARISON_TO_EMPTY),
LintId::of(&len_zero::LEN_WITHOUT_IS_EMPTY),
LintId::of(&len_zero::LEN_ZERO),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// run-rustfix
#![warn(clippy::into_and_try_into_instead_of_from_and_try_from)]
#![warn(clippy::into_instead_of_from)]
use std::convert::TryFrom;

fn foo<T>(a: T) where u32: From<T> {}
fn bar<T>(a: T) where u32: TryFrom<T> {}

fn main() {
// test code goes here
}

0 comments on commit aae5951

Please sign in to comment.