1
+ use derive_where:: derive_where;
1
2
use rustc_abi:: ExternAbi ;
2
3
use rustc_ast:: AttrId ;
3
4
use rustc_ast:: attr:: AttributeExt ;
@@ -8,7 +9,8 @@ use rustc_data_structures::stable_hasher::{
8
9
} ;
9
10
use rustc_error_messages:: { DiagMessage , MultiSpan } ;
10
11
use rustc_hir:: def:: Namespace ;
11
- use rustc_hir:: { HashStableContext , HirId , MissingLifetimeKind } ;
12
+ use rustc_hir:: def_id:: DefPathHash ;
13
+ use rustc_hir:: { HashStableContext , HirId , ItemLocalId , MissingLifetimeKind } ;
12
14
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
13
15
pub use rustc_span:: edition:: Edition ;
14
16
use rustc_span:: { Ident , MacroRulesNormalizedIdent , Span , Symbol , sym} ;
@@ -102,7 +104,7 @@ pub enum Applicability {
102
104
/// The index values have a type of `u16` to reduce the size of the `LintExpectationId`.
103
105
/// It's reasonable to assume that no user will define 2^16 attributes on one node or
104
106
/// have that amount of lints listed. `u16` values should therefore suffice.
105
- #[ derive( Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Debug , Hash , Encodable , Decodable ) ]
107
+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Hash , Encodable , Decodable ) ]
106
108
pub enum LintExpectationId {
107
109
/// Used for lints emitted during the `EarlyLintPass`. This id is not
108
110
/// hash stable and should not be cached.
@@ -156,13 +158,14 @@ impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
156
158
}
157
159
158
160
impl < HCX : rustc_hir:: HashStableContext > ToStableHashKey < HCX > for LintExpectationId {
159
- type KeyType = ( HirId , u16 , u16 ) ;
161
+ type KeyType = ( DefPathHash , ItemLocalId , u16 , u16 ) ;
160
162
161
163
#[ inline]
162
- fn to_stable_hash_key ( & self , _ : & HCX ) -> Self :: KeyType {
164
+ fn to_stable_hash_key ( & self , hcx : & HCX ) -> Self :: KeyType {
163
165
match self {
164
166
LintExpectationId :: Stable { hir_id, attr_index, lint_index : Some ( lint_index) } => {
165
- ( * hir_id, * attr_index, * lint_index)
167
+ let ( def_path_hash, lint_idx) = hir_id. to_stable_hash_key ( hcx) ;
168
+ ( def_path_hash, lint_idx, * attr_index, * lint_index)
166
169
}
167
170
_ => {
168
171
unreachable ! ( "HashStable should only be called for a filled `LintExpectationId`" )
@@ -174,19 +177,8 @@ impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectation
174
177
/// Setting for how to handle a lint.
175
178
///
176
179
/// See: <https://doc.rust-lang.org/rustc/lints/levels.html>
177
- #[ derive(
178
- Clone ,
179
- Copy ,
180
- PartialEq ,
181
- PartialOrd ,
182
- Eq ,
183
- Ord ,
184
- Debug ,
185
- Hash ,
186
- Encodable ,
187
- Decodable ,
188
- HashStable_Generic
189
- ) ]
180
+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Hash , Encodable , Decodable , HashStable_Generic ) ]
181
+ #[ derive_where( PartialOrd ) ]
190
182
pub enum Level {
191
183
/// The `allow` level will not issue any message.
192
184
Allow ,
@@ -201,7 +193,7 @@ pub enum Level {
201
193
///
202
194
/// The [`LintExpectationId`] is used to later link a lint emission to the actual
203
195
/// expectation. It can be ignored in most cases.
204
- Expect ( LintExpectationId ) ,
196
+ Expect ( # [ derive_where ( skip ) ] LintExpectationId ) ,
205
197
/// The `warn` level will produce a warning if the lint was violated, however the
206
198
/// compiler will continue with its execution.
207
199
Warn ,
@@ -211,7 +203,7 @@ pub enum Level {
211
203
///
212
204
/// The [`LintExpectationId`] is intended to fulfill expectations marked via the
213
205
/// `#[expect]` attribute, that will still be suppressed due to the level.
214
- ForceWarn ( Option < LintExpectationId > ) ,
206
+ ForceWarn ( # [ derive_where ( skip ) ] Option < LintExpectationId > ) ,
215
207
/// The `deny` level will produce an error and stop further execution after the lint
216
208
/// pass is complete.
217
209
Deny ,
@@ -294,6 +286,10 @@ impl Level {
294
286
_ => None ,
295
287
}
296
288
}
289
+
290
+ pub fn min ( self , other : Self ) -> Self {
291
+ if self < other { self } else { other }
292
+ }
297
293
}
298
294
299
295
/// Specification of a single lint.
0 commit comments