11use 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} ;
33use if_chain:: if_chain;
44use 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
811declare_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
4357impl 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}
0 commit comments