Skip to content

Commit dd005c1

Browse files
committed
Added MSRV and fixed typo
1 parent a451b2a commit dd005c1

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

clippy_lints/src/from_over_into.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use crate::utils::paths::INTO;
2-
use crate::utils::{match_def_path, span_lint_and_help};
2+
use crate::utils::{match_def_path, meets_msrv, span_lint_and_help};
33
use if_chain::if_chain;
44
use rustc_hir as hir;
5-
use rustc_lint::{LateContext, LateLintPass};
6-
use rustc_session::{declare_lint_pass, declare_tool_lint};
5+
use rustc_lint::{LateContext, LateLintPass, LintContext};
6+
use rustc_semver::RustcVersion;
7+
use rustc_session::{declare_tool_lint, impl_lint_pass};
8+
9+
const FROM_OVER_INTO_MSRV: RustcVersion = RustcVersion::new(1, 41, 0);
710

811
declare_clippy_lint! {
912
/// **What it does:** Searches for implementations of the `Into<..>` trait and suggests to implement `From<..>` instead.
@@ -38,10 +41,25 @@ declare_clippy_lint! {
3841
"Warns on implementations of `Into<..>` to use `From<..>`"
3942
}
4043

41-
declare_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
44+
pub struct FromOverInto {
45+
msrv: Option<RustcVersion>,
46+
}
47+
48+
impl FromOverInto {
49+
#[must_use]
50+
pub fn new(msrv: Option<RustcVersion>) -> Self {
51+
FromOverInto { msrv }
52+
}
53+
}
54+
55+
impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
4256

4357
impl LateLintPass<'_> for FromOverInto {
4458
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
59+
if !meets_msrv(self.msrv.as_ref(), &FROM_OVER_INTO_MSRV) {
60+
return;
61+
}
62+
4563
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
4664
if_chain! {
4765
if let hir::ItemKind::Impl{ .. } = &item.kind;
@@ -55,9 +73,11 @@ impl LateLintPass<'_> for FromOverInto {
5573
item.span,
5674
"An implementation of From is preferred since it gives you Into<..> for free where the reverse isn't true.",
5775
None,
58-
"consider implement From instead",
76+
"consider to implement From instead",
5977
);
6078
}
6179
}
6280
}
81+
82+
extract_msrv_attr!(LateContext);
6383
}

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10161016
store.register_late_pass(move || box checked_conversions::CheckedConversions::new(msrv));
10171017
store.register_late_pass(move || box mem_replace::MemReplace::new(msrv));
10181018
store.register_late_pass(move || box ranges::Ranges::new(msrv));
1019+
store.register_late_pass(move || box from_over_into::FromOverInto::new(msrv));
10191020
store.register_late_pass(move || box use_self::UseSelf::new(msrv));
10201021
store.register_late_pass(move || box missing_const_for_fn::MissingConstForFn::new(msrv));
10211022

@@ -1205,7 +1206,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12051206
store.register_late_pass(|| box manual_unwrap_or::ManualUnwrapOr);
12061207
store.register_late_pass(|| box manual_ok_or::ManualOkOr);
12071208
store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs);
1208-
store.register_late_pass(|| box from_over_into::FromOverInto);
12091209
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
12101210
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
12111211
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));

tests/ui/from_over_into.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | | }
99
| |_^
1010
|
1111
= note: `-D clippy::from-over-into` implied by `-D warnings`
12-
= help: consider implement From instead
12+
= help: consider to implement From instead
1313

1414
error: aborting due to previous error
1515

tests/ui/min_rust_version_attr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ pub fn checked_conversion() {
5757
let _ = value <= (u32::MAX as i64) && value >= 0;
5858
}
5959

60+
pub struct FromOverInto(String);
61+
62+
impl Into<FromOverInto> for String {
63+
fn into(self) -> FromOverInto {
64+
FromOverInto(self)
65+
}
66+
}
67+
6068
pub fn filter_map_next() {
6169
let a = ["1", "lol", "3", "NaN", "5"];
6270

tests/ui/min_rust_version_attr.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error: stripping a prefix manually
2-
--> $DIR/min_rust_version_attr.rs:142:24
2+
--> $DIR/min_rust_version_attr.rs:150:24
33
|
44
LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::manual-strip` implied by `-D warnings`
88
note: the prefix was tested here
9-
--> $DIR/min_rust_version_attr.rs:141:9
9+
--> $DIR/min_rust_version_attr.rs:149:9
1010
|
1111
LL | if s.starts_with("hello, ") {
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,13 +17,13 @@ LL | assert_eq!(<stripped>.to_uppercase(), "WORLD!");
1717
|
1818

1919
error: stripping a prefix manually
20-
--> $DIR/min_rust_version_attr.rs:154:24
20+
--> $DIR/min_rust_version_attr.rs:162:24
2121
|
2222
LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
2323
| ^^^^^^^^^^^^^^^^^^^^
2424
|
2525
note: the prefix was tested here
26-
--> $DIR/min_rust_version_attr.rs:153:9
26+
--> $DIR/min_rust_version_attr.rs:161:9
2727
|
2828
LL | if s.starts_with("hello, ") {
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)