@@ -9,7 +9,7 @@ use rustc_hir::{self as hir, AmbigArg, Expr, ExprKind, HirId, QPath};
9
9
use rustc_lint:: { LateContext , LateLintPass } ;
10
10
use rustc_middle:: ty:: TyCtxt ;
11
11
use rustc_session:: impl_lint_pass;
12
- use rustc_span:: def_id:: DefId ;
12
+ use rustc_span:: def_id:: { CrateNum , DefId } ;
13
13
use rustc_span:: { ExpnKind , Span , sym} ;
14
14
15
15
declare_clippy_lint ! {
@@ -83,16 +83,22 @@ pub struct IncompatibleMsrv {
83
83
msrv : Msrv ,
84
84
availability_cache : FxHashMap < ( DefId , bool ) , Availability > ,
85
85
check_in_tests : bool ,
86
+ core_crate : Option < CrateNum > ,
86
87
}
87
88
88
89
impl_lint_pass ! ( IncompatibleMsrv => [ INCOMPATIBLE_MSRV ] ) ;
89
90
90
91
impl IncompatibleMsrv {
91
- pub fn new ( conf : & ' static Conf ) -> Self {
92
+ pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
92
93
Self {
93
94
msrv : conf. msrv ,
94
95
availability_cache : FxHashMap :: default ( ) ,
95
96
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 ( ) ,
96
102
}
97
103
}
98
104
@@ -140,23 +146,16 @@ impl IncompatibleMsrv {
140
146
// We don't check local items since their MSRV is supposed to always be valid.
141
147
return ;
142
148
}
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 {
144
151
// Desugared expressions get to cheat and stability is ignored.
145
152
// Intentionally not using `.from_expansion()`, since we do still care about macro expansions
146
153
return ;
147
154
}
148
-
149
155
// Functions coming from `core` while expanding a macro such as `assert*!()` get to cheat too: the
150
156
// macros may have existed prior to the checked MSRV, but their expansion with a recent compiler
151
157
// 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 {
160
159
return ;
161
160
}
162
161
0 commit comments