11use std:: borrow:: Cow ;
22use std:: fmt:: Display ;
33
4- use rustc_ast:: AttrId ;
5- use rustc_ast:: attr:: AttributeExt ;
64use rustc_data_structures:: fx:: FxIndexSet ;
75use rustc_data_structures:: stable_hasher:: {
86 HashStable , StableCompare , StableHasher , ToStableHashKey ,
@@ -12,7 +10,7 @@ use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
1210use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
1311use rustc_span:: def_id:: DefPathHash ;
1412pub use rustc_span:: edition:: Edition ;
15- use rustc_span:: { Ident , Span , Symbol , sym } ;
13+ use rustc_span:: { AttrId , Ident , Span , Symbol } ;
1614use serde:: { Deserialize , Serialize } ;
1715
1816pub use self :: Level :: * ;
@@ -107,12 +105,12 @@ pub enum Applicability {
107105pub enum LintExpectationId {
108106 /// Used for lints emitted during the `EarlyLintPass`. This id is not
109107 /// hash stable and should not be cached.
110- Unstable { attr_id : AttrId , lint_index : Option < u16 > } ,
108+ Unstable { attr_id : AttrId , lint_index : u16 } ,
111109 /// The [`HirId`] that the lint expectation is attached to. This id is
112110 /// stable and can be cached. The additional index ensures that nodes with
113111 /// several expectations can correctly match diagnostics to the individual
114112 /// expectation.
115- Stable { hir_id : HirId , attr_index : u16 , lint_index : Option < u16 > } ,
113+ Stable { hir_id : HirId , attr_id : AttrId , attr_index : u16 , lint_index : u16 } ,
116114}
117115
118116impl LintExpectationId {
@@ -123,14 +121,14 @@ impl LintExpectationId {
123121 }
124122 }
125123
126- pub fn get_lint_index ( & self ) -> Option < u16 > {
124+ pub fn get_lint_index ( & self ) -> u16 {
127125 let ( LintExpectationId :: Unstable { lint_index, .. }
128126 | LintExpectationId :: Stable { lint_index, .. } ) = self ;
129127
130128 * lint_index
131129 }
132130
133- pub fn set_lint_index ( & mut self , new_lint_index : Option < u16 > ) {
131+ pub fn set_lint_index ( & mut self , new_lint_index : u16 ) {
134132 let ( LintExpectationId :: Unstable { lint_index, .. }
135133 | LintExpectationId :: Stable { lint_index, .. } ) = self ;
136134
@@ -142,7 +140,7 @@ impl<HCX: HashStableContext> HashStable<HCX> for LintExpectationId {
142140 #[ inline]
143141 fn hash_stable ( & self , hcx : & mut HCX , hasher : & mut StableHasher ) {
144142 match self {
145- LintExpectationId :: Stable { hir_id, attr_index, lint_index : Some ( lint_index ) } => {
143+ LintExpectationId :: Stable { hir_id, attr_index, lint_index, .. } => {
146144 hir_id. hash_stable ( hcx, hasher) ;
147145 attr_index. hash_stable ( hcx, hasher) ;
148146 lint_index. hash_stable ( hcx, hasher) ;
@@ -162,7 +160,7 @@ impl<HCX: HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
162160 #[ inline]
163161 fn to_stable_hash_key ( & self , hcx : & HCX ) -> Self :: KeyType {
164162 match self {
165- LintExpectationId :: Stable { hir_id, attr_index, lint_index : Some ( lint_index ) } => {
163+ LintExpectationId :: Stable { hir_id, attr_index, lint_index, .. } => {
166164 let ( def_path_hash, lint_idx) = hir_id. to_stable_hash_key ( hcx) ;
167165 ( def_path_hash, lint_idx, * attr_index, * lint_index)
168166 }
@@ -247,35 +245,6 @@ impl Level {
247245 }
248246 }
249247
250- /// Converts an `Attribute` to a level.
251- pub fn from_attr ( attr : & impl AttributeExt ) -> Option < ( Self , Option < LintExpectationId > ) > {
252- attr. name ( ) . and_then ( |name| Self :: from_symbol ( name, || Some ( attr. id ( ) ) ) )
253- }
254-
255- /// Converts a `Symbol` to a level.
256- pub fn from_symbol (
257- s : Symbol ,
258- id : impl FnOnce ( ) -> Option < AttrId > ,
259- ) -> Option < ( Self , Option < LintExpectationId > ) > {
260- match s {
261- sym:: allow => Some ( ( Level :: Allow , None ) ) ,
262- sym:: expect => {
263- if let Some ( attr_id) = id ( ) {
264- Some ( (
265- Level :: Expect ,
266- Some ( LintExpectationId :: Unstable { attr_id, lint_index : None } ) ,
267- ) )
268- } else {
269- None
270- }
271- }
272- sym:: warn => Some ( ( Level :: Warn , None ) ) ,
273- sym:: deny => Some ( ( Level :: Deny , None ) ) ,
274- sym:: forbid => Some ( ( Level :: Forbid , None ) ) ,
275- _ => None ,
276- }
277- }
278-
279248 pub fn to_cmd_flag ( self ) -> & ' static str {
280249 match self {
281250 Level :: Warn => "-W" ,
0 commit comments