@@ -9,7 +9,7 @@ use rustc_hir::{self as hir, AmbigArg, Expr, ExprKind, HirId, QPath};
99use rustc_lint:: { LateContext , LateLintPass } ;
1010use rustc_middle:: ty:: TyCtxt ;
1111use rustc_session:: impl_lint_pass;
12- use rustc_span:: def_id:: DefId ;
12+ use rustc_span:: def_id:: { CrateNum , DefId } ;
1313use rustc_span:: { ExpnKind , Span , sym} ;
1414
1515declare_clippy_lint ! {
@@ -83,16 +83,22 @@ pub struct IncompatibleMsrv {
8383 msrv : Msrv ,
8484 availability_cache : FxHashMap < ( DefId , bool ) , Availability > ,
8585 check_in_tests : bool ,
86+ core_crate : Option < CrateNum > ,
8687}
8788
8889impl_lint_pass ! ( IncompatibleMsrv => [ INCOMPATIBLE_MSRV ] ) ;
8990
9091impl IncompatibleMsrv {
91- pub fn new ( conf : & ' static Conf ) -> Self {
92+ pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
9293 Self {
9394 msrv : conf. msrv ,
9495 availability_cache : FxHashMap :: default ( ) ,
9596 check_in_tests : conf. check_incompatible_msrv_in_tests ,
97+ core_crate : tcx
98+ . crates ( ( ) )
99+ . iter ( )
100+ . find ( |krate| tcx. crate_name ( * * krate) == sym:: core)
101+ . copied ( ) ,
96102 }
97103 }
98104
@@ -140,23 +146,16 @@ impl IncompatibleMsrv {
140146 // We don't check local items since their MSRV is supposed to always be valid.
141147 return ;
142148 }
143- if let ExpnKind :: AstPass ( _) | ExpnKind :: Desugaring ( _) = span. ctxt ( ) . outer_expn_data ( ) . kind {
149+ let expn_data = span. ctxt ( ) . outer_expn_data ( ) ;
150+ if let ExpnKind :: AstPass ( _) | ExpnKind :: Desugaring ( _) = expn_data. kind {
144151 // Desugared expressions get to cheat and stability is ignored.
145152 // Intentionally not using `.from_expansion()`, since we do still care about macro expansions
146153 return ;
147154 }
148-
149155 // Functions coming from `core` while expanding a macro such as `assert*!()` get to cheat too: the
150156 // macros may have existed prior to the checked MSRV, but their expansion with a recent compiler
151157 // might use recent functions or methods. Compiling with an older compiler would not use those.
152- if span. from_expansion ( )
153- && cx. tcx . crate_name ( def_id. krate ) == sym:: core
154- && span
155- . ctxt ( )
156- . outer_expn_data ( )
157- . macro_def_id
158- . is_some_and ( |def_id| cx. tcx . crate_name ( def_id. krate ) == sym:: core)
159- {
158+ if Some ( def_id. krate ) == self . core_crate && expn_data. macro_def_id . map ( |did| did. krate ) == self . core_crate {
160159 return ;
161160 }
162161
0 commit comments